Example #1
0
 public function addAction()
 {
     $this->buildForm("admin/group/save");
     $this->gForm->getElement('tmp_id')->setValue(Util_Guid::generate());
     $this->gForm->getElement('url')->setValue('http://');
     $this->gForm->getElement('user_responsible')->setValue(UGD_Login_Manager::getInstance()->getActiveUser()->getId());
 }
Example #2
0
 /**
  * Create the setting form and populate with the custom setting values
  * 
  * @param integer $groupid
  */
 public static function createForm($groupid)
 {
     $form = new Zend_Form(array('action' => '/admin/settings/index/groupid/' . $groupid, 'method' => 'post'));
     $form->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator');
     $records = Doctrine_Query::create()->from('SettingsParameters s')->where('group_id = ?', $groupid)->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
     if (!empty($records)) {
         foreach ($records as $record) {
             // Custom style added to the textareas
             $style = $record['type'] == "textarea" ? array('rows' => 4) : array();
             $form->addElement($record['type'], $record['var'], $style + array('decorators' => array('Bootstrap'), 'filters' => array('StringTrim'), 'label' => $record['name'], 'description' => $record['description'], 'class' => 'form-control obj_' . $record['var']));
             if (!empty($record['config'])) {
                 $config = json_decode($record['config'], true);
                 if (!empty($config['class']) && class_exists($config['class']) && !empty($config['method']) && method_exists($config['class'], $config['method'])) {
                     $class = $config['class'];
                     $method = $config['method'];
                     $data = call_user_func(array($class, $method));
                     if (!empty($data)) {
                         if ($record['type'] == "select") {
                             $form->getElement($record['var'])->setMultiOptions($data);
                         } else {
                             $form->getElement($record['var'])->setValue($data);
                         }
                     }
                 }
             }
         }
     }
     $settings = self::getValues(Settings::find_by_GroupId($groupid));
     $form->populate($settings);
     return $form;
 }
Example #3
0
 public function simpleAction(\Zend_Form $form, \Application\Entity\Entity $model, $preventDefault = false)
 {
     $em = EntityManager::getInstance();
     $form->setAction($this->getRequest()->getRequestUri());
     if ($form->getElement("parent")) {
         $form->getElement("parent")->setValue($this->getRequest()->getParam("parent"));
     }
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         call_user_func(array($this->getActionController(), self::SET_MODEL_METHOD), $form, $model);
         $em->persist($model);
         if ($preventDefault == false) {
             $this->simpleEndAction();
         }
         return true;
     }
 }
Example #4
0
 /**
  * Adds an element BusUnitId.<br/><br/>
  * Defaults:<br/>
  * name         = busunit_id<br/>
  * requires     = true<br/>
  * label        = Business unit<br/>
  * placeholder  = 'Choose a business unit'<br/>
  * dimension    = 6<br/>
  * modelfield   = busunit_id<br/>
  * firstvaluenull  = true
  * 
  * @param Zend_Form $form The Zend_Form object where the element will be added
  * @param array $options The options to pass in the element
  */
 public function addElementBusunitId($form, $options = array())
 {
     $elementName = isset($options['name']) ? $options['name'] : 'busunit_id';
     $modelField = isset($options['modelfield']) ? $options['modelfield'] : 'busunit_id';
     $form->addElement('select', $elementName, array('filters' => array('StringTrim'), 'label' => isset($options['label']) ? $options['label'] : 'Business unit', 'dimension' => isset($options['dimension']) ? $options['dimension'] : 6, 'placeholder' => 'Choose a business unit', 'required' => isset($options['required']) ? $options['required'] : true, 'value' => $this->_model ? $this->_model->{$modelField} : ''));
     $el = $form->getElement($elementName);
     $firstvaluenull = isset($options['firstvaluenull']) ? $options['firstvaluenull'] : true;
     if ($firstvaluenull) {
         $el->addMultiOption(null, null);
     }
     /////////////////////
     // Add Headquarters
     $bud = new Busunit_Domain_Headquarters();
     $bu = $bud->getByAppAccount(Zend_Auth::getInstance()->getIdentity()->appaccount_id);
     $el->addMultiOption($bu->getId(), $bu->getName());
     // Add Branchs
     $bud = new Busunit_Domain_Branch();
     $bu = $bud->getAll('name');
     foreach ($bu as $busunit) {
         $el->addMultiOption($busunit->getId(), $busunit->getName());
     }
     // set value
     if ($this->_model && $this->_model->{$modelField}) {
         $el->setValue($this->_model->{$modelField});
     } else {
         $el->setValue(null);
     }
 }
