/**
  * Generates a display-friendly list of assignees
  * 
  * @param mixed $value If specified, use as the assignment instead of the
  *  current model's assignment field.
  */
 public function getAssigneeNames($value = false)
 {
     $assignment = !$value ? $this->owner->getAttribute($this->getAssignmentAttr()) : $value;
     $assignees = !is_array($assignment) ? explode(', ', $assignment) : $assignment;
     $groupIds = array_filter($assignees, 'ctype_digit');
     $userNames = array_diff($assignees, $groupIds);
     $userNameParam = AuxLib::bindArray($userNames);
     $userFullNames = !empty($userNames) ? array_map(function ($u) {
         return Formatter::fullName($u['firstName'], $u['lastName']);
     }, Yii::app()->db->createCommand()->select('firstName,lastName')->from(User::model()->tableName())->where('username IN ' . AuxLib::arrToStrList(array_keys($userNameParam)), $userNameParam)->queryAll()) : array();
     $groupIdParam = AuxLib::bindArray($groupIds);
     $groupNames = !empty($groupIds) ? Yii::app()->db->createCommand()->select('name')->from(Groups::model()->tableName())->where('id IN ' . AuxLib::arrToStrList(array_keys($groupIdParam)), $groupIdParam)->queryColumn() : array();
     return array_merge($userFullNames, $groupNames);
 }
Exemple #2
0
 /**
  * Returns the full name of the user.
  */
 public function getFullName()
 {
     if (!isset($this->_fullName)) {
         $this->_fullName = Formatter::fullName($this->firstName, $this->lastName);
     }
     return $this->_fullName;
 }
 public static function getEditableUserCalendarNames()
 {
     $users = User::model()->findAll(array('select' => 'id, username, firstName, lastName', 'index' => 'id'));
     $names = array('Anyone' => 'Anyone');
     // array mapping username to user's full name for user calendars we can edit
     if (Yii::app()->params->isAdmin) {
         foreach ($users as $user) {
             $first = $user->firstName;
             $last = $user->lastName;
             $fullname = Formatter::fullName($first, $last);
             $username = $user->username;
             $names[$username] = $fullname;
         }
     } else {
         $permissions = X2CalendarPermissions::model()->findAll(array('select' => 'user_id, other_user_id, edit', 'condition' => 'other_user_id=:user_id', 'params' => array(':user_id' => Yii::app()->user->id), 'index' => 'user_id'));
         /* x2tempstart */
         // safeguard to prevent invalid permissions from being used
         // TODO: write migration script to delete old invalid permissions
         $permissions = array_filter($permissions, function ($permission) use($users) {
             return in_array($permission->user_id, array_keys($users));
         });
         /* x2tempend */
         $checked = array();
         // user's who have there permission set up. Other user's will have default permissions
         foreach ($permissions as $permission) {
             // loop through user's that have set there permissions
             if ($permission->edit) {
                 // user gives us permission to view there calendar?
                 $user = $users[$permission->user_id];
                 $first = $user->firstName;
                 $last = $user->lastName;
                 $fullname = Formatter::fullName($first, $last);
                 $username = $user->username;
                 $names[$username] = $fullname;
             }
             $checked[] = $permission->user_id;
         }
         // user's who have not set permissions default to not letting everyone edit there calendar
         // let current user edit there own calendar
         $user = $users[Yii::app()->user->id];
         $first = $user->firstName;
         $last = $user->lastName;
         $fullname = Formatter::fullName($first, $last);
         $username = $user->username;
         $names[$username] = $fullname;
     }
     return $names;
 }