255], [['skype'], 'string', 'max' => 32], //[['active_task_ids'], 'string', 'max' => 100], //[['login'], 'unique'], //[['name'], 'unique'], //[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Companies::className(), 'targetAttribute' => ['company_id' => 'id']], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'name' => 'Name', 'cmdlevel' => 'Cmdlevel', 'phone' => 'Phone', 'password' => 'Password', 'login' => 'Login', 'email' => 'Email', 'skype' => 'Skype', 'company_id' => 'Company ID', 'active_company' => 'Active Company', 'active_device_id' => 'Active Device ID', 'active_task_ids' => 'Active Task Ids', 'created' => 'Created', 'jobtypes' => 'Jobtypes', 'last_seen_mobile' => 'Last Seen Mobile', 'last_seen_web' => 'Last Seen Web', ]; } /** * @return \yii\db\ActiveQuery */ public function getCompanies() { return $this->hasOne(Companies::className(), ['id' => 'company']); } /** * @return \yii\db\ActiveQuery */ public function getAccountsJobtypes() { return $this->hasMany(AccountsJobtypes::className(), ['account_id' => 'id'])->orderBy(['priority' => SORT_ASC]); } public function getAccountsJobtypesPriority() { return $this->hasMany(AccountsJobtypes::className(), ['account_id' => 'id'])->where(['priority' => 0]); } /** * @return \yii\db\ActiveQuery */ public function getJobtype() { return $this->hasMany(Jobtypes::class, ['id' => 'jobtype_id']) ->via('accountsJobtypes'); } /** * @return \yii\db\ActiveQuery */ public function getTasks() { return $this->hasMany(Tasks::class, ['assignees_arr' => 'id'])->andWhere(['<>','status', 5]); } public function isAdmin() { return $this->cmdlevel == 10; } public function getFaceFeature() { return $this->hasOne(FaceFeature::className(), ['id_account' => 'id']); } public function getFaceFeatureCurrent($id = null) { $row_last = (new \yii\db\Query()) ->select(['id_account','face_feature','date']) ->from('face_feature') ->where(['id_account' => $id]) ->orderBy(['id' => SORT_DESC]) ->one(); return $row_last; } /** * Возвращает массив ID должностей * * @return int[] */ public function getPositionIds() { $positions = AccountsJobtypes::find() ->select('jobtype_id') ->where(['account_id' => $this->id]) ->asArray() ->all() ; return array_column($positions, 'jobtype_id'); } /** * Возвращает информацию по должностям * * @return array */ public function getPositionsList() { $positionIds = $this->getPositionIds(); $accountJobTypes = AccountsJobtypes::find()->all(); $priorities = []; foreach ($accountJobTypes as $type) { $priorities[$type->jobtype_id] = $type->priority; } $positions = []; foreach (Jobtypes::findAll($positionIds) as $position) { $positions[] = [ 'id' => $position->id, 'name' => $position->name, 'main' => $priorities[$position->id], ]; } return $positions; } /** * Возвращает названия должностей * * @return string[] */ public function getPositionsNames() { $positionIds = $this->getPositionIds(); $positions = []; foreach (Jobtypes::findAll($positionIds) as $position) { $positions[] = $position->name; } return $positions; } /** * Проверяет онлайн ли пользователь в мобильном приложении * * @param $time * @return bool * @throws \Exception */ public function isOnline(): bool { if (null == $this->last_seen_mobile) return false; $now = new \DateTime(); $tenMin = new \DateInterval('PT10M'); $now->sub($tenMin); return $now->format('Y-m-d H:i:s') <= $this->last_seen_mobile; } }