Example #5
0
 /**
  * @group ZF-6070
  */
 public function testIndividualElementDecoratorsShouldOverrideGlobalElementDecorators()
 {
     $this->form->setOptions(array(
         'elementDecorators' => array(
             'ViewHelper',
             'Label',
         ),
         'elements' => array(
             'foo' => array(
                 'type' => 'text',
                 'options' => array(
                     'decorators' => array(
                         'Errors',
                         'ViewHelper',
                     ),
                 ),
             ),
         ),
     ));
     $element    = $this->form->getElement('foo');
     $expected   = array('Zend\Form\Decorator\Errors', 'Zend\Form\Decorator\ViewHelper');
     $actual     = array();
     foreach ($element->getDecorators() as $decorator) {
         $actual[] = get_class($decorator);
     }
     $this->assertSame($expected, $actual);
 }
 /**
  * editformAction
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 public function editformAction()
 {
     $this->core->logger->debug('users->controllers->UserController->editformAction()');
     try {
         $arrGroups = $this->getModelUsers()->getUserGroups($this->getRequest()->getParam('id'));
         if (count($arrGroups) > 0) {
             $this->arrGroups = array();
             foreach ($arrGroups as $objGroup) {
                 $this->arrGroups[] = $objGroup->idGroups;
             }
         }
         $this->initForm();
         $this->objForm->setAction('/zoolu/users/user/edit');
         $this->objUser = $this->getModelUsers()->getUserTable()->find($this->getRequest()->getParam('id'))->current();
         foreach ($this->objForm->getElements() as $objElement) {
             $name = $objElement->getName();
             if (isset($this->objUser->{$name})) {
                 $objElement->setValue($this->objUser->{$name});
             }
         }
         $this->objForm->getElement('language')->setValue($this->objUser->idLanguages);
         $this->view->form = $this->objForm;
         $this->view->formTitle = $this->core->translate->_('Edit_User');
         $this->renderScript('form.phtml');
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
Example #7
0
 /**
  * @return Zend_Form
  */
 public function getForm()
 {
     static $form;
     if (null === $form) {
         $form = new Zend_Form();
         $form->addElement('text', 'name', array('label' => _('Name'), 'required' => true))->addElement('text', 'organisationUnit', array('label' => _('Organisation unit')))->addElement('text', 'website', array('label' => _('Website')))->addElement('text', 'email', array('label' => _('E-mail')))->addElement('text', 'streetAddress', array('label' => _('Street Address')))->addElement('text', 'locality', array('label' => _('Locality')))->addElement('text', 'postalCode', array('label' => _('Postal Code')))->addElement('text', 'countryName', array('label' => _('Country Name')))->addElement('submit', 'submit', array('label' => _('Submit')));
         $form->getElement('email')->addValidator(new Zend_Validate_EmailAddress());
         try {
             $form->getElement('postalCode')->addValidator(new Zend_Validate_PostCode());
         } catch (Zend_Validate_Exception $e) {
             //no valid locale found, so be it...
         }
         $form->setDefaults($this->toArray());
     }
     return $form;
 }
Example #8
0
 /**
  * Adds an element JobFunctionId.<br/><br/>
  * Defaults:<br/>
  * name         = job_function_id<br/>
  * requires     = true<br/>
  * label        = Business unit<br/>
  * placeholder  = 'Choose a job function'<br/>
  * dimension    = 6<br/>
  * modelfield   = job_function_id<br/>
  * firstvaluenull  = true
  * 
  * @param Zend_Form $form The Zend_Form object where the element will be added
  * @param array $options The options to pass in the element
  */
 public function addElementJobFunctionId($form, $options = array())
 {
     $elementName = isset($options['name']) ? $options['name'] : 'job_function_id';
     $modelField = isset($options['modelfield']) ? $options['modelfield'] : 'job_function_id';
     $form->addElement('select', $elementName, array('filters' => array('StringTrim'), 'label' => isset($options['label']) ? $options['label'] : 'Job function', 'dimension' => isset($options['dimension']) ? $options['dimension'] : 6, 'placeholder' => 'Choose a job function', 'required' => isset($options['required']) ? $options['required'] : true, 'value' => $this->_model ? $this->_model->{$modelField} : ''));
     $el = $form->getElement($elementName);
     $firstvaluenull = isset($options['firstvaluenull']) ? $options['firstvaluenull'] : true;
     if ($firstvaluenull) {
         $el->addMultiOption(null, null);
     }
     /**
      * Add job functions
      */
     $jfd = new Staff_Domain_Jobfunction();
     $jf = $jfd->getAll('name');
     foreach ($jf as $item) {
         $el->addMultiOption($item->getId(), $item->getName());
     }
     // set value
     if ($this->_model && $this->_model->{$modelField}) {
         $el->setValue($this->_model->{$modelField});
     } else {
         $el->setValue(null);
     }
 }
