Skip to content

Commit

Permalink
DEV: remove User::getName($id) with $oUser->full_name (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson authored and Shnoulle committed Jul 7, 2017
1 parent 7139172 commit 10e1ef8
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 77 deletions.
27 changes: 13 additions & 14 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -1839,45 +1839,44 @@ public function getShareInfo_json()
$aData->page = 1;

// If super administrator all the share info in the links table will be shown
if (Permission::model()->hasGlobalPermission('superadmin','read'))
{
if (Permission::model()->hasGlobalPermission('superadmin','read')) {
$records = Participant::model()->getParticipantSharedAll();
$aData->records = count($records);
$aData->total = ceil($aData->records / 10);
$i = 0;

foreach ($records as $row)
{
foreach ($records as $row) {
//for conversion of uid to human readable names
$iShareUserId = $row['share_uid'];
if ($iShareUserId != 0) {
$oShared = User::model()->getName($iShareUserId);
$sSharename = $oShared['full_name'];
/** @var User $oUser */
$oUser = User::model()->findByPk($iShareUserId);
$sSharename = $oUser->full_name;
} else {
$sSharename = 'All users';
}
$owner = User::model()->getName($row['owner_uid']);
/** @var User $owner */
$owner = User::model()->findByPk($row['owner_uid']);
$aData->rows[$i]['id'] = $row['participant_id']."--".$row['share_uid']; //This is the unique combination per record
$aData->rows[$i]['cell'] = array($row['firstname'], $row['lastname'], $row['email'], $sSharename, $row['share_uid'], $owner['full_name'], $row['date_added'], $row['can_edit']);
$aData->rows[$i]['cell'] = array($row['firstname'], $row['lastname'], $row['email'], $sSharename, $row['share_uid'], $owner->full_name, $row['date_added'], $row['can_edit']);
$i++;
}

echo ls_json_encode($aData);
}
// otherwise only the shared participants by that user
else
{
else {
$records = Participant::model()->getParticipantShared(Yii::app()->session['loginID']);
$aData->records = count($records);
$aData->total = ceil($aData->records / 10);
$i = 0;

foreach ($records as $row)
{
foreach ($records as $row) {
$iShareUserId = $row['share_uid'];//for conversion of uid to human readable names
if ($iShareUserId != 0) {
$oShared = User::model()->getName($iShareUserId);
$sSharename = $oShared['full_name'];
/** @var User $oUser */
$oUser = User::model()->findByPk($iShareUserId);
$sSharename = $oUser->full_name;
} else {
$sSharename = 'All users';
}
Expand Down
47 changes: 18 additions & 29 deletions application/controllers/admin/useraction.php
Expand Up @@ -336,23 +336,22 @@ public function deleteFinalUser($result, $transfer_surveys_to)
public function modifyuser()
{

if ( Yii::app()->request->getParam('uid') !='' )
{
if ( Yii::app()->request->getParam('uid') !='' ) {
$postuserid = (int) Yii::app()->request->getParam("uid");
$sresult = User::model()->findAllByAttributes(array('uid' => $postuserid, 'parent_id' => Yii::app()->session['loginID']));
$sresultcount = count($sresult);


if (Permission::model()->hasGlobalPermission('superadmin','read') || Yii::app()->session['loginID'] == $postuserid ||
(Permission::model()->hasGlobalPermission('users','update') && $sresultcount > 0) )
{
(Permission::model()->hasGlobalPermission('users','update') && $sresultcount > 0) ) {
$sresult = User::model()->parentAndUser($postuserid);
if(empty($sresult))
{
if(empty($sresult)) {
Yii::app()->setFlashMessage(gT("You do not have permission to access this page."),'error');
$this->getController()->redirect(array("admin/user/sa/index"));
}
$oUser = User::model()->findByPk($postuserid);
$aData = array();
$aData['oUser'] = $oUser;
$aData['aUserData'] = $sresult;

$aData['fullpagebar']['savebutton']['form'] = 'moduserform';
Expand Down Expand Up @@ -389,59 +388,49 @@ public function moduser()
$sresultcount = count($sresult);

if ((Permission::model()->hasGlobalPermission('superadmin','read') || $postuserid == Yii::app()->session['loginID'] ||
($sresultcount > 0 && Permission::model()->hasGlobalPermission('users','update'))) && !(Yii::app()->getConfig("demoMode") == true && $postuserid == 1)
)
{
($sresultcount > 0 && Permission::model()->hasGlobalPermission('users','update'))) && !(Yii::app()->getConfig("demoMode") == true && $postuserid == 1)) {

$users_name = html_entity_decode($postuser, ENT_QUOTES, 'UTF-8');
$email = html_entity_decode($postemail, ENT_QUOTES, 'UTF-8');
$sPassword = Yii::app()->request->getPost('password');

$full_name = html_entity_decode($postfull_name, ENT_QUOTES, 'UTF-8');

if (!validateEmailAddress($email))
{
if (!validateEmailAddress($email)) {
Yii::app()->setFlashMessage( gT("Could not modify user data."). ' '. gT("Email address is not valid."),'error');
$this->getController()->redirect(array("/admin/user/sa/modifyuser/uid/".$postuserid));
}
else
{
} else {
$oRecord = User::model()->findByPk($postuserid);
$oRecord->email= $email;
$oRecord->full_name= $full_name;
if (!empty($sPassword))
{
if (!empty($sPassword)) {
$oRecord->password= hash('sha256', $sPassword);
}
$uresult = $oRecord->save(); // store result of save in uresult

if (empty($sPassword))
{
if (empty($sPassword)) {
Yii::app()->setFlashMessage( gT("Success!") .' <br/> '.gT("Password") . ": (" . gT("Unchanged") . ")", 'success');
$this->getController()->redirect(array("/admin/user/sa/modifyuser/uid/".$postuserid));
}
elseif ($uresult && !empty($sPassword)) // When saved successfully
{

} elseif ($uresult && !empty($sPassword)) {
// When saved successfully

Yii::app()->session['pw_notify'] = $sPassword != '';
if ($display_user_password_in_html === true) {
$displayedPwd = htmlentities($sPassword);
}
else {
} else {
$displayedPwd = preg_replace('/./', '*', $sPassword);
}
Yii::app()->setFlashMessage( gT("Success!") .' <br/> '.gT("Password") . ": " . $displayedPwd, 'success');
$this->getController()->redirect(array("/admin/user/sa/modifyuser/uid/".$postuserid));
}
else
{
} else {
//Saving the user failed for some reason, message about email is not helpful here
// Username and/or email adress already exists.
Yii::app()->setFlashMessage( gT("Could not modify user data."),'error');
$this->getController()->redirect(array("/admin/user/sa/modifyuser/uid/".$postuserid));
}
}
}
else
{
} else {
Yii::app()->setFlashMessage( gT("Could not modify user data."),'error');
$this->getController()->redirect(array("/admin/"));
}
Expand Down
5 changes: 3 additions & 2 deletions application/models/Participant.php
Expand Up @@ -536,8 +536,9 @@ public function getOwnersList($selected){
->queryAll();
$ownerList = array(''=>"");
foreach($owner_ids as $id){
$user = User::model()->getName($id['owner_uid']);
$ownerList[$id['owner_uid']] = $user['full_name'];
/** @var User $oUser */
$oUser = User::model()->findByPk($id['owner_uid']);
$ownerList[$id['owner_uid']] = $oUser->full_name;
}
return TbHtml::dropDownList('Participant[owner_uid]',$selected, $ownerList);

Expand Down
5 changes: 3 additions & 2 deletions application/models/ParticipantShare.php
Expand Up @@ -105,8 +105,9 @@ public function getSharedByList($selected)
if ($id['share_uid'] == -1) {
continue;
}
$user = User::model()->getName($id['share_uid']);
$shareList[$id['share_uid']] = $user['full_name'];
/** @var User $oUser */
$oUser = User::model()->findByPk($id['share_uid']);
$shareList[$id['share_uid']] = $oUser->full_name;
}
return TbHtml::dropDownList('ParticipantShare[share_uid]',$selected, $shareList);
}
Expand Down
38 changes: 9 additions & 29 deletions application/models/User.php
Expand Up @@ -225,27 +225,6 @@ public function getShareSetting()
return $result->row();
}

/**
* Returns full name of user
*
* @access public
* @param integer $userid
* @return string
*/
public function getName($userid)
{
// TODO should be accessed via $oUser->name (without param)
static $aOwnerCache = array();

if (array_key_exists($userid, $aOwnerCache)) {
$result = $aOwnerCache[$userid];
} else {
$result = Yii::app()->db->createCommand()->select('full_name')->from('{{users}}')->where("uid = :userid")->bindParam(":userid", $userid, PDO::PARAM_INT)->queryRow();
$aOwnerCache[$userid] = $result;
}

return $result;
}

public function getuidfromparentid($parentid)
{
Expand All @@ -257,6 +236,7 @@ public function getuidfromparentid($parentid)
->bindParam(":parent_id", $parentid, PDO::PARAM_INT)
->queryRow();
}

/**
* Returns id of user
*
Expand Down Expand Up @@ -349,15 +329,15 @@ public function getButtons(){
$setTemplatePermissionsUrl = Yii::app()->getController()->createUrl('admin/user/sa/setusertemplates');
$changeOwnershipUrl = Yii::app()->getController()->createUrl('admin/user/sa/setasadminchild');

$oUser = $this->getName($this->uid);

if($this->uid == Yii::app()->user->getId())
{
$editUser = "<button
data-toggle='tooltip'
title='".gT("Edit this user")."'
data-url='".$editUrl."'
data-uid='".$this->uid."'
data-user='".$oUser['full_name']."'
data-user='".$this->full_name."'
data-action='modifyuser'
class='btn btn-default btn-xs action_usercontrol_button'>
<span class='fa fa-pencil text-success'></span>
Expand All @@ -374,7 +354,7 @@ class='btn btn-default btn-xs action_usercontrol_button'>
data-onclick='$.post(".$deleteUrl.",{
action: \"deluser\",
uid:\"".$this->uid."\",
user: \"".htmlspecialchars($oUser['full_name'])."\",
user: \"".htmlspecialchars($this->full_name)."\",
});'
data-target='#confirmation-modal'
data-uid='".$this->uid."'
Expand All @@ -390,7 +370,7 @@ class='btn btn-default btn-xs'>
|| (Permission::model()->hasGlobalPermission('users','update')
&& $this->parent_id == Yii::app()->session['loginID'])) {

$editUser = "<button data-toggle='tooltip' data-url='".$editUrl."' data-user='".htmlspecialchars($oUser['full_name'])."' data-uid='".$this->uid."' data-action='modifyuser' title='".gT("Edit this user")."' type='submit' class='btn btn-default btn-xs action_usercontrol_button'><span class='fa fa-pencil text-success'></span></button>";
$editUser = "<button data-toggle='tooltip' data-url='".$editUrl."' data-user='".htmlspecialchars($this->full_name)."' data-uid='".$this->uid."' data-action='modifyuser' title='".gT("Edit this user")."' type='submit' class='btn btn-default btn-xs action_usercontrol_button'><span class='fa fa-pencil text-success'></span></button>";
}

if (((Permission::model()->hasGlobalPermission('superadmin','read') &&
Expand All @@ -399,14 +379,14 @@ class='btn btn-default btn-xs'>
$this->parent_id == Yii::app()->session['loginID'])) && $this->uid!=1) {

//'admin/user/sa/setuserpermissions'
$setPermissionsUser = "<button data-toggle='tooltip' data-user='".htmlspecialchars($oUser['full_name'])."' data-url='".$setPermissionsUrl."' data-uid='".$this->uid."' data-action='setuserpermissions' title='".gT("Set global permissions for this user")."' type='submit' class='btn btn-default btn-xs action_usercontrol_button'><span class='icon-security text-success'></span></button>";
$setPermissionsUser = "<button data-toggle='tooltip' data-user='".htmlspecialchars($this->full_name)."' data-url='".$setPermissionsUrl."' data-uid='".$this->uid."' data-action='setuserpermissions' title='".gT("Set global permissions for this user")."' type='submit' class='btn btn-default btn-xs action_usercontrol_button'><span class='icon-security text-success'></span></button>";
}
if ((Permission::model()->hasGlobalPermission('superadmin','read')
|| Permission::model()->hasGlobalPermission('templates','read'))
&& $this->uid!=1) {

//'admin/user/sa/setusertemplates')
$setTemplatePermissionUser = "<button type='submit' data-user='".htmlspecialchars($oUser['full_name'])."' data-url='".$setTemplatePermissionsUrl."' data-uid='".$this->uid."' data-action='setusertemplates' data-toggle='tooltip' title='".gT("Set template permissions for this user")."' class='btn btn-default btn-xs action_usercontrol_button'><span class='icon-templatepermissions text-success'></span></button>";
$setTemplatePermissionUser = "<button type='submit' data-user='".htmlspecialchars($this->full_name)."' data-url='".$setTemplatePermissionsUrl."' data-uid='".$this->uid."' data-action='setusertemplates' data-toggle='tooltip' title='".gT("Set template permissions for this user")."' class='btn btn-default btn-xs action_usercontrol_button'><span class='icon-templatepermissions text-success'></span></button>";
}
if ((Permission::model()->hasGlobalPermission('superadmin','read')
|| (Permission::model()->hasGlobalPermission('users','delete')
Expand All @@ -425,7 +405,7 @@ class='btn btn-default btn-xs'>
data-target='#confirmation-modal'
data-url='".$deleteUrl."'
data-uid='".$this->uid."'
data-user='".htmlspecialchars($oUser['full_name'])."'
data-user='".htmlspecialchars($this->full_name)."'
data-action='deluser'
data-onclick='triggerRunAction($(\"#delete_user_".$this->uid."\"))'
data-message='".gT("Do you want to delete this user?")."'
Expand All @@ -436,7 +416,7 @@ class='btn btn-default btn-xs '>

if (Yii::app()->session['loginID'] == "1" && $this->parent_id !=1 ) {
//'admin/user/sa/setasadminchild'
$changeOwnership = "<button data-toggle='tooltip' data-url='".$changeOwnershipUrl."' data-user='".htmlspecialchars($oUser['full_name'])."' data-uid='".$this->uid."' data-action='setasadminchild' title='".gT("Take ownership")."' class='btn btn-default btn-xs action_usercontrol_button' type='submit'><span class='icon-takeownership text-success'></span></button>";
$changeOwnership = "<button data-toggle='tooltip' data-url='".$changeOwnershipUrl."' data-user='".htmlspecialchars($this->full_name)."' data-uid='".$this->uid."' data-action='setasadminchild' title='".gT("Take ownership")."' class='btn btn-default btn-xs action_usercontrol_button' type='submit'><span class='icon-takeownership text-success'></span></button>";
}
}
return "<div>"
Expand Down
8 changes: 7 additions & 1 deletion application/views/admin/user/modifyuser.php
@@ -1,3 +1,8 @@
<?php
/**
* @var User $oUser
*/
?>
<div class="pagetitle h3"><?php eT("Editing user");?></div>

<div class="row" style="margin-bottom: 100px">
Expand Down Expand Up @@ -37,5 +42,6 @@
<input type='submit' class="hidden" value='<?php eT("Save");?>' />
<input type='hidden' name='action' value='moduser' />
</p>
</form>

<?php echo CHtml::endForm()?>

0 comments on commit 10e1ef8

Please sign in to comment.