Skip to content

Commit

Permalink
[WIP][unitfactoryAlumni#66] Considering code in RememberUserInfo::rem…
Browse files Browse the repository at this point in the history
…emberCursusUsersAndSkills and RememberUserInfo::rememberProjectsUsers as junk code, need help
  • Loading branch information
vbrazas committed Mar 27, 2019
1 parent 84b3709 commit 6906ede
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 10 deletions.
44 changes: 36 additions & 8 deletions helpers/RememberUserInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -26,6 +37,7 @@ public function rememberAll()
$this->rememberLevel();
$this->rememberXlogin();
$this->rememberCursusUsersAndSkills();
$this->rememberProjectsUsers();
}

private function rememberLevel()
Expand All @@ -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']])
Expand All @@ -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()
}
68 changes: 68 additions & 0 deletions models/ProjectsUsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace app\models;

use Yii;

/**
* This is the model class for table "projects_users".
*
* @property int $id
* @property string $xlogin
* @property int $current_team_id
* @property int $cursus_ids
* @property int $final_mark
* @property int $puid
* @property int $occurrence
* @property int $project_id
* @property string $name
* @property int $parent_id
* @property string $slug
* @property string $status
* @property string $validated
*/
class ProjectsUsers extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'projects_users';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['current_team_id', 'cursus_ids', 'final_mark', 'puid', 'occurrence', 'project_id', 'parent_id'], 'integer'],
[['xlogin'], 'string', 'max' => 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'),
];
}
}
4 changes: 2 additions & 2 deletions models/Xlogins.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 6906ede

Please sign in to comment.