示例#1
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return User
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->name) {
         $role = Table\Roles::findBy(['name' => $this->name]);
         if (isset($role->id) && $this->id != $role->id) {
             $this->getElement('name')->addValidator(new Validator\NotEqual($this->name, 'That role already exists.'));
         }
     }
     return $this;
 }
示例#2
0
 /**
  * Get users by role name
  *
  * @param  string $name
  * @return array
  */
 public function getByRole($name)
 {
     $role = Table\Roles::findBy(['name' => $name]);
     $users = [];
     if (isset($role->id)) {
         $users = Table\Users::findBy(['role_id' => $role->id])->rows();
     }
     return $users;
 }