protected function _cols(ffOneOption $oneOption)
 {
     $cols = trim($oneOption->getParam('cols'));
     return empty($cols) ? ' cols="30" ' : ' cols="' . $cols . '" ';
 }
コード例 #2
0
 protected function _printOption(ffOneOption $oneOption, $nameRoute, $idRoute)
 {
     $postType = $oneOption->getParam('post_type', 'page');
     $postGetter = ffContainer::getInstance()->getPostLayer()->getPostGetter();
     $posts = $postGetter->setNumberOfPosts(-1)->getPostsByType($postType);
     //$taxGetter = ffContainer::getInstance()->getTaxLayer()->getTaxGetter();//ffContainer::getInstance()->getTaxLayer()->getTaxGetter()->filterByTaxonomy('category')->getList());
     //$tax = $taxGetter->filterByTaxonomy( $taxType )->getList();
     $selectValues = $oneOption->getSelectValues();
     $selectValuesNew = array();
     if ($posts instanceof WP_Error) {
         $selectValuesNew = array();
     } else {
         foreach ($posts as $onePost) {
             $selectValuesNew[] = array('name' => $onePost->getTitle(), 'value' => $onePost->getId());
         }
     }
     if (empty($selectValues)) {
         $selectValues = array();
     }
     $selectValues = array_merge($selectValues, $selectValuesNew);
     //$selectValues = array_merge( $selectValues, $selectValuesNew );
     $selectedValue = $oneOption->getValue();
     $selectedValueExploded = explode('--||--', $selectedValue);
     $multiple = $oneOption->getParam('type', '');
     $isGroup = $oneOption->getParam('is_group', false);
     $width = $oneOption->getParam('width', 0);
     $style = '';
     echo '<div class="ff-select2-wrapper">';
     echo '<div class="ff-select2-value-wrapper">';
     echo '<input type="text" class="ff-select2-value" name="' . $nameRoute . '" value="' . $selectedValue . '">';
     echo '</div>';
     echo '<div class="ff-select2-real-wrapper">';
     echo '<select ' . $multiple . ' size="1" data-selected-value="' . $selectedValue . '" class="ff-select2" name="' . $nameRoute . '" ' . $style . '>';
     if (!$isGroup) {
         if (!empty($selectValues)) {
             foreach ($selectValues as $oneValue) {
                 $selected = '';
                 if ($this->_isValueSelected($oneValue['value'], $selectedValueExploded)) {
                     $selected = ' selected="selected" ';
                 }
                 echo '<option value="' . $oneValue['value'] . '" ' . $selected . '>' . $oneValue['name'] . '</option>';
             }
         }
     } else {
         if (!empty($selectValues)) {
             foreach ($selectValues as $groupName => $values) {
                 echo '<optgroup label="' . $groupName . '">';
                 foreach ($values as $oneValue) {
                     $selected = '';
                     if ($this->_isValueSelected($oneValue['value'], $selectedValue)) {
                         $selected = ' selected="selected" ';
                     }
                     echo '<option value="' . $oneValue['value'] . '" ' . $selected . '>' . $oneValue['name'] . '</option>';
                 }
                 echo '</optgroup>';
             }
         }
     }
     echo '</select>';
     echo '</div>';
     echo '<div class="ff-select2-shadow-wrapper">';
     echo '<select ' . $multiple . ' data-selected-value="' . $selectedValue . '" class="ff-select2" name="' . $nameRoute . '" ' . $style . '>';
     if (!$isGroup) {
         if (!empty($selectValues)) {
             foreach ($selectValues as $oneValue) {
                 $selected = '';
                 if ($oneValue['value'] == $selectedValue) {
                     $selected = ' selected="selected" ';
                 }
                 echo '<option value="' . $oneValue['value'] . '" ' . $selected . '>' . $oneValue['name'] . '</option>';
             }
         }
     } else {
         if (!empty($selectValues)) {
             foreach ($selectValues as $groupName => $values) {
                 echo '<optgroup label="' . $groupName . '">';
                 foreach ($values as $oneValue) {
                     $selected = '';
                     if ($oneValue['value'] == $selectedValue) {
                         $selected = ' selected="selected" ';
                     }
                     echo '<option value="' . $oneValue['value'] . '" ' . $selected . '>' . $oneValue['name'] . '</option>';
                 }
                 echo '</optgroup>';
             }
         }
     }
     echo '</select>';
     echo '</div>';
     echo '</div>';
 }