/**
  * @param array|\Traversable $options
  */
 public function setOptions($options)
 {
     if (isset($options['subscriber_id'])) {
         $this->subscriberId = $options['subscriber_id'];
     }
     if (isset($options['include_hidden'])) {
         $this->setIncludeHidden($options['include_hidden']);
     }
     parent::setOptions($options);
 }
 /**
  * @param TableModel $table
  */
 public function __construct(TableModel $table)
 {
     parent::__construct('Display');
     $this->tableModel = $table;
     $tableHeaders = $this->tableModel->getTableHeaders();
     // Group checkboxes by property
     $columnGroups = array();
     foreach ($tableHeaders as $tableHeader) {
         /** @var TableHeaderCellModel $tableHeader */
         $columnNameSegments = explode('.', $tableHeader->getName());
         if (!array_key_exists($columnNameSegments[0], $columnGroups)) {
             $columnGroups[$columnNameSegments[0]] = array();
         }
     }
     // Create all values for each property
     foreach ($tableHeaders as $tableHeader) {
         $columnNameSegments = explode('.', $tableHeader->getName());
         $label = $tableHeader->getName();
         if (count($columnNameSegments) > 1) {
             $segments = $columnNameSegments;
             unset($segments[0]);
             $label = implode('.', $segments);
         }
         $valueOption = array('value' => $tableHeader->getName(), 'label' => $label, 'selected' => $tableHeader->isVisible());
         $columnGroups[$columnNameSegments[0]][] = $valueOption;
     }
     // Create the actual form element per property
     foreach ($columnGroups as $property => $checkboxValues) {
         $multiCheckbox = new MultiCheckbox($this->checkboxName);
         $multiCheckbox->setOptions(array('inline' => false, 'value_options' => $checkboxValues));
         $isParentField = strpos($checkboxValues[0]['value'], ".") !== false;
         if (count($checkboxValues) >= 2 || count($checkboxValues) == 1 && $isParentField) {
             $multiCheckbox->setLabel($property);
         }
         // Dirty hack, because this->add() does not detect element or fieldset naming conflicts
         $this->iterator->insert($property, $multiCheckbox, 0);
     }
     $this->add(array('name' => 'submit', 'type' => 'submit', 'label' => '<span class="glyphicon glyphicon glyphicon-refresh"></span>', 'attributes' => array('value' => 'Apply', 'class' => 'btn knopSearch')));
 }
Ejemplo n.º 3
0
 public function formAction()
 {
     // Build a name element.
     $name = new Element('name');
     $name->setLabel('Your name');
     $name->setAttributes(array('type' => 'text'));
     // Build a submit button element.
     $send = new Element('send');
     $send->setLabel('Send');
     $send->setAttributes(array('type' => 'submit', 'value' => 'Send'));
     // Build a checkbox element.
     $check = new Checkbox('check');
     $check->setLabel('Checkbox example');
     // Build a multi-checkbox element.
     $multicheck = new MultiCheckbox('multicheck');
     $multicheck->setLabel('Multi checkbox example');
     $multicheck->setOptions(array('value_options' => array('One' => 'one', 'Two' => 'two')));
     // Assemble the form.
     $form = new Form('contact');
     $form->add($name);
     $form->add($check);
     $form->add($multicheck);
     $form->add($send);
     // Get the request if any.
     $request = $this->getRequest();
     $data = $request->getPost();
     $form->setData($data);
     // Validate the form
     if ($form->isValid()) {
         $validatedData = $form->getData();
         $success = 'Form submit was successful';
     } else {
         $success = 'Form submit failed';
         $messages = $form->getMessages();
     }
     // Set the method attribute for the form
     $form->setAttribute('method', 'post');
     return new ViewModel(array('form' => $form, 'success' => $success, 'messages' => $messages, 'data' => $data));
 }
Ejemplo n.º 4
0
 public function testSetOptionsOptions()
 {
     $element = new MultiCheckboxElement();
     $element->setOptions(array('value_options' => array('bar' => 'baz'), 'options' => array('foo' => 'bar')));
     $this->assertEquals(array('bar' => 'baz'), $element->getOption('value_options'));
     $this->assertEquals(array('foo' => 'bar'), $element->getOption('options'));
 }
Ejemplo n.º 5
0
 public function testEnsureUseHiddenElementMethodExists()
 {
     $element = new MultiCheckboxElement();
     $element->setName('codeType');
     $element->setOptions(array('label' => 'Code Type'));
     $element->setAttributes(array('type' => 'radio', 'value' => array('markdown')));
     $element->setValueOptions(array('Markdown' => 'markdown', 'HTML' => 'html', 'Wiki' => 'wiki'));
     $markup = $this->helper->render($element);
     $this->assertNotContains('type="hidden"', $markup);
     // Lack of error also indicates this test passes
 }
 /**
  * @param  array|\Traversable $options
  * @return self
  */
 public function setOptions($options)
 {
     $this->getProxy()->setOptions($options);
     return parent::setOptions($options);
 }
Ejemplo n.º 7
0
 /**
  * Set options for an element. Accepted options are:
  * - label: label to associate with the element
  * - label_attributes: attributes to use when the label is rendered
  * - value_options: list of values and labels for the select options
  *
  * @param  array|\Traversable $options
  * @return MultiCheckbox|ElementInterface
  * @throws InvalidArgumentException
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($this->options['question'])) {
         $this->setQuestion($this->options['question']);
     }
     if (isset($this->options['header'])) {
         $this->setHeader($this->options['header']);
     }
     if (isset($this->options['answers'])) {
         $this->setAnswers($this->options['answers']);
     }
     return $this;
 }