From 6906ede796c05cd08eb912bbe11d2c9f9ca80558 Mon Sep 17 00:00:00 2001 From: vbrazas Date: Wed, 27 Mar 2019 06:14:40 +0200 Subject: [PATCH] [WIP][#66] Considering code in RememberUserInfo::rememberCursusUsersAndSkills and RememberUserInfo::rememberProjectsUsers as junk code, need help --- helpers/RememberUserInfo.php | 44 ++++++++++++++++++----- models/ProjectsUsers.php | 68 ++++++++++++++++++++++++++++++++++++ models/Xlogins.php | 4 +-- 3 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 models/ProjectsUsers.php diff --git a/helpers/RememberUserInfo.php b/helpers/RememberUserInfo.php index 4fc5828..e37a8cd 100644 --- a/helpers/RememberUserInfo.php +++ b/helpers/RememberUserInfo.php @@ -6,17 +6,28 @@ use app\models\Xlogins; use app\models\Skills; use app\models\CursusUsers; +use app\models\ProjectsUsers; class RememberUserInfo { - + /** + * $response - response accepted by app\helpers\Auth42 + * + * @var Array + */ public $response = null; + /** + * __construct + * + * @param Array $response + */ public function __construct($response = null) { $this->response = $response; } + public function rememberAll() { if ($this->response === null) { @@ -26,6 +37,7 @@ public function rememberAll() $this->rememberLevel(); $this->rememberXlogin(); $this->rememberCursusUsersAndSkills(); + $this->rememberProjectsUsers(); } private function rememberLevel() @@ -48,15 +60,16 @@ private function rememberCursusUsersAndSkills() $skills = new Skills(); $cursus_users = $this->response['cursus_users']; - foreach ($cursus_users as $cursus) { + foreach ($cursus_users as $cursus) { // !!! Optimisation needed foreach ($cursus['skills'] as $skill) { - $skills = $skills->findOne([ 'xlogin' => $this->response['login'], 'skills_id' => $skill['id'] ]) - ?? $skills; - $skill['skills_id'] = $skill['id']; // ???WTF - $skill['skills_name'] = $skill['name']; // ???WTF - $skill['skills_level'] = $skill['level']; // ???WTF + // $skills = $skills->findOne([ 'xlogin' => $this->response['login'], 'skills_id' => $skill['id'] ]) + // ?? $skills; + $adopted_skill['xlogin'] = $this->response['login']; // ??? WTF + $adopted_skill['skills_id'] = $skill['id']; // ??? WTF + $adopted_skill['skills_name'] = $skill['name']; // ??? WTF + $adopted_skill['skills_level'] = $skill['level']; // ??? WTF - $skills->attributes = $skill; + $skills->attributes = $adopted_skill; $skills->save(false); } $cursusUsers = $cursusUsers->findOne(['cursus_users_id' => $cursus['id']]) @@ -66,4 +79,19 @@ private function rememberCursusUsersAndSkills() $cursusUsers->save(false); } } + + private function rememberProjectsUsers() + { + $pusers = new ProjectsUsers(); + + foreach ($this->response['projects_users'] as $project) { // !!! Optimisation needed + $pusers = $pusers->findOne(['current_team_id' => $project['current_team_id']]) + ?? $pusers; + + $pusers->attributes = $project; + $pusers->save(false); + } + } + + // TODO private function rememberPatroning() } diff --git a/models/ProjectsUsers.php b/models/ProjectsUsers.php new file mode 100644 index 0000000..d2329c0 --- /dev/null +++ b/models/ProjectsUsers.php @@ -0,0 +1,68 @@ + 12], + [['name', 'slug'], 'string', 'max' => 255], + [['status', 'validated'], 'string', 'max' => 25], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'ID'), + 'xlogin' => Yii::t('app', 'Xlogin'), + 'current_team_id' => Yii::t('app', 'Current Team ID'), + 'cursus_ids' => Yii::t('app', 'Cursus Ids'), + 'final_mark' => Yii::t('app', 'Final Mark'), + 'puid' => Yii::t('app', 'Puid'), + 'occurrence' => Yii::t('app', 'Occurrence'), + 'project_id' => Yii::t('app', 'Project ID'), + 'name' => Yii::t('app', 'Name'), + 'parent_id' => Yii::t('app', 'Parent ID'), + 'slug' => Yii::t('app', 'Slug'), + 'status' => Yii::t('app', 'Status'), + 'validated' => Yii::t('app', 'Validated'), + ]; + } +} diff --git a/models/Xlogins.php b/models/Xlogins.php index e602fb4..e06ad87 100644 --- a/models/Xlogins.php +++ b/models/Xlogins.php @@ -62,8 +62,8 @@ public function rules() */ public function init() { - $this->kick = 0; // ???WTF - $this->lastloc = date('Y-m-d H:i:s'); // ???WTF + $this->kick = 0; // ??? WTF + $this->lastloc = date('Y-m-d H:i:s'); // ??? WTF parent::init(); }