diff --git a/backend/modules/calendar/controllers/AjaxController.php b/backend/modules/calendar/controllers/AjaxController.php new file mode 100644 index 0000000..85530c3 --- /dev/null +++ b/backend/modules/calendar/controllers/AjaxController.php @@ -0,0 +1,32 @@ +search(Yii::$app->request->queryParams)->getModels(); + $models_array = ArrayHelper::toArray($models, [ + 'backend\modules\card\models\UserCard' => [ + 'id', + 'dob', + 'fio' + ], + ]); + + $response = Yii::$app->response; + $response->format = Response::FORMAT_JSON; + $response->getHeaders()->set('Content-Type', 'application/json; charset=utf-8'); + $response->content = json_encode( + $models_array + ); + return $response; + } +}?> diff --git a/backend/modules/calendar/controllers/CalendarController.php b/backend/modules/calendar/controllers/CalendarController.php index 86ae7e3..352efac 100644 --- a/backend/modules/calendar/controllers/CalendarController.php +++ b/backend/modules/calendar/controllers/CalendarController.php @@ -3,7 +3,6 @@ namespace backend\modules\calendar\controllers; use backend\modules\card\models\UserCardSearch; -use common\classes\Debug; use Yii; use yii\data\ArrayDataProvider; use yii\filters\AccessControl; @@ -43,6 +42,10 @@ class CalendarController extends Controller * Renders the index view for the module * @return string */ + public function actionCalendar(){ + return $this->render('calendar'); + } + public function actionIndex() { $searchModel = new UserCardSearch(); diff --git a/backend/modules/calendar/views/calendar/calendar.php b/backend/modules/calendar/views/calendar/calendar.php new file mode 100644 index 0000000..ca050c5 --- /dev/null +++ b/backend/modules/calendar/views/calendar/calendar.php @@ -0,0 +1,59 @@ +title = 'Календарь ДР'; +?> + '.success{color: orange;}', + + 'button' => Html::a(' Назад', + Yii::$app->request->referrer, ['class' => 'btn btn-primary',]), + 'runBuild' => "function (date, content){ + this.build(date, content) + }", + 'updateContent' => "function(date){ + let monthNumber = date.substr(5, 2); + return fetch('../ajax/get-birthday-by-month?' + + 'month=' + monthNumber) + .then((res) => { + return res.json() + }) + }", + 'getColor' => "function (date, dates = null) { + for (let contentDate of dates) { + if (contentDate['dob'].substr(8, 2) == DateHelper.intToDate(date.getDate())) { + return 'success'; + } + } + }", + 'getHtmlContentForDate' => 'function (content, date) { + let flag = false + let html = ` + + + + + + + + `; + for (let i = 1; i <= content.length; i++) { + let model = content[i - 1]; + if (model["dob"].substr(8, 2) == date.substr(8, 2)) { + flag = true; + html += `` + html += `` + html += `` + html += `` + html += CalendarHelper._getActionColumn(`secure/calendar/calendar`,model[`id`]) + html += `` + } + } + html += `
#ФИОДата рождения 
${i}${model["fio"]}${model["dob"]}
` + if (flag) return html; + return "empty" + }' +]) ?> + + diff --git a/backend/modules/calendar/views/calendar/index.php b/backend/modules/calendar/views/calendar/index.php index 148d8a5..1783f5f 100644 --- a/backend/modules/calendar/views/calendar/index.php +++ b/backend/modules/calendar/views/calendar/index.php @@ -4,9 +4,10 @@ /* @var $dataProvider yii\data\ActiveDataProvider */ use yii\grid\GridView; +use yii\helpers\Html; use yii\widgets\Pjax; ?> - +

- + 'far fa-calendar-alt']), + ['calendar'], ['class' => 'btn btn-success', 'style' => 'margin-left: 10px'])?> +
'reload']); echo GridView::widget([ diff --git a/backend/modules/card/models/UserCardSearch.php b/backend/modules/card/models/UserCardSearch.php index cb6676b..4fd7e0a 100755 --- a/backend/modules/card/models/UserCardSearch.php +++ b/backend/modules/card/models/UserCardSearch.php @@ -6,7 +6,6 @@ use common\classes\Debug; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; -use backend\modules\card\models\UserCard; /** * UserCardSearch represents the model behind the search form of `backend\modules\card\models\UserCard`. @@ -64,6 +63,10 @@ class UserCardSearch extends UserCard $query->where(['deleted_at' => null]); + if (isset($params['month'])) { + $query->andFilterWhere(['=', 'MONTH(dob)', $params['month']]); + } + // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, diff --git a/backend/modules/reports/controllers/AjaxController.php b/backend/modules/reports/controllers/AjaxController.php index 3971529..7b81181 100644 --- a/backend/modules/reports/controllers/AjaxController.php +++ b/backend/modules/reports/controllers/AjaxController.php @@ -3,10 +3,9 @@ namespace backend\modules\reports\controllers; use backend\modules\reports\models\Month; -use common\classes\Debug; use Yii; use backend\modules\reports\models\ReportsSearch; -use yii\web\JsonResponseFormatter; +use yii\helpers\ArrayHelper; use yii\web\Response; class AjaxController extends \yii\web\Controller @@ -15,20 +14,28 @@ class AjaxController extends \yii\web\Controller public function actionGetReportsForMonthByIdYearMonth($user_id, $year, $month){ $searchModel = new ReportsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - $reports = $dataProvider->getModels(); - $reports_array = array_column($reports, 'attributes'); - foreach ($reports as $i => $report){ - $reports_array[$i]['today'] = array_column($report->task, 'attributes'); - } + $reports_array = ArrayHelper::toArray($dataProvider->getModels(), [ + 'common\models\Reports' => [ + 'id', + 'created_at', + 'difficulties', + 'tomorrow', + 'user_card_id', + 'today' => function ($report) { + return ArrayHelper::toArray($report->task, [ + 'common\models\ReportsTask' => [ + 'hours_spent', + 'task' + ], + ]); + } + ], + ]); $response = Yii::$app->response; $response->format = Response::FORMAT_JSON; $response->getHeaders()->set('Content-Type', 'application/json; charset=utf-8'); - $response->content = json_encode(array_merge( - ['reports' => $reports_array], - ['month' => (array)new Month($year.'-'.$month.'-01')]) - ); + $response->content = json_encode($reports_array); return $response; } diff --git a/backend/modules/reports/controllers/ReportsController.php b/backend/modules/reports/controllers/ReportsController.php index 5f11f35..3a0e29a 100644 --- a/backend/modules/reports/controllers/ReportsController.php +++ b/backend/modules/reports/controllers/ReportsController.php @@ -7,8 +7,8 @@ use Yii; use common\models\Reports; use backend\modules\reports\models\ReportsSearch; use yii\filters\AccessControl; +use yii\helpers\ArrayHelper; use yii\web\Controller; -use yii\web\JsonResponseFormatter; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -48,9 +48,14 @@ class ReportsController extends Controller public function actionIndex() { $searchModel = new ReportsSearch(); - $user_id__fio = []; - foreach ($searchModel->search([])->getModels() as $model) - $user_id__fio[$model->user_card_id] = \common\models\Reports::getFio($model); + $user_id__fio = ArrayHelper::map(ArrayHelper::toArray($searchModel->search([])->getModels(), [ + 'common\models\Reports' => [ + 'user_card_id', + 'fio' => function ($report) { + return Reports::getFio($report); + } + ], + ]),'user_card_id', 'fio'); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ @@ -61,14 +66,38 @@ class ReportsController extends Controller } - public function actionUser($user_id) + public function actionCalendar($user_id) { $searchModel = new ReportsSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $searchModel->user_card_id = $user_id; + $dataProvider = $searchModel->search([]); - return $this->render('user', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, + + $reports_array = ArrayHelper::toArray($dataProvider->getModels(), [ + 'common\models\Reports' => [ + 'id', + 'created_at', + 'difficulties', + 'tomorrow', + 'user_card_id', + 'today' => function ($report) { + return ArrayHelper::toArray($report->task, [ + 'common\models\ReportsTask' => [ + 'hours_spent', + 'task' + ], + ]); + } + ], + ]); + + if (!$dataProvider->getCount()){ + return $this->render('non-exist_user_id', ['id' => $user_id]); + } + return $this->render('calendar', [ + 'reports' => $reports_array, + 'fio' => Reports::getFio($searchModel), + 'USER_ID' => $user_id ]); } diff --git a/backend/modules/reports/views/reports/calendar.php b/backend/modules/reports/views/reports/calendar.php new file mode 100644 index 0000000..2496e4b --- /dev/null +++ b/backend/modules/reports/views/reports/calendar.php @@ -0,0 +1,89 @@ +title = 'Календарь пользователя - ' . $fio; +?> + + Html::a(' Назад', + Yii::$app->request->referrer, ['class' => 'btn btn-primary',]), + + 'runBuild' => "function (date, content){ + contentDays = [] + for (let item of content){ + contentDays.push(item['created_at']) + } + this.build(date, contentDays) + }", + + 'updateContent' => "function(date){ + let monthNumber = date.substr(5, 2); + let yearNumber = date.substr(0, 4); + return fetch('../ajax/get-reports-for-month-by-id-year-month?user_id='+".$USER_ID."+ + '&month=' + monthNumber + + '&year=' + yearNumber) + .then((res) => { + return res.json() + }) + }", + + 'getColor' => "function (date, dates = null) { + let d = date; + if ([6, 0].includes(d.getDay())) + return; + for (let i = 0; i < dates.length; i++) { + if (dates[i] == DateHelper.dateToString(date)) { + return 'success'; + } + } + return 'danger'; + }", + + 'getHtmlContentForDate' => "function (content, date) { + if ([0, 6].includes(new Date(date).getDay())) { + return 'Выходной день'; + } + let j = 0; + let html = `