Example #9
0
 public static function addOptionsToForm(Zend_Form $form, $options, $fieldName, $attributeName)
 {
     $arr = array();
     foreach ($options as $option) {
         $arr[$option->id] = $option->{$attributeName};
     }
     $form->getElement($fieldName)->setMultiOptions($arr);
 }
Example #10
0
 public static function SetValueToFormField(Zend_Form $form, $fieldName, $value)
 {
     try {
         $field = $form->getElement($fieldName);
     } catch (Exception $e) {
         throw new C3op_Util_FormFieldValueSetterException("Cant find %s element", $fieldName);
     }
     $field->setValue($value);
 }
Example #11
0
 public function makeOptionCheckbox(Zend_Form $form, $elements, $label = 'Options', $displayGroupName = 'options')
 {
     foreach ($elements as $element) {
         $form->getElement($element)->setAttrib('noFormItem', true);
     }
     $form->addDisplayGroup($elements, $displayGroupName);
     $form->getDisplayGroup($displayGroupName)->setAttrib('class', 'form-checkbox')->setAttrib('formItem', 'true')->setLegend($label);
     return $form;
 }
Example #12
0
 public static function addPackagesToForm(Zend_Form $form, $packages)
 {
     $arr = array();
     $arr[-1] = "N/A";
     foreach ($packages as $package) {
         $arr[$package->id] = $package->name;
     }
     $form->getElement('partner_package')->setMultiOptions($arr);
 }
Example #13
0
 /**
  * @return Zend_Form
  */
 public function getForm()
 {
     static $form;
     if (null === $form) {
         $form = new Zend_Form();
         $form->addElement('text', 'name', array('label' => _('Name'), 'required' => true))->addElement('text', 'organisationUnit', array('label' => _('Organisation unit')))->addElement('text', 'website', array('label' => _('Website')))->addElement('text', 'email', array('label' => _('E-mail')))->addElement('text', 'streetAddress', array('label' => _('Street Address')))->addElement('text', 'locality', array('label' => _('Locality')))->addElement('text', 'postalCode', array('label' => _('Postal Code')))->addElement('text', 'countryName', array('label' => _('Country Name')))->addElement('checkbox', 'enableStatusesSystem', array('label' => _('Enable the statuses system for concepts. (check help below *)'), 'required' => false))->addElement('submit', 'submit', array('label' => _('Submit')));
         $form->getElement('email')->addValidator(new Zend_Validate_EmailAddress());
         $form->setDefaults($this->toArray());
     }
     return $form;
 }
Example #14
0
 public static function addPackagesToForm(Zend_Form $form, $packages, $fieldName, $addDefult = true, $defaultName = "N/A")
 {
     $arr = array();
     if ($addDefult) {
         $arr[''] = $defaultName;
     }
     foreach ($packages as $package) {
         $arr[$package->id] = $package->name;
     }
     $form->getElement($fieldName)->setMultiOptions($arr);
 }
 public function saveAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     $message = array("success" => 0, "message" => "Please Correct the Errors Below!");
     if ($this->_addForm->isValid($_POST)) {
         //As everything is ok, save it...
         $task = $this->_dataTable->createRow();
         $task->name = $this->_addForm->getElement("name")->getValue();
         $task->description = $this->_addForm->getElement("desc")->getValue();
         $time = $this->_addForm->getElement("end_date")->getValue();
         if (!empty($time)) {
             $task->end_date = date("Y-m-d", strtotime($time));
         }
         $task->status = Task::STATUS_OPEN;
         $task->save();
         $message["success"] = 1;
         $message["message"] = "Task is saved successfully! Wait For Redirection!";
     } else {
         $message["errors"] = $this->_addForm->getErrors();
     }
     echo json_encode($message);
 }
