Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #134 from Millon15/fix-129
Browse files Browse the repository at this point in the history
Full fix PR #129
  • Loading branch information
Vitas Brazas authored Apr 29, 2019
2 parents 003d867 + 4b160fb commit 057fc83
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 97 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions controllers/LocationsSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions controllers/ShowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion controllers/ShowSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
74 changes: 70 additions & 4 deletions helpers/LogTimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace app\helpers;


class LogTimeHelper
{
public function countTime($countTime, $summa = null)
Expand All @@ -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;
}
}
}
}

/**
* 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];
}
}
20 changes: 15 additions & 5 deletions helpers/RememberUserInfo/RememberUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace app\helpers\RememberUserInfo;

use Yii;
use app\controllers\LocationsSearch;
use app\helpers\LogTimeHelper;

class RememberUser extends RememberHelper
{

Expand Down Expand Up @@ -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'] = 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
$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']);
Expand Down
2 changes: 1 addition & 1 deletion views/projects/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@
]); ?>
</div>

<?= Pjax::end(); ?>
<?php Pjax::end(); ?>

</div>
115 changes: 34 additions & 81 deletions views/show/_time.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,89 +14,42 @@
<?php Pjax::begin(['timeout' => 10000 ]); ?>
<?= $this->render('_search_time', ['model' => $searchModelTime, 'action' => $action]); ?>
<?php

$labels = [];
$data = [];
$shit = [];
$tempDate = null;
$count = count($dataProviderTime->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
],
]
]);
?>

<h4><?= Yii::t('app', 'Amount') . ': ' . $amount ?></h4>
<?php Pjax::end(); ?>
Expand Down

0 comments on commit 057fc83

Please sign in to comment.