public function createElement($type, $name, $options = null) { if (null === $options || !is_array($options)) { $options = array('prefixPath' => array(array('prefix' => 'ZendX_', 'path' => 'ZendX/'), array('prefix' => 'HausDesign_', 'path' => 'HausDesign/'), array('prefix' => 'Application_', 'path' => 'Application/'))); } elseif (is_array($options)) { if (array_key_exists('prefixPath', $options)) { if (isset($options['prefixPath']['prefix'])) { $options['prefixPath'] = array(array('prefix' => $options['prefixPath']['prefix'], 'path' => $options['prefixPath']['path']), array('prefix' => 'ZendX_', 'path' => 'ZendX/'), array('prefix' => 'HausDesign_', 'path' => 'HausDesign/'), array('prefix' => 'Application_', 'path' => 'Application/')); } else { $options['prefixPath'][] = array(array('prefix' => 'ZendX_', 'path' => 'ZendX/'), array('prefix' => 'HausDesign_', 'path' => 'HausDesign/'), array('prefix' => 'Application_', 'path' => 'Application/')); } } else { $options['prefixPath'] = array(array('prefix' => 'ZendX_', 'path' => 'ZendX/'), array('prefix' => 'HausDesign_', 'path' => 'HausDesign/'), array('prefix' => 'Application_', 'path' => 'Application/')); } } return parent::createElement($type, $name, $options); }
/** * Initialize the form. */ public function init() { parent::init(); $this->setAttrib('id', 'csvimport-mapping'); $this->setMethod('post'); $elementsByElementSetName = $this->_getElementPairs($this->_itemTypeId); $elementsByElementSetName = array('' => 'Select Below') + $elementsByElementSetName; foreach ($this->_columnNames as $index => $colName) { $rowSubForm = new Zend_Form_SubForm(); $selectElement = $rowSubForm->createElement('select', 'element', array('class' => 'map-element', 'multiOptions' => $elementsByElementSetName, 'multiple' => false)); $selectElement->setIsArray(true); if ($this->_automapColumnNamesToElements) { $selectElement->setValue($this->_getElementIdFromColumnName($colName)); } $rowSubForm->addElement($selectElement); $rowSubForm->addElement('checkbox', 'html'); $rowSubForm->addElement('checkbox', 'tags'); $rowSubForm->addElement('checkbox', 'file'); $this->_setSubFormDecorators($rowSubForm); $this->addSubForm($rowSubForm, "row{$index}"); } $this->addElement('submit', 'submit', array('label' => __('Import CSV File'), 'class' => 'submit submit-medium')); }
/** * Fügt ein Element zum Formular hinzu. * * Ist das Element als 'required' markiert, werden die Nachrichten für den entsprechenden Validator gesetzt. * * Wenn die Option 'useNameAsLabel' auf true gesetzt ist wird automatisch der Name des Elements als Label verwendet. * Bei vielen Opus Model Formularen stimmt der Element-Name mit dem Übersetzungsschlüssel überein. * * @param string|Zend_Form_Element $element * @param null $name * @param null $options * @return void|Zend_Form */ public function createElement($element, $name, $options = null) { if ($this->isUseNameAsLabel()) { $labelOption = array('label' => is_null($this->_labelPrefix) ? $name : $this->_labelPrefix . $name); $options = is_array($options) ? array_merge($labelOption, $options) : $labelOption; } $element = parent::createElement($element, $name, $options); if (!is_null($element)) { $this->applyCustomMessages($element); } return $element; }
public function createElement($type, $name, $options) { if (isset($options['checkbox'])) { if (false !== ($cbo = $options['checkbox']) && $cbo['show']) { if ($cbo['prefix']) { $prefix = $cbo['prefix']; } else { $prefix = 'cb'; } $this->addElement('hidden', $prefix . '_' . $name, array('value' => 0)); $this->hideField($prefix . '_' . $name); } } $element = parent::createElement($type, $name, $options); if (isset($options['checkbox'])) { if (false !== ($cbo = $options['checkbox']) && $cbo['show']) { $decorators = $element->getDecorators(); $options = array_merge($cbo, array('placement' => $cbo['placement'] ? $cbo['placement'] : 'prepend', 'prefix' => $prefix)); array_splice($decorators, $cbo['order'], count($decorators), array_merge(array(array('Checkbox', $options)), array_slice($decorators, $cbo['order']))); $element->setDecorators($decorators); $this->_elementsWithCb[$name] = $prefix . '_' . $name; } } return $element; }
/** * Initialize the form. */ public function init() { parent::init(); $this->setAttrib('id', 'csvimport-mapping'); $this->setMethod('post'); // Prepare elements for each format. switch ($this->_format) { case 'Manage': $elementsByElementSetName = $this->_getElementPairs(true); $special = label_table_options(array('Tags' => 'Tags', 'Collection' => 'Collection (for item)', 'Item' => 'Item (for file)', 'File' => 'Files', 'Action' => 'Action', 'RecordType' => 'Record type', 'itemType' => 'Item type', 'IdentifierField' => 'Identifier field', 'Identifier' => 'Identifier')); break; case 'Report': return false; case 'Item': $elementsByElementSetName = $this->_getElementPairs($this->_itemTypeId); break; case 'File': $elementsByElementSetName = $this->_getElementPairsForFiles(); break; // Deprecated. // Deprecated. case 'Mix': $elementsByElementSetName = $this->_getElementPairs(true); $special = label_table_options(array('Tags' => 'Tags', 'Collection' => 'Collection', 'fileUrl' => 'Zero or one file', 'File' => 'Files', 'RecordType' => 'Record type', 'ItemType' => 'Item type', 'Public' => 'Public', 'Featured' => 'Featured', 'sourceItemId' => 'Source Item Id')); break; case 'Update': $elementsByElementSetName = $this->_getElementPairs(true); $special = label_table_options(array('Tags' => 'Tags', 'Collection' => 'Collection', 'fileUrl' => 'Zero or one file', 'File' => 'Files', 'RecordType' => 'Record type', 'ItemType' => 'Item type', 'Public' => 'Public', 'Featured' => 'Featured', 'updateMode' => 'Update mode', 'updateIdentifier' => 'Update identifier', 'recordIdentifier' => 'Record identifier')); break; default: return false; } $elementsByElementSetName = label_table_options($elementsByElementSetName); foreach ($this->_columnNames as $index => $colName) { $rowSubForm = new Zend_Form_SubForm(); $selectElement = $rowSubForm->createElement('select', 'element', array('class' => 'map-element', 'multiOptions' => $elementsByElementSetName, 'multiple' => false)); $selectElement->setIsArray(true); if ($this->_automapColumns) { $selectElement->setValue($this->_getElementIdFromColumnName($colName)); } $rowSubForm->addElement($selectElement); $rowSubForm->addElement('checkbox', 'html', array('value' => $this->_elementsAreHtml)); // If import type is File, add checkbox for file url only because // files can't get tags and we just need the url. switch ($this->_format) { case 'Item': $rowSubForm->addElement('checkbox', 'tags'); $rowSubForm->addElement('checkbox', 'file'); break; case 'File': $rowSubForm->addElement('checkbox', 'file_url'); break; case 'Manage': // Deprecated. // Deprecated. case 'Mix': case 'Update': $specialElement = $rowSubForm->createElement('select', 'special', array('class' => 'map-element', 'multiOptions' => $special, 'multiple' => false)); // $specialElement->setIsArray(true); if ($this->_automapColumns) { $specialElement->setValue($this->_getSpecialValue($colName, $special)); } $rowSubForm->addElement($specialElement); $rowSubForm->addElement('checkbox', 'extra_data', array('label' => __('Extra data'))); break; } $this->_setSubFormDecorators($rowSubForm); $this->addSubForm($rowSubForm, "row{$index}"); } $this->addElement('submit', 'submit', array('label' => __('Import CSV file'), 'class' => 'submit submit-medium')); }
public function form($values = array()) { $config = Zend_Registry::get('config'); $form = new Zend_Form(); $form->setAttrib('id', 'eventForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $workshop = new Workshop(); $where = $workshop->getAdapter()->quoteInto('status = ?', 'enabled'); $workshops = $workshop->fetchAll($where, 'title'); $workshopList = array(); foreach ($workshops as $w) { $workshopList[$w->workshopId] = $w->title; } $workshopElement = $form->createElement('select', 'workshop', array('label' => 'Workshop:')); $workshopElement->setMultiOptions($workshopList)->setValue(isset($values['workshopId']) ? $values['workshopId'] : ''); $location = new Location(); $where = $location->getAdapter()->quoteInto('status = ?', 'enabled'); $locations = $location->fetchAll($where, 'name'); $locationList = array(); $locationCapacity = array(); foreach ($locations as $l) { $locationList[$l->locationId] = $l->name; $locationCapacity['loc_' . $l->locationId] = $l->capacity; } $locationIds = array_keys($locationList); // add the location capacities to the page in js so we can process it as a json object for the "live" max size changing with location selection Zend_Layout::getMvcInstance()->getView()->headScript()->appendScript('var locationCapacitiesString = ' . Zend_Json::encode($locationCapacity) . ';'); $locationElement = $form->createElement('select', 'location', array('label' => 'Location:')); $locationElement->setMultiOptions($locationList)->setValue(isset($values['locationId']) ? $values['locationId'] : $locationCapacity['loc_' . $locationIds[0]]); $date = $form->createElement('text', 'date', array('label' => 'Date:')); $date->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '128')->setAttrib('style', 'width: 200px')->setValue(isset($values['date']) ? strftime('%A, %B %e, %Y', strtotime($values['date'])) : ''); $password = $form->createElement('text', 'password', array('label' => 'Event Password:'******'StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '100')->setValue(isset($values['password']) ? $values['password'] : ''); // add the start time selector $startTimeSub = new Zend_Form_SubForm(); $startTimeSub->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')))); $startTimeSub->setAttrib('class', 'sub'); $startTimeHour = $startTimeSub->createElement('select', 'hour', array('label' => 'Start Time:')); for ($i = 1; $i <= 12; $i++) { $startTimeHour->addMultiOption($i, $i); } $startTimeHour->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')), array('Label'))); $startTimeHour->setValue(isset($values['startTime']) ? date('g', strtotime($values['startTime'])) : date('g')); $startTimeMinute = $startTimeSub->createElement('select', 'minute'); for ($i = 0; $i < 60; $i += 5) { $startTimeMinute->addMultiOption(str_pad($i, 2, '0', STR_PAD_LEFT), str_pad($i, 2, '0', STR_PAD_LEFT)); } $startTimeMinute->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')))); $startTimeMinute->setValue(isset($values['startTime']) ? date('i', strtotime($values['startTime'])) : date('i')); $startTimeMeridian = $startTimeSub->createElement('select', 'meridian'); $startTimeMeridian->addMultiOption('am', 'AM')->addMultiOption('pm', 'PM')->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')))); $startTimeMeridian->setValue(isset($values['startTime']) ? date('a', strtotime($values['startTime'])) : date('a')); $startTimeSub->addElements(array($startTimeHour, $startTimeMinute, $startTimeMeridian)); // add the end time selector $endTimeSub = new Zend_Form_SubForm(); $endTimeSub->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')))); $endTimeSub->setAttrib('class', 'sub'); $endTimeHour = $endTimeSub->createElement('select', 'hour', array('label' => 'End Time:')); for ($i = 1; $i <= 12; $i++) { $endTimeHour->addMultiOption($i, $i); } $endTimeHour->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')), array('Label'))); $endTimeHour->setValue(isset($values['endTime']) ? date('g', strtotime($values['endTime'])) : date('g')); $endTimeMinute = $endTimeSub->createElement('select', 'minute'); for ($i = 0; $i < 60; $i += 5) { $endTimeMinute->addMultiOption(str_pad($i, 2, '0', STR_PAD_LEFT), str_pad($i, 2, '0', STR_PAD_LEFT)); } $endTimeMinute->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')))); $endTimeMinute->setValue(isset($values['endTime']) ? date('i', strtotime($values['endTime'])) : date('i')); $endTimeMeridian = $endTimeSub->createElement('select', 'meridian'); $endTimeMeridian->addMultiOption('am', 'AM')->addMultiOption('pm', 'PM')->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')))); $endTimeMeridian->setValue(isset($values['endTime']) ? date('a', strtotime($values['endTime'])) : date('a')); $endTimeSub->addElements(array($endTimeHour, $endTimeMinute, $endTimeMeridian)); // get all the users available for the instructor list $otAccount = new Ot_Account(); $accounts = $otAccount->fetchAll(null, array('lastName', 'firstName'))->toArray(); $instructorList = array(); foreach ($accounts as $a) { $instructorList[$a['accountId']] = $a['lastName'] . ", " . $a['firstName']; } $instructorElement = $form->createElement('multiselect', 'instructors', array('label' => 'Instructor(s):')); $instructorElement->setMultiOptions($instructorList)->setAttrib('size', 10)->setValue(isset($values['instructorIds']) ? $values['instructorIds'] : ''); $minSize = $form->createElement('text', 'minSize', array('label' => 'Min Size:')); $minSize->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '64')->setAttrib('style', 'width: 50px;')->setValue(isset($values['minSize']) ? $values['minSize'] : $config->user->defaultMinWorkshopSize->val); $maxSize = $form->createElement('text', 'maxSize', array('label' => 'Max Size:')); $maxSize->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '64')->setAttrib('style', 'width: 50px;')->setValue(isset($values['maxSize']) ? $values['maxSize'] : $locationElement->getValue()); $waitlistSize = $form->createElement('text', 'waitlistSize', array('label' => 'Waitlist Size:')); $waitlistSize->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '64')->setAttrib('style', 'width: 50px;')->setValue(isset($values['waitlistSize']) ? $values['waitlistSize'] : $config->user->defaultWorkshopWaitlistSize->val); $evaluationType = $form->createElement('select', 'evaluationType', array('label' => 'Evaluation Type:')); $evaluationType->setMultiOptions(array('default' => 'Default', 'google' => 'Google Form'))->setRequired(true)->setValue(isset($values['evaluationType']) ? $values['evaluationType'] : 'default'); $formKey = $form->createElement('textarea', 'formKey', array('label' => 'Google Form Question Key:')); $formKey->setAttribs(array('cols' => '10', 'rows' => '5', 'style' => 'width : 250px;'))->addDecorators(array('ViewHelper', 'Errors', 'HtmlTag', array('Label', array('tag' => 'span')), array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div', 'id' => 'formKey', 'class' => 'elm'))))->setValue(isset($values['formKey']) ? $values['formKey'] : ''); $answerKey = $form->createElement('textarea', 'answerKey', array('label' => 'Google Form Answer Key:')); $answerKey->addFilter('StringTrim')->addFilter('StripTags')->setAttribs(array('cols' => '10', 'rows' => '3', 'style' => 'width : 250px;'))->addDecorators(array('ViewHelper', 'Errors', 'HtmlTag', array('Label', array('tag' => 'span')), array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div', 'id' => 'answerKey', 'class' => 'elm'))))->setValue(isset($values['answerKey']) ? $values['answerKey'] : ''); $submit = $form->createElement('submit', 'submitButton', array('label' => 'Submit')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel')); $cancel->setAttrib('id', 'cancel'); $cancel->setDecorators(array(array('ViewHelper', array('helper' => 'formButton')))); $form->addElements(array($workshopElement, $locationElement, $password, $date, $evaluationType))->addSubForms(array('startTime' => $startTimeSub, 'endTime' => $endTimeSub))->addElements(array($minSize, $maxSize, $waitlistSize, $instructorElement)); $form->addDisplayGroup(array('instructors'), 'instructors-group', array('legend' => 'Instructors')); $form->addDisplayGroup(array('workshop', 'password', 'location', 'minSize', 'maxSize', 'waitlistSize'), 'generalInformation', array('legend' => 'General Information')); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit, $cancel)); $form->addElements(array($evaluationType, $formKey, $answerKey)); $form->addDisplayGroup(array('evaluationType', 'formKey', 'answerKey'), 'evaluationTypes', array('legend' => 'Evaluations')); $form->addDisplayGroup(array('submitButton', 'cancel'), 'buttons'); $form->setDisplayGroupDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'widget-content')), array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div', 'class' => array('widget-footer', 'ui-corner-bottom'), 'placement' => Zend_Form_Decorator_Abstract::APPEND)), array('FieldSet', array('class' => 'formField')))); $buttons = $form->getDisplayGroup('buttons'); $buttons->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'style' => 'clear : both;')))); if (isset($values['eventId'])) { $eventId = $form->createElement('hidden', 'eventId'); $eventId->setValue($values['eventId']); $eventId->setDecorators(array(array('ViewHelper', array('helper' => 'formHidden')))); $form->addElement($eventId); } return $form; }