diff --git a/helpers/RememberUserInfo/RememberAchievements.php b/helpers/RememberUserInfo/RememberAchievements.php index 997e361..a6ce49b 100644 --- a/helpers/RememberUserInfo/RememberAchievements.php +++ b/helpers/RememberUserInfo/RememberAchievements.php @@ -7,20 +7,27 @@ class RememberAchievements extends RememberHelper { - protected function norminateTheResponse() + protected function init() { - foreach ($this->response['achievements'] as &$achievement) { - $achievement['xlogin'] = $this->response['login']; + $this->responseSubSet =& $this->response['projects_users']; + $this->model = new Achievements(); + } + + protected function norminate() + { + $this->responseSubSet =& $this->response['achievements']; + + foreach ($this->responseSubSet as &$achievement) { + $this->setXlogin($achievement); + $achievement['visible'] = $achievement['visible'] ? 'True' : 'False'; self::swapKeysInArr($achievement, [ 'id' => 'aid' ]); } } - public function rememberToDB() + protected function remember() { - $achievements = new Achievements(); - - foreach ($this->response['achievements'] as &$achievement) { - self::saveChangesToDB($achievements, $achievement, $achievements->find() + foreach ($this->responseSubSet as &$achievement) { + self::saveChangesToDB($this->model, $achievement, $this->model->find() ->Where([ 'aid' => $achievement['aid'] ]) ->andWhere([ 'xlogin' => $achievement['xlogin'] ]) ->all()); diff --git a/helpers/RememberUserInfo/RememberCurses.php b/helpers/RememberUserInfo/RememberCurses.php index a621f92..a622729 100644 --- a/helpers/RememberUserInfo/RememberCurses.php +++ b/helpers/RememberUserInfo/RememberCurses.php @@ -7,9 +7,17 @@ class RememberCurses extends RememberHelper { - protected function norminateTheResponse() + protected function init() { - foreach ($this->response['cursus_users'] as &$curs) { + $this->responseSubSet =& $this->response['projects_users']; + $this->model = new Curses(); + } + + protected function norminate() + { + $this->responseSubSet =& $this->response['cursus_users']; + + foreach ($this->responseSubSet as &$curs) { self::dateToSqlFormat($curs['begin_at']); self::swapKeysInArr($curs, [ 'id' => 'xid' ]); self::mergeChildArrByKey($curs, 'cursus'); @@ -20,12 +28,10 @@ protected function norminateTheResponse() } } - public function rememberToDB() + protected function remember() { - $curses = new Curses(); - - foreach ($this->response['cursus_users'] as &$curs) { - self::saveChangesToDB($curses, $curs, $curses->find() + foreach ($this->responseSubSet as &$curs) { + self::saveChangesToDB($this->model, $curs, $this->model->find() ->Where([ 'xlogin' => $curs['xlogin'] ]) ->andWhere([ 'cursus_id' => $curs['cursus_id'] ]) ->all()); diff --git a/helpers/RememberUserInfo/RememberHelper.php b/helpers/RememberUserInfo/RememberHelper.php index feade1c..98499c0 100644 --- a/helpers/RememberUserInfo/RememberHelper.php +++ b/helpers/RememberUserInfo/RememberHelper.php @@ -5,25 +5,37 @@ abstract class RememberHelper { - abstract public function rememberToDB(); - abstract protected function norminateTheResponse(); + abstract protected function init(); + abstract protected function remember(); + abstract protected function norminate(); protected $response; + protected $responseSubSet; + protected $model; + public function __construct(&$response) { $this->response =& $response; - static::norminateTheResponse(); - static::rememberToDB(); + $this->init(); + + $this->norminate(); + $this->remember(); + } + + + protected function setXlogin(&$arrToSetXlogin, $xloginKey = 'xlogin') + { + $arrToSetXlogin[$xloginKey] = $this->response['login']; } protected static function isArraysIdentical($a1, $a2, $arrayKeysToCompare) { - foreach ($arrayKeysToCompare as $keyFor_both) { - if ($a1[$keyFor_both] != $a2[$keyFor_both]) { + foreach ($arrayKeysToCompare as $keyForBoth) { + if ($a1[$keyForBoth] != $a2[$keyForBoth]) { return false; } } @@ -70,7 +82,7 @@ protected static function saveChangesToDB($baseActiveRecordModel, $arrToPutIntoD if ( $identicalNotFound && $index == $len ) { $AR->attributes = $arrToPutIntoDb; - $AR->update(false); + $AR->save(false); } else { $AR->delete(); } diff --git a/helpers/RememberUserInfo/RememberLevel.php b/helpers/RememberUserInfo/RememberLevel.php index e2b4ab3..47374b9 100644 --- a/helpers/RememberUserInfo/RememberLevel.php +++ b/helpers/RememberUserInfo/RememberLevel.php @@ -7,9 +7,10 @@ class RememberLevel extends RememberHelper { - protected function norminateTheResponse() { } + protected function init() { } + protected function norminate() { } - public function rememberToDB() + protected function remember() { Yii::$app->session->set('level', $this->response['cursus_users'][0]['level']); } diff --git a/helpers/RememberUserInfo/RememberProjects.php b/helpers/RememberUserInfo/RememberProjects.php index f3ae349..96a07c7 100644 --- a/helpers/RememberUserInfo/RememberProjects.php +++ b/helpers/RememberUserInfo/RememberProjects.php @@ -7,10 +7,17 @@ class RememberProjects extends RememberHelper { - protected function norminateTheResponse() + protected function init() { - foreach ($this->response['projects_users'] as &$project) { - $project['xlogin'] = $this->response['login']; + $this->responseSubSet =& $this->response['projects_users']; + $this->model = new ProjectsAll(); + } + + protected function norminate() + { + + foreach ($this->responseSubSet as &$project) { + $this->setXlogin($project); $project['cursus_ids'] = $project['cursus_ids'][0]; // ??? WTF $project['validated?'] = $project['validated?'] ? 'True' : 'False'; // $project['marked'] = $project['marked'] ? 'True' : 'False'; @@ -22,12 +29,10 @@ protected function norminateTheResponse() } } - public function rememberToDB() + protected function remember() { - $pusers = new ProjectsAll(); - - foreach ($this->response['projects_users'] as &$project) { - self::saveChangesToDB($pusers, $project, $pusers->find() + foreach ($this->responseSubSet as &$project) { + self::saveChangesToDB($this->model, $project, $this->model->find() ->Where([ 'puid' => $project['puid'] ]) ->andWhere([ 'xlogin' => $project['xlogin'] ]) ->all()); diff --git a/helpers/RememberUserInfo/RememberShow.php b/helpers/RememberUserInfo/RememberShow.php index 7700a5f..1fa366e 100644 --- a/helpers/RememberUserInfo/RememberShow.php +++ b/helpers/RememberUserInfo/RememberShow.php @@ -7,18 +7,26 @@ class RememberShow extends RememberHelper { - protected function norminateTheResponse() + protected function init() { - self::swapKeysInArr($this->response, [ 'id' => 'xid' ]); + $this->responseSubSet =& $this->response['projects_users']; + $this->model = new Show(); } - public function rememberToDB() + protected function norminate() { - $show = new Show(); + $this->responseSubSet =& $this->response; - self::saveChangesToDB($show, $this->response, $show->find() - ->Where([ 'xid' => $this->response['xid'] ]) - ->orWhere([ 'login' => $this->response['login'] ]) + $this->responseSubSet['kick'] = 0; // ??? WTF + $this->responseSubSet['lastloc'] = date('Y-m-d H:i:s'); // ??? WTF + self::swapKeysInArr($this->responseSubSet, [ 'id' => 'xid' ]); + } + + protected function remember() + { + self::saveChangesToDB($this->model, $this->responseSubSet, $this->model->find() + ->Where([ 'xid' => $this->responseSubSet['xid'] ]) + ->orWhere([ 'login' => $this->responseSubSet['login'] ]) ->all()); } diff --git a/helpers/RememberUserInfo/RememberSkills.php b/helpers/RememberUserInfo/RememberSkills.php index 34e1237..7a742e7 100644 --- a/helpers/RememberUserInfo/RememberSkills.php +++ b/helpers/RememberUserInfo/RememberSkills.php @@ -7,24 +7,30 @@ class RememberSkills extends RememberHelper { - protected function norminateTheResponse() + protected function init() { - foreach ($this->response['cursus_users'] as &$cursus) { + $this->responseSubSet =& $this->response['projects_users']; + $this->model = new Skills(); + } + + protected function norminate() + { + $this->responseSubSet =& $this->response['cursus_users']; + + foreach ($this->responseSubSet as &$cursus) { foreach ($cursus['skills'] as &$skill) { - $skill['xlogin'] = $this->response['login']; - $skill['cursus_id'] = $cursus['skills']['cursus_id']; + $this->setXlogin($skill); + $skill['cursus_id'] = $cursus['cursus_id']; self::swapKeysInArr($skill, [ 'id' => 'skills_id', 'name' => 'skills_name', 'level' => 'skills_level' ]); } } } - public function rememberToDB() + protected function remember() { - $skills = new Skills(); - - foreach ($this->response['cursus_users'] as &$cursus) { + foreach ($this->responseSubSet as &$cursus) { foreach ($cursus['skills'] as &$skill) { - self::saveChangesToDB($skills, $skill, $skills->find() + self::saveChangesToDB($this->model, $skill, $this->model->find() ->Where([ 'skills_id' => $skill['skills_id'] ]) ->andWhere([ 'xlogin' => $skill['xlogin'] ]) ->all()); diff --git a/helpers/RememberUserInfo/RememberUserInfo.php b/helpers/RememberUserInfo/RememberUserInfo.php index 0bef53b..3b78dd7 100644 --- a/helpers/RememberUserInfo/RememberUserInfo.php +++ b/helpers/RememberUserInfo/RememberUserInfo.php @@ -20,3 +20,4 @@ public static function rememberAllToDB($response) } } +// WHERE `xlogin`='vbrazas' diff --git a/models/Show.php b/models/Show.php index 651c716..cc50ed3 100644 --- a/models/Show.php +++ b/models/Show.php @@ -64,16 +64,6 @@ public function rules() ]; } - /** - * {@inheritdoc} - */ - public function init() - { - $this->kick = 0; // ??? WTF - $this->lastloc = date('Y-m-d H:i:s'); // ??? WTF - parent::init(); - } - /** * {@inheritdoc} */