/** {@inheritdoc} */ public function init() { parent::init(); $config = $this->getOption('config'); $mergeCustomFields = new Element\Checkbox('mergeCustomFields'); $mergeCustomFields->setLabel('Merge user supplied information'); $mergeCustomFields->setChecked($config->defaultMergeCustomFields); $this->add($mergeCustomFields); $mergeGroups = new Element\Checkbox('mergeGroups'); $mergeGroups->setLabel('Merge manual group assignments'); $mergeGroups->setChecked($config->defaultMergeGroups); $this->add($mergeGroups); $mergePackages = new Element\Checkbox('mergePackages'); $mergePackages->setLabel('Merge missing package assignments'); $mergePackages->setChecked($config->defaultMergePackages); $this->add($mergePackages); $submit = new \Library\Form\Element\Submit('submit'); $submit->setLabel('Merge selected clients'); $this->add($submit); // Checkboxes for "clients[]" are generated manually, without // \Zend\Form\Element. Define an input filter to have them processed. $arrayCount = new \Zend\Validator\Callback(); $arrayCount->setCallback(array($this, 'validateArrayCount'))->setMessage('At least 2 different clients have to be selected', \Zend\Validator\Callback::INVALID_VALUE); $inputFilter = new \Zend\InputFilter\InputFilter(); $inputFilter->add(array('name' => 'clients', 'required' => true, 'continue_if_empty' => true, 'filters' => array(array($this, 'clientsFilter')), 'validators' => array($arrayCount, new \Zend\Validator\Explode(array('validator' => new \Zend\Validator\Digits()))), 'error_message' => $arrayCount->getDefaultTranslator()->translate($arrayCount->getMessageTemplates()[\Zend\Validator\Callback::INVALID_VALUE]))); $this->setInputFilter($inputFilter); }
/** {@inheritdoc} */ public function init() { parent::init(); $types = new \Zend\Form\Fieldset('Types'); $this->add($types); $inputFilterTypes = new \Zend\InputFilter\InputFilter(); $this->_definedTypes = $this->getOption('DeviceManager')->getTypeCounts(); foreach ($this->_definedTypes as $name => $count) { $element = new \Zend\Form\Element\Text($name); $element->setValue($name); $types->add($element); $callback = new \Zend\Validator\Callback(); $callback->setCallback(array($this, 'validateName'))->setCallbackOptions($name)->setTranslatorTextDomain('default')->setMessage('The name already exists'); $filter = array('name' => $name, 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 1, 'max' => 255)), $callback)); $inputFilterTypes->add($filter); } $add = new \Zend\Form\Element\Text('Add'); $add->setLabel('Add'); $this->add($add); $submit = new \Library\Form\Element\Submit('Submit'); $submit->setLabel('Change'); $this->add($submit); $callback = new \Zend\Validator\Callback(); $callback->setCallback(array($this, 'validateName'))->setTranslatorTextDomain('default')->setMessage('The name already exists'); $inputFilter = new \Zend\InputFilter\InputFilter(); $inputFilter->add($inputFilterTypes, 'Types'); $inputFilter->add(array('name' => 'Add', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)), $callback))); $this->setInputFilter($inputFilter); }
/** {@inheritdoc} */ public function init() { parent::init(); $what = new \Zend\Form\Element\Radio('What'); $what->setValueOptions(array(\Model\Client\Client::MEMBERSHIP_AUTOMATIC => $this->_('Store search parameters. Group memberships will be updated automatically.'), \Model\Client\Client::MEMBERSHIP_ALWAYS => $this->_('Add current search results. Group memberships will be set only this time.'), \Model\Client\Client::MEMBERSHIP_NEVER => $this->_('Exclude search results from a group.'))); $what->setValue(\Model\Client\Client::MEMBERSHIP_AUTOMATIC); $this->add($what); $where = new \Zend\Form\Element\Radio('Where'); $where->setValueOptions(array('new' => $this->_('Store in new group'), 'existing' => $this->_('Store in existing group'))); $where->setValue('new')->setAttribute('onchange', 'selectElements()'); $this->add($where); $newGroup = new \Zend\Form\Element\Text('NewGroup'); $newGroup->setLabel('Name'); $this->add($newGroup); $description = new \Zend\Form\Element\Text('Description'); $description->setLabel('Description'); $this->add($description); $existingGroup = new \Library\Form\Element\SelectSimple('ExistingGroup'); $existingGroup->setLabel('Group'); $groups = array(); foreach ($this->getOption('GroupManager')->getGroups(null, null, 'Name') as $group) { $groups[] = $group['Name']; } $existingGroup->setValueOptions($groups); $this->add($existingGroup); $submit = new \Library\Form\Element\Submit('Submit'); $submit->setLabel('OK'); $this->add($submit); $lengthValidator = new \Zend\Validator\Callback(); $lengthValidator->setCallback(array($this, 'validateLength'))->setCallbackOptions(array(0, 255))->setTranslatorTextDomain('default')->setMessage('The input is more than 255 characters long'); $requiredValidator = new \Zend\Validator\Callback(); $requiredValidator->setCallback(array($this, 'validateLength'))->setCallbackOptions(array(1, 255))->setTranslatorTextDomain('default')->setMessage("Value is required and can't be empty"); $existsValidator = new \Zend\Validator\Callback(); $existsValidator->setCallback(array($this, 'validateGroupExists'))->setTranslatorTextDomain('default')->setMessage('The name already exists'); $validatorChain = new \Zend\Validator\ValidatorChain(); $validatorChain->attach($lengthValidator, true)->attach($requiredValidator, true)->attach($existsValidator, true); $inputFilter = new \Zend\InputFilter\InputFilter(); $inputFilter->add(array('name' => 'NewGroup', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array($validatorChain))); $lengthValidator = new \Zend\Validator\Callback(); $lengthValidator->setCallback(array($this, 'validateLength'))->setCallbackOptions(array(0, 255))->setTranslatorTextDomain('default')->setMessage('The input is more than 255 characters long'); $inputFilter->add(array('name' => 'Description', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null', 'options' => array('type' => 'string'))), 'validators' => array($lengthValidator))); $this->setInputFilter($inputFilter); }
/** {@inheritdoc} */ public function init() { parent::init(); $translatedTypes = array('text' => $this->_('Text'), 'clob' => $this->_('Long text'), 'integer' => $this->_('Integer'), 'float' => $this->_('Float'), 'date' => $this->_('Date')); $fields = new \Zend\Form\Fieldset('Fields'); $this->add($fields); $inputFilterFields = new \Zend\InputFilter\InputFilter(); foreach ($this->getOption('CustomFieldManager')->getFields() as $name => $type) { if ($name == 'TAG') { // Static field, can not be edited continue; } $this->_definedFields[$name] = $translatedTypes[$type]; $element = new \Zend\Form\Element\Text($name); $element->setValue($name); $fields->add($element); $callback = new \Zend\Validator\Callback(); $callback->setCallback(array($this, 'validateName'))->setCallbackOptions($name)->setTranslatorTextDomain('default')->setMessage('The name already exists'); $filter = array('name' => $name, 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 1, 'max' => 255)), $callback)); $inputFilterFields->add($filter); } // Empty text field to create new field. $newName = new \Zend\Form\Element\Text('NewName'); $newName->setLabel('Add'); $this->add($newName); // Datatype of new field $newType = new \Zend\Form\Element\Select('NewType'); $newType->setValueOptions($translatedTypes); $this->add($newType); $submit = new \Library\Form\Element\Submit('Submit'); $submit->setLabel('Change'); $this->add($submit); $callback = new \Zend\Validator\Callback(); $callback->setCallback(array($this, 'validateName'))->setTranslatorTextDomain('default')->setMessage('The name already exists'); $inputFilter = new \Zend\InputFilter\InputFilter(); $inputFilter->add($inputFilterFields, 'Fields'); $inputFilter->add(array('name' => 'NewName', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)), $callback))); $this->setInputFilter($inputFilter); }
public function lcformAction() { $id = $this->getEvent()->getRouteMatch()->getParam('id'); $subid = $this->getEvent()->getRouteMatch()->getParam('subparam'); $lecturermodule = ""; if ($subid) { $lecturermodule = $this->em->getRepository("\\Application\\Entity\\Lecturermodule")->find($subid); } $deptentity = $this->em->getRepository("\\Application\\Entity\\Staff")->findOneBy(array("fkUserid" => $this->userid)); //Get selected module information $module = $this->em->getRepository("\\Application\\Entity\\Classmodule")->find($id); //Get form $form = new \Application\Form\Lecturermodule($this->em, $deptentity->getFkDeptid()->getPkDeptid()); $form->bind($this->request->getPost()); if ($this->request->getPost('save')) { $form->setData($this->request->getPost()); if ($form->isValid()) { $formData = $form->getData(); //If request other departments option is not selected if ($formData['Lecturermodule']['fkStaffid'] != "-1") { if ($subid) { //Get existing record information $entity = $lecturermodule; } else { //Set new entity $entity = new \Application\Entity\Lecturermodule(); } //Delete serviced module first $this->exams->deletefromdb("\\Application\\Entity\\Servicedmodule", array("fkClassmoduleid" => $module->getPkClassmoduleid())); //Get selected staff entity $staffentity = $this->em->getRepository('\\Application\\Entity\\Staff')->find($formData['Lecturermodule']['fkStaffid']); $entity->setFkClassmoduleid($module); $entity->setFkStaffid($staffentity); $this->exams->saveLecturerModule($entity); $this->redirect()->toRoute("examination", array("action" => "lecturermodule")); } else { //Define custom validation $validator = new \Zend\Validator\Callback(function ($formvalue) { //Checking if department has been selected on not return empty($formvalue['fkReqdeptid']) ? false : true; }); $validator->setMessage("Select department"); if ($validator->isValid($formData)) { //Delete any lecturer assigned to the module $this->exams->deletefromdb("\\Application\\Entity\\Lecturermodule", array("fkClassmoduleid" => $module->getPkClassmoduleid())); //Get servicing department entity $servicingdeptentity = $this->em->getRepository('\\Application\\Entity\\Department')->find($formData['fkReqdeptid']); //If the module is already assigned update $currentmodule = $this->em->getRepository('\\Application\\Entity\\Servicedmodule')->findOneBy(array("fkClassmoduleid" => $module->getPkClassmoduleid())); if (count($currentmodule) > 0) { $entity = $currentmodule; } else { //Save serviced entity $entity = new \Application\Entity\Servicedmodule(); } $entity->setFkClassmoduleid($module); $entity->setReqdept($deptentity->getFkDeptid()); $entity->setServicingdept($servicingdeptentity); $entity->setFlag("REQUESTED"); if ($this->exams->saveServicedModule($entity)) { //If allocatre, send an email to hod } $this->redirect()->toRoute("examination", array("action" => "lecturermodule")); } else { $messages = $validator->getMessages(); $form->get('fkReqdeptid')->setMessages(array($messages['callbackValue'])); } } } } return new ViewModel(array("module" => $module, "form" => $form, "details" => $lecturermodule)); }
/** * Get input filter specification for an integer field * * @param string $name Field name * @param integer $min Allowed minimum value * @return array */ protected function _getIntegerFilter($name, $min) { $validatorChain = new \Zend\Validator\ValidatorChain(); $validatorChain->attachByName('Callback', array('callback' => array($this, 'validateInteger')), true); // Callback validators do not support message variables. For // translatable messages with a parameter, do translation and // substitution here and disable further translation. $message = "The input is not greater or equal than '%min%'"; // Prevent extraction by xgettext $minValueValidator = new \Zend\Validator\Callback(); $minValueValidator->setCallback(array($this, 'validateMinValue'))->setCallbackOptions($min)->setMessage(str_replace('%min%', $min, $minValueValidator->getTranslator()->translate($message)))->setTranslatorEnabled(false); $validatorChain->attach($minValueValidator); return array('name' => $name, 'required' => false, 'filters' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'filterInteger')))), 'validators' => $validatorChain); }
/** * Get input filter specification for an integer field * * @param string $name Field name * @param integer $min Allowed minimum value * @return array */ protected function _getIntegerFilter($name, $min) { $validatorChain = new \Zend\Validator\ValidatorChain(); $validatorChain->attachByName('Callback', array('callback' => array($this, 'validateInteger')), true); $minValueValidator = new \Zend\Validator\Callback(); $minValueValidator->setCallback(array($this, 'validateMinValue'))->setCallbackOptions($min)->setMessage("The input is not greater or equal than '{$min}'"); $validatorChain->attach($minValueValidator); return array('name' => $name, 'required' => false, 'filters' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'filterInteger')))), 'validators' => $validatorChain); }