Skip to content

Commit

Permalink
Dev: TODO-s User: get $parentUser as relation (#831)
Browse files Browse the repository at this point in the history
Dev: TODO-s User: get $parentUser as relation
Dev: TODO-s User: get $parentUser as relation: remove initial method
  • Loading branch information
TonisOrmisson authored and LouisGac committed Oct 9, 2017
1 parent e6d6599 commit ad92d8e
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions application/models/User.php
Expand Up @@ -31,6 +31,8 @@
* @property string $modified Time modified Time created Time user was modified as 'YYYY-MM-DD hh:mm:ss'
*
* @property Permission[] $permissions
* @property User $parentUser Parent user
* @property string $parentUserName Parent user's name
*/
class User extends LSActiveRecord
{
Expand Down Expand Up @@ -60,6 +62,14 @@ public function primaryKey()
{
return 'uid';
}
/** @inheritdoc */
public function relations()
{
return array(
'permissions' => array(self::HAS_MANY, 'Permission', 'uid'),
'parentUser' => array(self::HAS_ONE, 'User', array('uid' => 'parent_id') ),
);
}

/** @inheritdoc */
public function rules()
Expand Down Expand Up @@ -109,16 +119,6 @@ public function parentAndUser($postuserid)
return $user;
}

/**
* TODO via relation
* @return mixed
*/
public function getParentUser(){
$parent_user = $this->parentAndUser( $this->uid );
return $parent_user['parent'];
}


/**
* @return string
*/
Expand Down Expand Up @@ -278,13 +278,6 @@ public function getCommonUID($surveyid, $postusergroupid)
return Yii::app()->db->createCommand($query2)->bindParam(":surveyid", $surveyid, PDO::PARAM_INT)->bindParam(":postugid", $postusergroupid, PDO::PARAM_INT)->query(); //Checked
}

/** @inheritdoc */
public function relations()
{
return array(
'permissions' => array(self::HAS_MANY, 'Permission', 'uid')
);
}

/**
* Return all super admins in the system
Expand Down Expand Up @@ -416,6 +409,15 @@ class='btn btn-default btn-xs '>
. "</div>";
}

public function getParentUserName(){
if($this->parentUser){
return $this->parentUser->users_name;
}
// root user, no parent
return null;
}


/**
* @return array
*/
Expand Down Expand Up @@ -452,8 +454,8 @@ public function getColums(){
}

$cols[] = array(
"name" => 'parentUser',
"header" => gT("Created by")
"name" =>"parentUserName",
"header" => gT("Created by"),
);
return $cols;
}
Expand Down

0 comments on commit ad92d8e

Please sign in to comment.