Example #16
0
 /**
  * Wrap parent to provide a default Zend_View to
  * the element, if none is given
  *
  * @param string $elementName
  * @return NULL|Zend_Form_Element
  */
 public function getElement($elementName)
 {
     $element = parent::getElement($elementName);
     if (!isset($element) || FALSE == $element instanceof Zend_Form_Element) {
         return NULL;
     }
     if (NULL == $element->getView()) {
         if (NULL == $this->getView()) {
             $this->setView(new Zend_View());
         }
         $element->setView($this->getView());
     }
     return $element;
 }
Example #17
0
    /**
     * Faz a validação do formulário de usergroup (usado pelo Admin)
     * 
     * @param Nidorx_Form $form
     * @param Array $data 
     */
    public function validateForm(Zend_Form $form, $data)
    {

        if ($form->isValid($data)) {

            $translator = new Nidorx_Translator();

            $username = $form->getElement('username')->getValue();
            if ($this->_daoUser->getByUsername($username)) {
                $form->getElement('username')->addError($translator->translate('error_username_in_use'));
                $form->addError($translator->translate('error_username_in_use'));
            }

            //Verificando se o email já está em uso
            $email = $form->getElement('email')->getValue();
            if ($this->_daoUser->getByEmail($email)) {
                $form->getElement('email')->addError($translator->translate('error_email_in_use'));
                $form->addError($translator->translate('error_email_in_use'));
            }
        };

        return!$form->isErrors();
    }
Example #18
0
 /**
  * @group ZF-11088
  */
 public function testAddErrorOnElementMakesFormInvalidAndReturnsCustomError()
 {
     $element = new Zend_Form_Element_Text('foo');
     $errorString = 'This element made a booboo';
     $element->addError($errorString);
     $errorMessages = $element->getErrorMessages();
     $this->assertSame(1, count($errorMessages));
     $this->assertSame($errorString, $errorMessages[0]);
     $element2 = new Zend_Form_Element_Text('bar');
     $this->form->addElement($element2);
     $this->form->getElement('bar')->addError($errorString);
     $errorMessages2 = $this->form->getElement('bar')->getErrorMessages();
     $this->assertSame(1, count($errorMessages2));
     $this->assertSame($errorString, $errorMessages2[0]);
 }
Example #19
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;
 }
Example #20
0
 public function getForm()
 {
     $form = new Zend_Form();
     $form->setMethod('post');
     $form->setDecorators(array(array('ViewScript', array('viewScript' => 'reports/report1Form.phtml'))));
     $items = $this->getPeriodItems('REQ_MOZ_CONTMOVEMENT');
     $e = new Zend_Form_Element_Select('period', array('label' => 'Період', 'multiOptions' => $items, 'required' => true));
     $form->addElement($e);
     $items = $this->getGuideItems('T_STRUCTURE_ITEM', true, false, 'CT.TITLE');
     $e = new Zend_Form_Element_Select('establishment', array('label' => 'Установа', 'multiOptions' => $items));
     $form->addElement($e);
     $items = $this->getGuideItems('T_EDUFORM', true);
     $e = new Zend_Form_Element_Select('eduform', array('label' => 'Форма навчання', 'multiOptions' => $items));
     $form->addElement($e);
     $items = $this->getGuideItems('T_EDUBASIS', true);
     $e = new Zend_Form_Element_Select('edubase', array('label' => 'Форма фінансування', 'multiOptions' => $items));
     $form->addElement($e);
     $items = $this->getGuideItems('T_COUNTRY', true);
     $e = new Zend_Form_Element_Select('country', array('label' => 'Громадянство (країна)', 'multiOptions' => $items));
     $form->addElement($e);
     $items = $this->getGuideItems('T_COUNTRYTYPE', true);
     $e = new Zend_Form_Element_Select('countrytype', array('label' => 'Тип громадянства', 'multiOptions' => $items));
     $form->addElement($e);
     $items = $this->getGuideItems('T_EDULEVEL');
     $e = new Zend_Form_Element_MultiCheckbox('edulevel', array('label' => 'Рівень підготовки', 'multiOptions' => $items));
     $e->setValue(array_keys($items));
     $form->addElement($e);
     $refreshAct = Zend_Controller_Action_HelperBroker::getStaticHelper('url')->url(array('controller' => 'page', 'action' => 'show'));
     $e = new Zend_Form_Element_Submit('refresh', array('label' => 'Обновити', 'onclick' => "document.forms[0].action='{$refreshAct}'"));
     $form->addElement($e);
     $excelAct = Zend_Controller_Action_HelperBroker::getStaticHelper('url')->url(array('controller' => 'reports', 'action' => 'excel', 'report' => 1));
     $e = new Zend_Form_Element_Submit('excel', array('label' => 'Excel', 'onclick' => "document.forms[0].action='{$excelAct}'"));
     $form->addElement($e);
     $form->setElementDecorators(array('ViewHelper', 'Errors'));
     $auth = Zend_Auth::getInstance();
     $ident = $auth->getIdentity();
     if ($ident->STRUCTURE_CODE != 0) {
         $form->getElement('establishment')->setValue($ident->STRUCTUREID);
     }
     return $form;
 }
