fromId() public static method

Initiliaze from id
public static fromId ( integer $userId ) : Model
$userId integer User id
return Model
Ejemplo n.º 1
0
 /**
  * Get user model
  *
  * @return \Gc\User\Model
  */
 public function getUser()
 {
     if ($this->getData('user') === null and $this->getUserId() != null) {
         $this->setData('user', User\Model::fromId($this->getUserId()));
     }
     return $this->getData('user');
 }
Ejemplo n.º 2
0
 /**
  * Test
  *
  * @return void
  */
 public function testFromFakeId()
 {
     $this->assertFalse(Model::fromId(10000));
 }
Ejemplo n.º 3
0
 /**
  * Retrieve user who trigger the event
  *
  * @return boolean|\Gc\User\Model
  */
 public function getUser()
 {
     if ($this->hasData('user') === false) {
         $this->setData('user', UserModel::fromId($this->getUserId()));
     }
     return $this->getData('user');
 }
Ejemplo n.º 4
0
 /**
  * Edit user
  *
  * @return \Zend\View\Model\ViewModel|array
  */
 public function editAction()
 {
     $userId = $this->getRouteMatch()->getParam('id');
     $userModel = User\Model::fromId($userId);
     if (empty($userModel)) {
         $this->flashMessenger()->addErrorMessage("Can't edit this user");
         return $this->redirect()->toRoute('config/user');
     }
     $form = new UserForm();
     $form->setAttribute('action', $this->url()->fromRoute('config/user/edit', array('id' => $userId)));
     $form->loadValues($userModel);
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost()->toArray();
         if (!empty($post['password'])) {
             $form->passwordRequired();
             $form->getInputFilter()->get('password_confirm')->getValidatorChain()->addValidator(new Identical($post['password']));
         }
         $form->setData($post);
         if ($form->isValid()) {
             $userModel->addData($post);
             $userModel->setActive(empty($post['active']) ? false : $post['active']);
             if (!empty($post['password'])) {
                 $userModel->setPassword($post['password']);
             }
             $userModel->save();
             $this->flashMessenger()->addSuccessMessage('This user has been saved');
             return $this->redirect()->toRoute('config/user/edit', array('id' => $userId));
         }
         $this->flashMessenger()->addErrorMessage('User can not be saved');
     }
     return array('form' => $form);
 }