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;
 }
示例#2
0
 public function testAddOptionToOptgroup()
 {
     $sel = new HTML_QuickForm2_Element_Select();
     $optgroup = $sel->addOptgroup('Label');
     $optgroup->addOption('Text', 'Value');
     $this->assertRegExp('!^<select[^>]*>\\s*<optgroup[^>]+label="Label"[^>]*>\\s*' . '<option[^>]+value="Value"[^>]*>Text</option>\\s*</optgroup>\\s*</select>!', $sel->__toString());
     $sel2 = new HTML_QuickForm2_Element_Select();
     $optgroup2 = $sel2->addOptgroup('Label');
     $optgroup2->addOption('Text', 'Value', array('class' => 'bar'));
     $this->assertRegExp('!<optgroup[^>]+label="Label"[^>]*>\\s*<option[^>]+class="bar"[^>]*>Text</option>\\s*</optgroup>!', $sel2->__toString());
     $sel3 = new HTML_QuickForm2_Element_Select();
     $optgroup3 = $sel3->addOptgroup('Label');
     $optgroup3->addOption('Text', 'Value', array('selected'));
     $this->assertEquals('Value', $sel3->getValue());
     $this->assertRegExp('!<optgroup[^>]+label="Label"[^>]*>\\s*<option[^>]+selected="selected"[^>]*>Text</option>\\s*</optgroup>!', $sel3->__toString());
 }
 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);
     }
 }