Example #21
0
 public function errorMessage(Zend_Form $form = null, $messages)
 {
     $html = '';
     if (count($messages)) {
         $html = '<div class="ui-widget">' . '  <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">' . '      <ul>';
         $elements = count($messages);
         for ($i = 0; $i < $elements; $i++) {
             $key = array_keys($messages);
             $mess = $messages[$key[$i]];
             $label = $form->getElement($key[$i]);
             if (isset($label)) {
                 $label = $label->getLabel();
                 $key = array_keys($mess);
                 $html .= '               <li style="font-size: .6em;"><b>' . $label . ': </b>' . $mess[$key[0]] . '</li>';
             } else {
                 $html .= '               <li style="font-size: .6em;">' . $mess . '</li>';
             }
         }
         $html .= '      </ul>' . '   </div>' . '</div>';
     }
     return $html;
 }
Example #22
0
 /**
  * Simple default function for making sure there is a $this->_saveButton.
  *
  * As the save button is not part of the model - but of the interface - it
  * does deserve it's own function.
  */
 protected function addSaveButton()
 {
     if ($this->_saveButton) {
         $this->saveButtonId = $this->_saveButton->getName();
         if (!$this->_form->getElement($this->saveButtonId)) {
             $this->_form->addElement($this->_saveButton);
         }
     } elseif ($this->saveButtonId) {
         //If not already there, add a save button
         $this->_saveButton = $this->_form->getElement($this->saveButtonId);
         if (!$this->_saveButton) {
             if (null === $this->saveLabel) {
                 $this->saveLabel = $this->_('Save');
             }
             $options = array('label' => $this->saveLabel);
             if ($this->buttonClass) {
                 $options['class'] = $this->buttonClass;
             }
             $this->_saveButton = $this->_form->createElement('submit', $this->saveButtonId, $options);
             $this->_form->addElement($this->_saveButton);
         }
     }
 }
 /**
  * Set Button Decorators
  *
  * @param Zend_Form $form       Instance of the form.
  * @param string    $format     The format (standard, minimal, table).
  * @param string    $submit_str Element name of the submit button.
  * @param string    $cancel_str Element name of the cancel button.
  *
  * @return void
  */
 protected static function setButtonDecorators(Zend_Form $form, $format, $submit_str, $cancel_str)
 {
     // set submit button decorators
     if ($form->getElement($submit_str)) {
         $form->getElement($submit_str)->setDecorators(self::$_SubmitDecorator[$format]);
         if (self::BOOTSTRAP == $format || self::BOOTSTRAP_MINIMAL == $format) {
             $attribs = $form->getElement($submit_str)->getAttrib('class');
             if (empty($attribs)) {
                 $attribs = array('btn', 'btn-primary');
             } else {
                 if (is_string($attribs)) {
                     $attribs = array($attribs);
                 }
                 $attribs = array_unique(array_merge(array('btn'), $attribs));
             }
             $submitBtn = $form->getElement($submit_str);
             $submitBtn->setAttrib('class', $attribs);
             if (true === $submitBtn instanceof Zend_Form_Element_Button && $submitBtn->getAttrib('type') === null) {
                 $submitBtn->setAttrib('type', 'submit');
             }
             if ($form->getElement($cancel_str) && self::BOOTSTRAP == $format) {
                 $form->getElement($submit_str)->getDecorator('HtmlTag')->setOption('openOnly', true);
             }
         }
         if (self::TABLE == $format) {
             if ($form->getElement($cancel_str)) {
                 $form->getElement($submit_str)->getDecorator('data')->setOption('openOnly', true);
                 $form->getElement($submit_str)->getDecorator('row')->setOption('openOnly', true);
             }
         }
     }
     // set cancel button decorators
     if ($form->getElement($cancel_str)) {
         $form->getElement($cancel_str)->setDecorators(self::$_ResetDecorator[$format]);
         if (self::BOOTSTRAP == $format || self::BOOTSTRAP_MINIMAL == $format) {
             $attribs = $form->getElement($cancel_str)->getAttrib('class');
             if (empty($attribs)) {
                 $attribs = array('btn');
             } else {
                 if (is_string($attribs)) {
                     $attribs = array($attribs);
                 }
                 $attribs = array_unique(array_merge(array('btn'), $attribs));
             }
             $form->getElement($cancel_str)->setAttrib('class', $attribs)->setAttrib('type', 'reset');
             if ($form->getElement($submit_str) && self::BOOTSTRAP == $format) {
                 $form->getElement($cancel_str)->getDecorator('HtmlTag')->setOption('closeOnly', true);
             }
         }
         if (self::TABLE == $format) {
             if ($form->getElement($submit_str)) {
                 $form->getElement($cancel_str)->getDecorator('data')->setOption('closeOnly', true);
                 $form->getElement($cancel_str)->getDecorator('row')->setOption('closeOnly', true);
             }
         }
     }
 }
