From d71f7484bbb8289d7a3dc5f2de50c55ed44440aa Mon Sep 17 00:00:00 2001 From: vbrazas Date: Fri, 26 Apr 2019 16:28:26 +0300 Subject: [PATCH 1/2] [#129] some bug fixes --- Dockerfile | 3 ++- helpers/RememberUserInfo/RememberUser.php | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 765109f..4193c72 100755 --- a/Dockerfile +++ b/Dockerfile @@ -68,5 +68,6 @@ RUN pecl install redis xdebug-2.6.0 \ && echo "xdebug.remote_autostart=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo "xdebug.remote_port=9999" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ - && echo "xdebug.remote_host=192.168.99.1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo "xdebug.remote_host=192.168.99.1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini + RUN echo "memory_limit=-1" >> /usr/local/etc/php/php.ini diff --git a/helpers/RememberUserInfo/RememberUser.php b/helpers/RememberUserInfo/RememberUser.php index 7fcd93e..6cc4509 100644 --- a/helpers/RememberUserInfo/RememberUser.php +++ b/helpers/RememberUserInfo/RememberUser.php @@ -32,11 +32,11 @@ protected function remember() $this->responseSubset['campus'] = $this->responseSubset['campus'][0]['name']; $this->responseSubset['visible'] = ($this->responseSubset['campus'] === 'Kyiv'); - $this->responseSubset['needupd'] = 0; - $this->responseSubset['kick'] = $user->kick ?? 0; // ! Need some refactor - $this->responseSubset['location'] = $user->location ?? 0; // ! Need some refactor - $this->responseSubset['hours'] = $user->hours ?? 0; // ! Need some refactor - $this->responseSubset['lasthours'] = $user->lasthours ?? 0; // ! Need some refactor + $this->responseSubset['needupd'] = $user->needupd ?? 0; // !!! + $this->responseSubset['kick'] = $user->kick ?? 0; // !!! + $this->responseSubset['location'] = $user->location ?? 0; // !!! + $this->responseSubset['hours'] = $user->hours ?? 0; // !!! + $this->responseSubset['lasthours'] = $user->lasthours ?? 0; // !!! self::swapKeysInArr($this->responseSubset, [ 'id' => 'xid', 'staff?' => 'staff' ]); self::setTrueFalse($this->responseSubset['staff']); From 4b160fb977414d5edb9e744c581c216b87332f8c Mon Sep 17 00:00:00 2001 From: vbrazas Date: Mon, 29 Apr 2019 20:37:33 +0300 Subject: [PATCH 2/2] [#129] RememberUser now working properly --- controllers/LocationsSearch.php | 5 +- controllers/ShowController.php | 3 +- controllers/ShowSearch.php | 2 +- helpers/LogTimeHelper.php | 74 +++++++++++++- helpers/RememberUserInfo/RememberUser.php | 20 +++- views/projects/index.php | 2 +- views/show/_time.php | 115 +++++++--------------- 7 files changed, 125 insertions(+), 96 deletions(-) diff --git a/controllers/LocationsSearch.php b/controllers/LocationsSearch.php index bf557e7..a9c9881 100644 --- a/controllers/LocationsSearch.php +++ b/controllers/LocationsSearch.php @@ -55,8 +55,9 @@ public function scenarios() public function search($params) { $query = Locations::find() - ->where(['xlogin' => $this->login]) - ->andWhere('end_at > 0'); + ->where(['xlogin' => $this->login]) + ->andWhere('end_at > 0') + ; $this->load($params); // add conditions that should always apply here diff --git a/controllers/ShowController.php b/controllers/ShowController.php index 36075fc..16aaa1c 100644 --- a/controllers/ShowController.php +++ b/controllers/ShowController.php @@ -2,10 +2,9 @@ namespace app\controllers; +use Yii; use app\helpers\SkillsHelper; -use app\models\ProjectsAll; use app\models\ProjectsLogin; -use Yii; use app\models\Show; use yii\web\NotFoundHttpException; diff --git a/controllers/ShowSearch.php b/controllers/ShowSearch.php index 51aee70..57557e9 100644 --- a/controllers/ShowSearch.php +++ b/controllers/ShowSearch.php @@ -51,7 +51,7 @@ public function search($params, $course) ->where([ 'xlogins.visible' => 1, 'cursus_users.name' => $course, - ]); + ]); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ diff --git a/helpers/LogTimeHelper.php b/helpers/LogTimeHelper.php index 68f0f80..df74ce3 100644 --- a/helpers/LogTimeHelper.php +++ b/helpers/LogTimeHelper.php @@ -8,7 +8,6 @@ namespace app\helpers; - class LogTimeHelper { public function countTime($countTime, $summa = null) @@ -30,19 +29,86 @@ public function countTime($countTime, $summa = null) return "$forReturn"; } - public function fix24(&$data) + public static function fix24(&$data) { $fix = 0; - foreach ($data as &$key) { + foreach ($data as &$key) { if ($fix > 0) { $key = $fix; $fix = 0; } + if ($key > 24.0) { $fix = $key - 24.00; $key = 24.00; } } } -} \ No newline at end of file + + /** + * getChartJSInfo + * + * @param Locations[] $models + * @param array $get - GET request + * @return array [$labels, $data, $amount] - info for ChartJS::widget + */ + public static function getChartJSInfo($models, $get = []) + { + $labels = []; + $data = []; + $arr = []; + $tempDate = null; + $count = count($models); + $amount = 0; + $tempDate = ''; + + if (isset($get['LocationsSearch']['dateEnd'])) { + $tempDate = $get['LocationsSearch']['dateEnd']; + } else { + $tempDate = date('Y-m-d', time()); + } + + $first = ''; + foreach ($models as $model) { + $first = $model->date; + break; + } + + while ($tempDate != $first) { + $tempDate = date('Y-m-d', strtotime($tempDate . "-1 days")); + $arr[$tempDate] = '00.00'; + break ; + } + + foreach ($models as $model) { + if ($count > 0) { + if ($tempDate != $model->date) { + while ($count > 0 && $tempDate != $model->date) { + $tempDate = date('Y-m-d', strtotime($tempDate . "-1 days")); + $arr[$tempDate] = '00.00'; + } + } else { + $tempDate = date('Y-m-d',strtotime($model->date)); + $count--; + } + } + if (isset($arr[$model->date]) && $count > 0) { + $arr[$model->date] = self::countTime($model->how, $arr[$model->date]); + } else { + $arr[$model->date] = self::countTime($model->how); + } + $tempDate = date('Y-m-d',strtotime($model->date)); + } + + foreach ($arr as $key => $value) { + $labels = array_merge([$key], $labels); + $data = array_merge([$value], $data); + $amount += $value; + } + + self::fix24($data); + + return [$amount, $labels, $data]; + } +} diff --git a/helpers/RememberUserInfo/RememberUser.php b/helpers/RememberUserInfo/RememberUser.php index 6cc4509..960202c 100644 --- a/helpers/RememberUserInfo/RememberUser.php +++ b/helpers/RememberUserInfo/RememberUser.php @@ -2,6 +2,10 @@ namespace app\helpers\RememberUserInfo; +use Yii; +use app\controllers\LocationsSearch; +use app\helpers\LogTimeHelper; + class RememberUser extends RememberHelper { @@ -32,11 +36,17 @@ protected function remember() $this->responseSubset['campus'] = $this->responseSubset['campus'][0]['name']; $this->responseSubset['visible'] = ($this->responseSubset['campus'] === 'Kyiv'); - $this->responseSubset['needupd'] = $user->needupd ?? 0; // !!! - $this->responseSubset['kick'] = $user->kick ?? 0; // !!! - $this->responseSubset['location'] = $user->location ?? 0; // !!! - $this->responseSubset['hours'] = $user->hours ?? 0; // !!! - $this->responseSubset['lasthours'] = $user->lasthours ?? 0; // !!! + $searchModelTime = new LocationsSearch($this->xlogin); + $dataProviderTime = $searchModelTime->search(Yii::$app->request->queryParams); + $lastloc = $dataProviderTime->models[0]; + [$amount, $labels, $data] = LogTimeHelper::getChartJSInfo($dataProviderTime->models); + $this->responseSubset['hours'] = $amount; + + $this->responseSubset['needupd'] = $user->needupd ?? 0; + $this->responseSubset['lasthours'] = $user->lasthours ?? 0; + $this->responseSubset['kick'] = $user->kick ?? 0; + // $this->responseSubset['lastloc'] = $lastloc->begin_at; + $this->responseSubset['location'] = $user->location ?? $lastloc->host; self::swapKeysInArr($this->responseSubset, [ 'id' => 'xid', 'staff?' => 'staff' ]); self::setTrueFalse($this->responseSubset['staff']); diff --git a/views/projects/index.php b/views/projects/index.php index 35af5a0..fadf0f2 100644 --- a/views/projects/index.php +++ b/views/projects/index.php @@ -56,6 +56,6 @@ ]); ?> - + diff --git a/views/show/_time.php b/views/show/_time.php index 334becd..6b0fbd2 100644 --- a/views/show/_time.php +++ b/views/show/_time.php @@ -14,89 +14,42 @@ 10000 ]); ?> render('_search_time', ['model' => $searchModelTime, 'action' => $action]); ?> models); - $amount = 0; - $get = Yii::$app->request->get(); - $tempDate = ''; - if (isset($get['LocationsSearch']['dateEnd'])) { - $tempDate = $get['LocationsSearch']['dateEnd']; - } else { - $tempDate = date('Y-m-d', time()); - } - $first = ''; - foreach ($dataProviderTime->models as $model) { - $first = $model->date; - break; - } - while ($tempDate != $first) { - $tempDate = date('Y-m-d', strtotime($tempDate . "-1 days")); - $shit[$tempDate] = '00.00'; - break ; - } - foreach ($dataProviderTime->models as $model) { - if ($count > 0) { - if ($tempDate != $model->date) { - while ($count > 0 && $tempDate != $model->date) { - $tempDate = date('Y-m-d', strtotime($tempDate . "-1 days")); - $shit[$tempDate] = '00.00'; - } - } else { - $tempDate = date('Y-m-d',strtotime($model->date)); - $count--; - } - } - if (isset($shit[$model->date]) && $count > 0) { - $shit[$model->date] = LogTimeHelper::countTime($model->how, $shit[$model->date]); - } else { - $shit[$model->date] = LogTimeHelper::countTime($model->how); - } - $tempDate = date('Y-m-d',strtotime($model->date)); - } - ; - foreach ($shit as $key => $value) { - $labels = array_merge([$key], $labels); - $data = array_merge([$value], $data); - $amount += $value; - } - LogTimeHelper::fix24($data); - - echo ChartJs::widget([ - 'type' => 'line', - - 'data' => [ - 'labels' => $labels, - 'datasets' => [ - [ - 'label' => Yii::t('app', 'Time in cluster'), - 'backgroundColor' => "rgba(255,99,132,0.2)", - 'borderColor' => "rgba(255,99,132,1)", - 'pointBackgroundColor' => "rgba(255,99,132,1)", - 'pointBorderColor' => "#fff", - 'pointHoverBackgroundColor' => "#fff", - 'pointHoverBorderColor' => "rgba(255,99,132,1)", - 'data' => $data, - 'lineTension' => '0.1', + $get = Yii::$app->request->get(); + [$amount, $labels, $data] = LogTimeHelper::getChartJSInfo($dataProviderTime->models, $get); + + echo ChartJs::widget([ + 'type' => 'line', + + 'data' => [ + 'labels' => $labels, + 'datasets' => [ + [ + 'label' => Yii::t('app', 'Time in cluster'), + 'backgroundColor' => "rgba(255,99,132,0.2)", + 'borderColor' => "rgba(255,99,132,1)", + 'pointBackgroundColor' => "rgba(255,99,132,1)", + 'pointBorderColor' => "#fff", + 'pointHoverBackgroundColor' => "#fff", + 'pointHoverBorderColor' => "rgba(255,99,132,1)", + 'data' => $data, + 'lineTension' => '0.1', + ] ] - ] - ], - 'options'=> [ - 'height' => '100%', - 'responsive'=> true, - 'tooltips'=> [ - 'mode'=> 'index', - 'intersect'=> false, - ], - 'hover'=> [ - 'mode'=> 'nearest', - 'intersect'=> true ], - ] - ]);?> + 'options'=> [ + 'height' => '100%', + 'responsive'=> true, + 'tooltips'=> [ + 'mode'=> 'index', + 'intersect'=> false, + ], + 'hover'=> [ + 'mode'=> 'nearest', + 'intersect'=> true + ], + ] + ]); + ?>