123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- namespace app\models\entity;
- class Accounts extends \yii\db\ActiveRecord
- {
-
- public static function tableName()
- {
- return 'accounts_internal';
- }
-
- public function rules()
- {
- return [
- [['name', 'cmdlevel', 'password', 'login', 'active_company', 'jobtypes'], 'required'],
- [['cmdlevel', 'company_id', 'active_company'], 'integer'],
- [['created', 'last_seen_mobile', 'last_seen_web'], 'safe'],
- [['name', 'phone', 'password', 'login', 'email', 'active_device_id', 'jobtypes'], 'string', 'max' => 255],
- [['skype'], 'string', 'max' => 32],
-
-
-
-
- ];
- }
-
- 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',
- ];
- }
-
- public function getCompanies()
- {
- return $this->hasOne(Companies::className(), ['id' => 'company']);
- }
-
- 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]);
- }
-
-
- public function getJobtype()
- {
- return $this->hasMany(Jobtypes::class, ['id' => 'jobtype_id'])
- ->via('accountsJobtypes');
- }
-
-
- 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;
- }
-
- public function getPositionIds()
- {
- $positions = AccountsJobtypes::find()
- ->select('jobtype_id')
- ->where(['account_id' => $this->id])
- ->asArray()
- ->all()
- ;
- return array_column($positions, 'jobtype_id');
- }
-
- 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;
- }
-
- public function getPositionsNames()
- {
- $positionIds = $this->getPositionIds();
- $positions = [];
- foreach (Jobtypes::findAll($positionIds) as $position) {
- $positions[] = $position->name;
- }
- return $positions;
- }
-
- 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;
- }
- }
|