protected function addField($name)
 {
     switch ($name) {
         case 'username':
             $this->form->setDefault('username', $this->resource->username);
             $this->form->setValidator('username', new sfValidatorString(array('required' => true)));
             $this->form->setWidget('username', new sfWidgetFormInput());
             break;
         case 'email':
             $this->form->setDefault('email', $this->resource->email);
             $this->form->setValidator('email', new sfValidatorEmail(array('required' => true)));
             $this->form->setWidget('email', new sfWidgetFormInput());
             break;
         case 'password':
         case 'confirmPassword':
             $this->form->setDefault($name, null);
             // Required field only if a new user is being created
             $this->form->setValidator($name, new sfValidatorString(array('required' => !isset($this->getRoute()->resource))));
             $this->form->setWidget($name, new sfWidgetFormInputPassword());
             break;
         case 'groups':
             $values = array();
             $criteria = new Criteria();
             $criteria->add(QubitAclUserGroup::USER_ID, $this->resource->id);
             foreach (QubitAclUserGroup::get($criteria) as $item) {
                 $values[] = $item->groupId;
             }
             $choices = array();
             $criteria = new Criteria();
             $criteria->add(QubitAclGroup::ID, 99, Criteria::GREATER_THAN);
             foreach (QubitAclGroup::get($criteria) as $item) {
                 $choices[$item->id] = $item->getName(array('cultureFallback' => true));
             }
             $this->form->setDefault('groups', $values);
             $this->form->setValidator('groups', new sfValidatorPass());
             $this->form->setWidget('groups', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         case 'translate':
             $c = sfCultureInfo::getInstance($this->context->user->getCulture());
             $languages = $c->getLanguages();
             $choices = array();
             if (0 < count($langSettings = QubitSetting::getByScope('i18n_languages'))) {
                 foreach ($langSettings as $item) {
                     $choices[$item->name] = $languages[$item->name];
                 }
             }
             // Find existing translate permissions
             $criteria = new Criteria();
             $criteria->add(QubitAclPermission::USER_ID, $this->resource->id);
             $criteria->add(QubitAclPermission::ACTION, 'translate');
             $defaults = null;
             if (null !== ($permission = QubitAclPermission::getOne($criteria))) {
                 $defaults = $permission->getConstants(array('name' => 'languages'));
             }
             $this->form->setDefault('translate', $defaults);
             $this->form->setValidator('translate', new sfValidatorPass());
             $this->form->setWidget('translate', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
     }
 }
Пример #2
0
 public static function getaclUserGroupsById($id, array $options = array())
 {
     $criteria = new Criteria();
     self::addaclUserGroupsCriteriaById($criteria, $id);
     return QubitAclUserGroup::get($criteria, $options);
 }
Пример #3
0
 /**
  * Check if user belongs to *any* of the checkGroup(s) listed
  *
  * @param mixed $groups - integer value for group id, or array of group ids
  * @return boolean
  */
 public function hasGroup($checkGroups)
 {
     $hasGroup = false;
     // Cast $checkGroups as an array
     if (!is_array($checkGroups)) {
         $checkGroups = array($checkGroups);
     }
     // A user is always part of the authenticated group
     if (in_array(QubitAclGroup::AUTHENTICATED_ID, $checkGroups)) {
         return true;
     }
     $criteria = new Criteria();
     $criteria->add(QubitAclUserGroup::USER_ID, $this->id);
     if (0 < count($userGroups = QubitAclUserGroup::get($criteria))) {
         foreach ($userGroups as $userGroup) {
             if (in_array(intval($userGroup->groupId), $checkGroups)) {
                 $hasGroup = true;
                 break;
             }
         }
     }
     return $hasGroup;
 }