Example #24
0
 /**
  * Set Button Decorators
  *
  * @param Zend_Form $form Instance of the form.
  * @param string $format The format (standard, minimal, table).
  * @param $buttons
  * @throws Zend_Form_Exception
  * @internal param string $submit_str Element name of the submit button.
  * @internal param string $cancel_str Element name of the cancel button.
  *
  */
 protected static function setButtonDecorators(Zend_Form $form, $format, $buttons)
 {
     if (array_key_exists('submit', $buttons)) {
         $submit_str = $buttons['submit'];
         unset($buttons['submit']);
     } elseif (array_key_exists(0, $buttons)) {
         $submit_str = $buttons[0];
         unset($buttons[0]);
     }
     if (array_key_exists('cancel', $buttons)) {
         $cancel_str = $buttons['cancel'];
         unset($buttons['cancel']);
     } elseif (array_key_exists(1, $buttons)) {
         $cancel_str = $buttons[1];
         unset($buttons[1]);
     }
     $tmp = [];
     foreach ($buttons as $key => $button) {
         $elem = $form->getElement($button);
         if ($elem) {
             $tmp[] = $elem;
         }
     }
     $buttons = $tmp;
     unset($elem, $button, $key, $tmp);
     // set submit button decorators
     if ($form->getElement($submit_str)) {
         $form->getElement($submit_str)->setDecorators(self::$_SubmitDecorator[$format]);
         if (self::BOOTSTRAP === $format || self::BOOTSTRAP_MINIMAL === $format) {
             $attribs = $form->getElement($submit_str)->getAttrib('class');
             if (empty($attribs)) {
                 $attribs = array('btn', 'btn-primary', 'pull-right');
             } else {
                 if (is_string($attribs)) {
                     $attribs = array($attribs);
                 }
                 $attribs = array_unique(array_merge(array('btn'), $attribs));
             }
             $submitBtn = $form->getElement($submit_str);
             $submitBtn->setAttrib('class', $attribs);
             if (true === $submitBtn instanceof Zend_Form_Element_Button && $submitBtn->getAttrib('type') === null) {
                 $submitBtn->setAttrib('type', 'submit');
             }
             if ((isset($cancel_str) && $form->getElement($cancel_str) || count($buttons) > 0) && self::BOOTSTRAP == $format) {
                 $form->getElement($submit_str)->getDecorator('HtmlTag')->setOption('openOnly', true);
             }
         }
         if (self::TABLE == $format) {
             if ($form->getElement($cancel_str)) {
                 $form->getElement($submit_str)->getDecorator('data')->setOption('openOnly', true);
                 $form->getElement($submit_str)->getDecorator('row')->setOption('openOnly', true);
             }
         }
     }
     // set cancel button decorators
     if (isset($cancel_str) && $form->getElement($cancel_str)) {
         //TODO chcek tags open close
         $form->getElement($cancel_str)->setDecorators(self::$_ResetDecorator[$format]);
         if (self::BOOTSTRAP == $format || self::BOOTSTRAP_MINIMAL == $format) {
             $attribs = $form->getElement($cancel_str)->getAttrib('class');
             if (empty($attribs)) {
                 $attribs = array('btn', 'btn-warning', 'pull-right');
             } else {
                 if (is_string($attribs)) {
                     $attribs = array($attribs);
                 }
                 $attribs = array_unique(array_merge(array('btn', 'pull-right'), $attribs));
             }
             $form->getElement($cancel_str)->setAttrib('class', $attribs)->setAttrib('type', 'reset');
             if ($form->getElement($submit_str) && self::BOOTSTRAP == $format) {
                 $form->getElement($cancel_str)->getDecorator('HtmlTag')->setOption('closeOnly', true);
             }
         }
         if (self::TABLE == $format) {
             if ($form->getElement($submit_str)) {
                 $form->getElement($cancel_str)->getDecorator('data')->setOption('closeOnly', true);
                 $form->getElement($cancel_str)->getDecorator('row')->setOption('closeOnly', true);
             }
         }
     }
     $count = count($buttons);
     /** @var Zend_Form_Element $button */
     foreach ($buttons as $key => $button) {
         $button->setDecorators(self::$_ResetDecorator[$format]);
         if (self::BOOTSTRAP == $format || self::BOOTSTRAP_MINIMAL == $format) {
             $attribs = $button->getAttrib('class');
             if (empty($attribs)) {
                 $attribs = array('btn', 'pull-right');
             } else {
                 if (is_string($attribs)) {
                     $attribs = array($attribs);
                 }
                 $attribs = array_unique(array_merge(array('btn', 'pull-right'), $attribs));
             }
             $button->setAttrib('class', $attribs);
             if ($button && $key == $count - 1 && self::BOOTSTRAP == $format) {
                 $button->getDecorator('HtmlTag')->setOption('closeOnly', true);
             } else {
                 $button->removeDecorator('HtmlTag');
             }
         }
         if (self::TABLE == $format) {
             //TODO chcek tags open close
             if ($form->getElement($submit_str)) {
                 $form->getElement($cancel_str)->getDecorator('data')->setOption('closeOnly', true);
                 $form->getElement($cancel_str)->getDecorator('row')->setOption('closeOnly', true);
             }
         }
     }
 }
