public function __toString()
 {
     $name = Am_Controller::escape($this->getName());
     $ret = "<div class='resourceaccess' id='{$name}'>";
     $ret .= "<span class='protected-access'>\n";
     $ret .= ___('Choose Products and/or Product Categories that allows access') . "<br />\n";
     $ret .= ___('or %smake access free%s', "<a href='javascript:' class='make-free'>", '</a>') . "<br /><br />\n";
     $select = new HTML_QuickForm2_Element_Select(null, array('class' => 'access-items'));
     $select->addOption(___('Please select an item...'), '');
     $g = $select->addOptgroup(___('Product Categories'), array('class' => 'product_category_id', 'data-text' => ___("Category")));
     $g->addOption(___('Any Product'), '-1', array('style' => 'font-weight: bold'));
     foreach (Am_Di::getInstance()->productCategoryTable->getAdminSelectOptions() as $k => $v) {
         $g->addOption($v, $k);
     }
     $g = $select->addOptgroup(___('Products'), array('class' => 'product_id', 'data-text' => ___("Product")));
     foreach (Am_Di::getInstance()->productTable->getOptions() as $k => $v) {
         $g->addOption($v, $k);
     }
     $ret .= (string) $select;
     foreach (Am_Di::getInstance()->resourceAccessTable->getFnValues() as $k) {
         $ret .= "<div class='{$k}-list'></div>";
     }
     $ret .= "</span>\n";
     $ret .= "<span class='free-access' style='display:none;'>this item is available for all registered customers.<br />\n            <a href='javascript:' class='make-free'>click to make this item protected</a>\n            </span>";
     $json = array();
     if (!empty($this->value['product_category_id']) || !empty($this->value['product_id']) || !empty($this->value['free'])) {
         $json = $this->value;
         foreach ($json as &$fn) {
             foreach ($fn as &$rec) {
                 if (is_string($rec)) {
                     $rec = json_decode($rec, true);
                 }
             }
         }
     } else {
         foreach ($this->value as $cl => $access) {
             $json[$access->getClass()][$access->getId()] = array('text' => $access->getTitle(), 'start' => $access->getStart(), 'stop' => $access->getStop());
         }
     }
     $json = Am_Controller::escape(Am_Controller::getJson($json));
     $ret .= "<input type='hidden' class='resourceaccess-init' value='{$json}' />\n";
     $ret .= "</div>";
     $without_period = $this->getAttribute('without_period') ? 'true' : 'false';
     $ret .= "\n        <script type='text/javascript'>\n             \$('.resourceaccess').resourceaccess({without_period: {$without_period}});\n        </script>\n        ";
     return $ret;
 }
 public function toArray()
 {
     $id = $this->getId();
     $name = $this->getName();
     $selectFrom = new HTML_QuickForm2_Element_Select("_{$name}", array('id' => "{$id}-from") + $this->attributes);
     $selectTo = new HTML_QuickForm2_Element_Select($name, array('id' => "{$id}-to") + $this->attributes);
     $strValues = array_map('strval', $this->values);
     foreach ($this->optionContainer as $option) {
         // We don't do optgroups here
         if (!is_array($option)) {
             continue;
         }
         $value = $option['attr']['value'];
         unset($option['attr']['value']);
         if (in_array($value, $strValues, true)) {
             $selectTo->addOption($option['text'], $value, empty($option['attr']) ? null : $option['attr']);
         } else {
             $selectFrom->addOption($option['text'], $value, empty($option['attr']) ? null : $option['attr']);
         }
     }
     $buttonFromTo = HTML_QuickForm2_Factory::createElement('button', "{$name}_fromto", array('type' => 'button', 'id' => "{$id}-fromto") + (empty($this->data['from_to']['attributes']) ? array() : self::prepareAttributes($this->data['from_to']['attributes'])), array('content' => empty($this->data['from_to']['content']) ? ' &gt;&gt; ' : $this->data['from_to']['content']));
     $buttonToFrom = HTML_QuickForm2_Factory::createElement('button', "{$name}_tofrom", array('type' => 'button', 'id' => "{$id}-tofrom") + (empty($this->data['to_from']['attributes']) ? array() : self::prepareAttributes($this->data['to_from']['attributes'])), array('content' => empty($this->data['to_from']['content']) ? ' &lt;&lt; ' : $this->data['to_from']['content']));
     return array('select_from' => $selectFrom->__toString(), 'select_to' => $selectTo->__toString(), 'button_from_to' => $buttonFromTo->__toString(), 'button_to_from' => $buttonToFrom->__toString());
 }
