public function actionMonth($y = null, $m = null) { $m = Html::encode($m); $y = Html::encode($y); if ($data = yii::$app->request->post('user_id')) { Schedule::deleteAll("date_format(date, '%Y%m') = :date", [':date' => $y . $m]); foreach ($data as $date => $shifts) { foreach ($shifts as $shiftId => $userIds) { if (is_array($userIds)) { foreach ($userIds as $userId) { $model = new Schedule(); $model->date = $date; $model->shift = $shiftId; $model->user_id = $userId; $model->save(); } } } } yii::$app->session->setFlash('success', 'Данные успешно сохранены'); return $this->redirect(['/worksess/schedule/month', 'y' => $y, 'm' => $m]); } $model = new Schedule(); $workers = yii::$app->getModule('worksess')->getWorkersList(); return $this->render('month', ['m' => $m, 'y' => $y, 'module' => $this->module, 'months' => self::getMonths(), 'days' => self::getDays(), 'month' => yii::t('order', "month_{$m}"), 'model' => $model, 'workers' => $workers]); }
public function getWorkers($date = null, $shiftId = null) { if (!$date) { $date = date('Y-m-d'); } $userModel = yii::$app->getModule('worksess')->userModel; if ($userIds = Schedule::find()->select('user_id')->distinct()->where(['date' => $date, 'shift' => $shiftId])->select('user_id')->distinct()) { return $userModel::findAll(['id' => $userIds]); } else { return []; } }