Example #25
0
 /**
  * Adds an element Status of Project as a Combobox.<br/>
  * Defaults:<br/>
  * name         = status<br/>
  * required     = true<br/>
  * label        = Status<br/>
  * dimension    = 6<br/>
  * modelfield   = status<br/>
  * class        = selectpicker<br/>
  * first-options= must be and array of array('value1', 'label'). Default is an empty array<br/>
  * sample of first-options: array(array('value'=>null, 'label'=>'Choose an option'))
  * 
  * @param Zend_Form $form The Zend_Form object where the element will be added
  * @param array $options The options to pass in the element
  * @return Zend_Form_Element Zend Form element just created
  */
 public function addElementProjectStatus($form, $options = array())
 {
     $elementName = isset($options['name']) ? $options['name'] : 'status';
     $modelField = isset($options['modelfield']) ? $options['modelfield'] : 'status';
     $form->addElement('select', $elementName, array('filters' => array('StringTrim'), 'label' => isset($options['label']) ? $options['label'] : 'Status', 'dimension' => isset($options['dimension']) ? $options['dimension'] : 6, 'required' => isset($options['required']) ? $options['required'] : true, 'value' => $this->_model ? $this->_model->{$modelField} : '', 'class' => isset($options['class']) ? $options['class'] : 'selectpicker'));
     $el = $form->getElement($elementName);
     if (isset($options['first-options'])) {
         foreach ($options['first-options'] as $op) {
             $el->addMultiOption($op['value'], $op['label']);
         }
     }
     $el->addMultiOption(Project_Model_Project::PROJECT_STATUS_DRAFT_ID, Project_Model_Project::PROJECT_STATUS_DRAFT_LABEL);
     $el->addMultiOption(Project_Model_Project::PROJECT_STATUS_ACTIVE_ID, Project_Model_Project::PROJECT_STATUS_ACTIVE_LABEL);
     $el->addMultiOption(Project_Model_Project::PROJECT_STATUS_FINISHED_ID, Project_Model_Project::PROJECT_STATUS_FINISHED_LABEL);
     $el->addMultiOption(Project_Model_Project::PROJECT_STATUS_CLOSED_ID, Project_Model_Project::PROJECT_STATUS_CLOSED_LABEL);
     $el->addMultiOption(Project_Model_Project::PROJECT_STATUS_PAUSED_ID, Project_Model_Project::PROJECT_STATUS_PAUSED_LABEL);
     $optionClasses[] = '" data-content="<span class=\'label\'>' . $form->getTranslator()->_(Project_Model_Project::PROJECT_STATUS_DRAFT_LABEL) . '</span>';
     $optionClasses[] = '" data-content="<span class=\'label label-success\'>' . $form->getTranslator()->_(Project_Model_Project::PROJECT_STATUS_ACTIVE_LABEL) . '</span>';
     $optionClasses[] = '" data-content="<span class=\'label label-info\'>' . $form->getTranslator()->_(Project_Model_Project::PROJECT_STATUS_FINISHED_LABEL) . '</span>';
     $optionClasses[] = '" data-content="<span class=\'label label-inverse\'>' . $form->getTranslator()->_(Project_Model_Project::PROJECT_STATUS_CLOSED_LABEL) . '</span>';
     $optionClasses[] = '" data-content="<span class=\'label label-warning\'>' . $form->getTranslator()->_(Project_Model_Project::PROJECT_STATUS_PAUSED_LABEL) . '</span>';
     $el->setAttrib('optionClasses', $optionClasses);
     if ($this->_model && $this->_model->{$modelField}) {
         $el->setValue($this->_model->{$modelField});
     } else {
         $el->setValue(null);
     }
     return $el;
 }
 /**
  * @group ZF-2828
  */
 public function testCanPopulateCheckboxOptionsFromPostedData()
 {
     $form = new Zend_Form(array('elements' => array('100_1' => array('MultiCheckbox', array('multiOptions' => array('100_1_1' => 'Agriculture', '100_1_2' => 'Automotive', '100_1_12' => 'Chemical', '100_1_13' => 'Communications'), 'required' => true)))));
     $data = array('100_1' => array('100_1_1', '100_1_2', '100_1_12', '100_1_13'));
     $form->populate($data);
     $html = $form->render($this->getView());
     foreach ($form->getElement('100_1')->getMultiOptions() as $key => $value) {
         if (!preg_match('#(<input[^>]*' . $key . '[^>]*>)#', $html, $m)) {
             $this->fail('Missing input for a given multi option: ' . $html);
         }
         $this->assertContains('checked="checked"', $m[1]);
     }
 }
