Esempio n. 1
0
 /**
  * Save user into the database
  *
  * @param void
  * @return boolean
  */
 function save()
 {
     $modified_fields = $this->modified_fields;
     $is_new = $this->isNew();
     if ($is_new && $this->getToken() == '') {
         $this->resetToken();
     }
     // if
     $save = parent::save();
     if ($save && !is_error($save)) {
         if ($is_new || in_array('email', $modified_fields) || in_array('first_name', $modified_fields) || in_array('last_name', $modified_fields)) {
             $content = $this->getEmail();
             if ($this->getFirstName() || $this->getLastName()) {
                 $content .= "\n\n" . trim($this->getFirstName() . ' ' . $this->getLastName());
             }
             // if
             search_index_set($this->getId(), 'User', $content);
             cache_remove_by_pattern('object_assignments_*_rendered');
         }
         // if
         // Role changed?
         if (in_array('role_id', $modified_fields)) {
             clean_user_permissions_cache($this);
         }
         // if
     }
     // if
     return $save;
 }
 /**
  * Remove given user from this project
  *
  * @param User $user
  * @return boolean
  */
 function removeUser($user)
 {
     $project_user = ProjectUsers::findById(array('user_id' => $user->getId(), 'project_id' => $this->getId()));
     if (instance_of($project_user, 'ProjectUser')) {
         db_begin_work();
         $delete = $project_user->delete();
         if ($delete && !is_error($delete)) {
             clean_user_permissions_cache($user);
             event_trigger('on_project_user_removed', array($this, $user));
             db_commit();
             return true;
         } else {
             db_rollback();
             return $delete;
         }
         // if
     }
     // if
     return true;
 }