Example #3
0
 public function testBug11138()
 {
     $options = array('2' => 'TwoWithoutZero', '02' => 'TwoWithZero');
     $sel = new HTML_QuickForm2_Element_Select('bug11138');
     $sel->loadOptions($options);
     $sel->setValue('02');
     $selHtml = $sel->__toString();
     $this->assertRegExp('!selected="selected"[^>]*>TwoWithZero!', $selHtml);
     $this->assertNotRegExp('!selected="selected"[^>]*>TwoWithoutZero!', $selHtml);
     $sel->toggleFrozen(true);
     $selFrozen = $sel->__toString();
     $this->assertContains('TwoWithZero', $selFrozen);
     $this->assertContains('value="02"', $selFrozen);
     $this->assertNotContains('TwoWithoutZero', $selFrozen);
     $this->assertNotContains('value="2"', $selFrozen);
 }
 /**
  * Disable possibleValues checks in getValue()
  *
  * For lazy people who add options to selects on client side and do not
  * want to add the same stuff server-side
  *
  * @link http://pear.php.net/bugs/bug.php?id=13088
  * @link http://pear.php.net/bugs/bug.php?id=16974
  */
 public function testDisableIntrinsicValidation()
 {
     $selectSingle = new HTML_QuickForm2_Element_Select('foo', null, array('intrinsic_validation' => false));
     $selectSingle->setValue('foo');
     $this->assertEquals('foo', $selectSingle->getValue());
     $selectSingle->loadOptions(array('one' => 'First', 'two' => 'Second'));
     $selectSingle->setValue('three');
     $this->assertEquals('three', $selectSingle->getValue());
     $selectMultiple = new HTML_QuickForm2_Element_Select('bar', array('multiple'), array('intrinsic_validation' => false));
     $selectMultiple->loadOptions(array('one' => 'First', 'two' => 'Second'));
     $selectMultiple->setValue(array('two', 'three'));
     $this->assertEquals(array('two', 'three'), $selectMultiple->getValue());
 }
 function addCategoriesProductsList(HTML_QuickForm2_Element_Select $select)
 {
     $g = $select->addOptgroup(___('Product Categories'), array('class' => 'product_category_id', 'data-text' => ___("Category")));
     $g->addOption(___('Any Product'), 'c-1', array('style' => 'font-weight: bold'));
     foreach ($this->getDi()->productCategoryTable->getAdminSelectOptions() as $k => $v) {
         $g->addOption($v, 'c' . $k);
     }
     $g = $select->addOptgroup(___('Products'), array('class' => 'product_id', 'data-text' => ___("Product")));
     foreach ($this->getDi()->productTable->getOptions() as $k => $v) {
         $g->addOption($v, 'p' . $k);
     }
 }
Example #6
0
 function getValue()
 {
     $value = parent::getValue();
     return $value == null ? array() : $value;
 }
Example #7
0
 public function __construct($name = null, $attributes = null, array $data = array())
 {
     if ($attributes === null) {
         $attributes = array();
     }
     $attributes['class'] = 'magicselect';
     $attributes['multiple'] = 'multiple';
     $attributes['data-offer'] = '-- ' . ___("Please Select") . ' --';
     parent::__construct($name, $attributes, $data);
 }
 public function testSelectMultipleNonRecursive()
 {
     $s = new HTML_QuickForm2_Element_Select('foo', array('multiple' => 'multiple'), array('intrinsic_validation' => false));
     $s->setValue(array('foo', 'bar'));
     $s->addFilter('count');
     $this->assertEquals(2, $s->getValue());
 }
 /**
  * @see  http://pear.php.net/bugs/bug.php?id=12610
  */
 function testValidateSelectMultiple()
 {
     $options = array('1' => 'Option 1', '2' => 'Option 2');
     $multiSelect = new HTML_QuickForm2_Element_Select('mult', array('multiple'), array('options' => $options));
     $nonEmpty = new HTML_QuickForm2_Rule_Nonempty($multiSelect, 'an error');
     $this->assertFalse($nonEmpty->validate());
     $multiSelect->setValue(array(1));
     $this->assertTrue($nonEmpty->validate());
     $nonEmpty->setConfig(2);
     $this->assertFalse($nonEmpty->validate());
 }