public function update(array $data)
 {
     $object = User::findFirstById($data['id']);
     if (!$object) {
         throw new \Exception('Object not found');
     }
     $security = $this->getDI()->get('security');
     $object->setUserFirstName($data['user_first_name']);
     $object->setUserLastName($data['user_last_name']);
     $object->setUserEmail($data['user_email']);
     $object->setUserPassword($security->hash($data['user_password']));
     $object->setUserIsActive($data['user_is_active']);
     $o_acl_role = AclRoles::findFirstByName($data['user_acl_role']);
     if (!$o_acl_role) {
         throw new \Exception("Role {$user_role} does not exists");
     }
     $o_user_role[0] = new UserRole();
     $o_user_role[0]->setUserRole($data['user_acl_role']);
     $object->roles = $o_user_role;
     $object->profile->setUserProfileLocation($data['user_profile_location']);
     return $this->save($object, 'update');
 }
Beispiel #2
0
 public function initialize($entity = null, $options = null)
 {
     if (isset($options['edit']) && $options['edit'] === true) {
         $this->edit = true;
     }
     // First name
     $user_first_name = new Text('user_first_name', array('placeholder' => 'First name'));
     $user_first_name->addValidators(array(new PresenceOf(array('message' => 'First name is required'))));
     $this->add($user_first_name);
     // Last name
     $user_last_name = new Text('user_last_name', array('placeholder' => 'Last name'));
     $user_last_name->addValidators(array(new PresenceOf(array('message' => 'Last name is required'))));
     $this->add($user_last_name);
     // Email
     $user_email = new Text('user_email', array('placeholder' => 'Email'));
     $user_email->addValidators(array(new PresenceOf(array('message' => 'The e-mail is required')), new Email(array('message' => 'The e-mail is not valid'))));
     $this->add($user_email);
     //Password
     $user_password = new Password('user_password', array('placeholder' => 'Password'));
     $user_password->addValidators(array(new PresenceOf(array('message' => 'Password is required')), new StringLength(array('min' => 8, 'messageMinimum' => 'Password is too short. Minimum 8 characters'))));
     $this->add($user_password);
     // User is active
     $this->add(new Select('user_is_active', array(1 => 'Yes', 0 => 'No')));
     // User location
     $user_profile_location = new Text('user_profile_location', array('placeholder' => 'Location'));
     if (true === $this->edit) {
         $user_profile_location->setDefault($entity->profile->getUserProfileLocation());
     }
     $this->add($user_profile_location);
     // User role
     // We query the acl_roles table for all existing roles and add the to the select element
     $user_acl_role = new Select('user_acl_role', AclRoles::find(), array('using' => array('name', 'name')));
     $this->add($user_acl_role);
     //CSRF
     $csrf = new Hidden('csrf');
     $csrf->addValidator(new Identical(array('value' => $this->security->getSessionToken(), 'message' => 'CSRF validation failed')));
     $this->add($csrf);
     $this->add(new Submit('save', array('class' => 'btn btn-lg btn-primary btn-block')));
 }