Skip to content

Commit

Permalink
[WIP][unitfactoryAlumni#66] Update behaviour setted right, CursusUser…
Browse files Browse the repository at this point in the history
…s is now inserting
  • Loading branch information
vbrazas committed Apr 6, 2019
1 parent 56b78a3 commit d610684
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 2,842 deletions.
2 changes: 1 addition & 1 deletion helpers/Auth42.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function fetchMe($params)
->setHeaders($params);
$response = $this->sendRequest($request);

RememberUserInfo::rememberAll($response);
(new RememberUserInfo($response))->rememberAll();

$profileLink = '/pools/';
if (isset($response['cursus_users'])) {
Expand Down
53 changes: 40 additions & 13 deletions helpers/RememberUserInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,60 @@

use Yii;
use app\models\Xlogins;
use app\models\Skills;
use app\models\CursusUsers;

class RememberUserInfo
{
public static function rememberAll($response = null)

public $response = null;

public function __construct($response = null)
{
$this->response = $response;
}

public function rememberAll()
{
if ($response === null) {
if ($this->response === null) {
return ;
}

static::rememberLevel($response);
static::rememberXlogin($response);
$this->rememberLevel();
$this->rememberXlogin();
$this->rememberCursusUsersAndSkills();
}

private static function rememberLevel($response)
private function rememberLevel()
{
$session = Yii::$app->session;
if (!$session->isActive) {
$session->open();
}
$session->set('level', $response['cursus_users'][0]['level']);
Yii::$app->session->set('level', $this->response['cursus_users'][0]['level']);
}

private static function rememberXlogin($response)
private function rememberXlogin()
{
$xlogins = new Xlogins();
$xlogins->attributes = $xlogins->findOne(['xid' => $response['id']]);
$xlogins->attributes = $response;
$xlogins = $xlogins->findOne(['xid' => $this->response['id']]);
$xlogins->attributes = $this->response;
$xlogins->save(false);
}

private function rememberCursusUsersAndSkills()
{
$cursusUsers = new CursusUsers();
$skills = new Skills();
$cursus_users = $this->response['cursus_users'];

$skills->attributes = $skills->findOne(['xlogin' => $this->response['login']]); // ? Is this check considers enough?
$cursus_users[0]['grade'] = 'lol';
foreach ($cursus_users as $v) {
// foreach ($v['skills'] as $k => $v) {
//
// }
$cursusUsers = $cursusUsers->findOne(['cursus_users_id' => $v['id']]);
$v['begin_at'] = date('Y-m-d H:i:s', strtotime($v['begin_at'])); // ! normilizing time format for mySQL
$cursusUsers->attributes = $v;
$cursusUsers->save(false);
}
}
}
70 changes: 70 additions & 0 deletions models/CursusUsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace app\models;

use Yii;

/**
* This is the model class for table "cursus_users".
*
* @property int $id
* @property string $xlogin
* @property int $cursus_id
* @property string $begin_at
* @property string $created_at
* @property string $name
* @property string $slug
* @property string $end_at
* @property string $grade
* @property string $has_coalition
* @property int $cursus_users_id
* @property double $level
* @property int $xid
*/
class CursusUsers extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'cursus_users';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['cursus_id', 'cursus_users_id', 'xid'], 'integer'],
[['begin_at'], 'safe'],
[['created_at', 'end_at'], 'string'],
[['level'], 'number'],
[['xlogin', 'has_coalition'], 'string', 'max' => 12],
[['name', 'slug', 'grade'], 'string', 'max' => 255],
];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'xlogin' => Yii::t('app', 'Xlogin'),
'cursus_id' => Yii::t('app', 'Cursus ID'),
'begin_at' => Yii::t('app', 'Begin At'),
'created_at' => Yii::t('app', 'Created At'),
'name' => Yii::t('app', 'Name'),
'slug' => Yii::t('app', 'Slug'),
'end_at' => Yii::t('app', 'End At'),
'grade' => Yii::t('app', 'Grade'),
'has_coalition' => Yii::t('app', 'Has Coalition'),
'cursus_users_id' => Yii::t('app', 'Cursus Users ID'),
'level' => Yii::t('app', 'Level'),
'xid' => Yii::t('app', 'Xid'),
];
}
}
Loading

0 comments on commit d610684

Please sign in to comment.