Example #1
0
 /**
  * @return Zend_Form
  */
 public function getForm()
 {
     static $form;
     if (null === $form) {
         $form = new Zend_Form();
         $form->addElement('hidden', 'id', array('required' => $this->id ? true : false))->addElement('text', 'tenant', array('label' => _('Tenant'), 'readonly' => true, 'disabled' => true))->addElement('text', 'name', array('label' => _('Name'), 'required' => true))->addElement('text', 'email', array('label' => _('E-mail'), 'required' => true))->addElement('password', 'pw1', array('label' => _('Password'), 'maxlength' => 100, 'size' => 15, 'validators' => array(array('StringLength', false, array(4, 30)), array('identical', false, array('token' => 'pw2')))))->addElement('password', 'pw2', array('label' => _('Password (check)'), 'maxlength' => 100, 'size' => 15, 'validators' => array(array('identical', false, array('token' => 'pw1')))))->addElement('select', 'role', array('label' => _('Role'), 'required' => true))->addElement('radio', 'type', array('label' => _('Usertype'), 'required' => true))->addElement('text', 'apikey', array('label' => _('API Key (required for API users)'), 'required' => false))->addElement('text', 'eppn', array('label' => _('eduPersonPrincipalName (for SAML authentication)'), 'required' => false))->addElement('multiselect', 'defaultSearchProfileIds', array('label' => _('Search Profile Id'), 'required' => false))->addElement('checkbox', 'disableSearchProfileChanging', array('label' => _('Disable changing search profile'), 'required' => false))->addElement('submit', 'submit', array('label' => _('Submit')))->addElement('reset', 'reset', array('label' => _('Reset')))->addElement('submit', 'cancel', array('label' => _('Cancel')))->addElement('submit', 'delete', array('label' => _('Delete'), 'onclick' => 'return confirm(\'' . _('Are you sure you want to delete this user?') . '\');'))->addDisplayGroup(array('submit', 'reset', 'cancel', 'delete'), 'buttons');
         $form->getElement('type')->addMultiOptions(array_combine(OpenSKOS_Db_Table_Users::$types, OpenSKOS_Db_Table_Users::$types))->setSeparator(' ');
         $form->getElement('role')->addMultiOptions(array_combine(OpenSKOS_Db_Table_Users::$roles, OpenSKOS_Db_Table_Users::$roles));
         $searchProfilesModel = new OpenSKOS_Db_Table_SearchProfiles();
         $select = $searchProfilesModel->select();
         if (Zend_Auth::getInstance()->hasIdentity()) {
             $select->where('tenant=?', Zend_Auth::getInstance()->getIdentity()->tenant);
         }
         $searchProfiles = $searchProfilesModel->fetchAll($select);
         $searchProfilesOptions = array();
         foreach ($searchProfiles as $profile) {
             $searchProfilesOptions[$profile->id] = $profile->name;
         }
         $form->getElement('defaultSearchProfileIds')->addMultiOptions($searchProfilesOptions);
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueEmail'));
         $validator->setMessage(_("there is already a user with e-mail address '%value%'"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('email')->addValidator($validator)->addValidator(new Zend_Validate_EmailAddress());
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueEppn'));
         $validator->setMessage(_("there is already a user with eduPersonPrincipalName '%value%'"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('eppn')->addValidator($validator);
         $validator = new Zend_Validate_Callback(array($this, 'needApiKey'));
         $validator->setMessage(_("An API Key is required for users that have access to the API"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('type')->addValidator($validator, true);
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueApiKey'));
         $validator->setMessage(_("there is already a user with API key '%value%'"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('apikey')->addValidator(new Zend_Validate_Alnum())->addValidator($validator)->addValidator(new Zend_Validate_StringLength(array('min' => 6)));
         $userData = $this->toArray();
         $userData['defaultSearchProfileIds'] = explode(', ', $userData['defaultSearchProfileIds']);
         $form->setDefaults($userData);
         if (!$this->id || Zend_Auth::getInstance()->hasIdentity() && Zend_Auth::getInstance()->getIdentity()->id == $this->id) {
             $form->removeElement('delete');
             if (!OpenSKOS_Db_Table_Users::fromIdentity()->isAllowed('editor.users', 'manage')) {
                 // Currently only password edit is allowed.
                 $form->removeElement('name');
                 $form->removeElement('email');
                 $form->removeElement('role');
                 $form->removeElement('type');
                 $form->removeElement('apikey');
                 $form->removeElement('eppn');
                 $form->removeElement('defaultSearchProfileIds');
                 $form->removeElement('disableSearchProfileChanging');
             }
         }
     }
     return $form;
 }
 /**
  * @return Editor_Forms_SearchOptions
  */
 protected function buildSearchProfiles()
 {
     $profilesModel = new OpenSKOS_Db_Table_SearchProfiles();
     $profiles = $profilesModel->fetchAll($profilesModel->select()->where('tenant=?', $this->_getCurrentTenant()->code));
     $profilesOptions = array();
     $profilesOptions[''] = _('Default');
     foreach ($profiles as $profile) {
         $profilesOptions[$profile->id] = $profile->name;
     }
     $profilesOptions['custom'] = _('Custom');
     $this->addElement('select', 'searchProfileId', array('label' => _('Search Profile'), 'multiOptions' => $profilesOptions));
     $this->addElement('text', 'searchProfileName', array('filters' => array('StringTrim'), 'label' => _('Search Profile Name')));
     $this->addElement('hidden', 'switchProfile', array('value' => 0, 'decorators' => array('ViewHelper')));
     return $this;
 }
Example #3
0
 /**
  * @return Editor_Forms_Search
  */
 protected function buildSearchProfiles()
 {
     $profilesModel = new OpenSKOS_Db_Table_SearchProfiles();
     $profiles = $profilesModel->fetchAll($profilesModel->select()->where('tenant=?', $this->_getCurrentTenant()->code));
     $user = OpenSKOS_Db_Table_Users::requireFromIdentity();
     $profilesOptions = array();
     $profilesOptions[''] = _('Default');
     foreach ($profiles as $profile) {
         $profilesOptions[$profile->id] = $profile->name;
     }
     $profilesOptions['custom'] = _('Custom');
     // Check which profiles are allowed for the user.
     foreach (array_keys($profilesOptions) as $profileKey) {
         if (!$user->isAllowedToUseSearchProfile($profileKey)) {
             unset($profilesOptions[$profileKey]);
         }
     }
     $userOptions = $user->getSearchOptions();
     $this->addElement('select', 'searchProfileId', array('label' => _('Search Profile'), 'multiOptions' => $profilesOptions, 'value' => isset($userOptions['searchProfileId']) ? $userOptions['searchProfileId'] : ''));
     $this->addDisplayGroup(array('searchProfileId'), 'search-profile-selector', array('disableDefaultDecorators' => true, 'decorators' => array('FormElements', array('HtmlTag', array('tag' => 'span', 'id' => 'search-profile-selector', 'class' => $profiles->count() < 2 ? 'do-not-show' : '')))));
     return $this;
 }