Example #27
0
 /**
  * Helper function to merge different types of error.
  *
  * @param \Zend_Form $form    The form.
  * @param string     $element The name of the element.
  *
  * @return array
  */
 public static function mergeErrors($form, $elementName)
 {
     $elementErrors = $form->getErrors($elementName);
     $element = $form->getElement($elementName);
     if ($element && method_exists($element, 'getErrorMessages')) {
         $elementCustomErrors = $element->getErrorMessages();
     }
     if (!is_array($elementErrors)) {
         $elementErrors = array();
     }
     if (!is_array($elementCustomErrors)) {
         $elementCustomErrors = array();
     }
     return array_merge($elementErrors, $elementCustomErrors);
 }
 /**
  * @group ZF-9682
  */
 public function testCustomLabelDecorator()
 {
     $form = new Zend_Form();
     $form->addElementPrefixPath('My_Decorator', dirname(__FILE__) . '/../_files/decorators/', 'decorator');
     $form->addElement($this->element);
     $element = $form->getElement('foo');
     $this->assertType('My_Decorator_Label', $element->getDecorator('Label'));
 }
Example #29
0
 private function setDateValueToFormField(Zend_Form $form, $fieldName, $value)
 {
     $field = $form->getElement($fieldName);
     if ($value != '0000-00-00') {
         $field->setValue(C3op_Util_DateDisplay::FormatDateToShow($value));
     } else {
         $field->setValue("");
     }
 }
Example #30
0
 public static function addTriggersToForm(Zend_Form $form)
 {
     $arr = array(3 => 'Flavor Ready', 2 => 'Moderation Approved');
     $form->getElement('trigger')->setMultiOptions($arr);
 }