Esempio n. 1
0
 /**
  * @throws AppException
  */
 public function index()
 {
     $this->app->jbdebug->mark('autocomplete::start');
     if (!$this->app->jbcache->start(null, 'autocomplete')) {
         $type = $this->_jbrequest->get('type');
         $query = $this->_jbrequest->get('value');
         $appId = $this->_jbrequest->get('app_id');
         $element = $this->_jbrequest->get('name');
         if ($element && preg_match('/(?:\\[)([^]]*)(?:[]])(?(?<=\\[)|\\[?([^]]*))/i', $element, $element_id)) {
             $param_id = isset($element_id[2]) ? $element_id[2] : null;
             $element_id = $element_id[1];
             $element = $this->app->jbentity->getElement($element_id, $type, $appId);
             $elementType = $element->getElementType();
             $db = JBModelAutocomplete::model();
             if ($element_id == '_itemname') {
                 $rows = $db->name($query, $type, $appId);
             } elseif ($element_id == '_itemtag') {
                 $rows = $db->tag($query, $type, $appId);
             } elseif ($element_id == '_itemauthor') {
                 $rows = $db->author($query, $type, $appId);
             } else {
                 if ($element instanceof ElementJBPrice) {
                     $param_id = JBModelSku::model()->getId($param_id);
                     $rows = $db->priceElement($query, $element_id, $param_id, $type, $appId);
                 } else {
                     if ($elementType == 'textarea') {
                         $rows = $db->textarea($query, $element_id, $type, $appId);
                     } else {
                         if ($elementType == 'jbcomments') {
                             $rows = $db->comments($query, $type, $appId);
                         } else {
                             $rows = $db->field($query, $element_id, $type, $appId);
                         }
                     }
                 }
             }
             $data = array();
             if (!empty($rows)) {
                 foreach ($rows as $row) {
                     if (JString::strlen($row->value) > self::MAX_LENGTH) {
                         $value = $this->app->jbstring->smartSubstr($row->value, $query);
                     } else {
                         $value = $row->value;
                     }
                     $label = isset($row->label) ? $row->label : $row->value;
                     $id = isset($row->id) ? $row->id : $row->value;
                     $data[] = array('id' => JString::str_ireplace("\n", " ", $id), 'label' => JString::str_ireplace("\n", " ", $label), 'value' => JString::str_ireplace("\n", " ", JString::trim($value, '.')));
                 }
             }
             echo json_encode($data);
         } else {
             throw new AppException('Unkown element name');
         }
         $this->app->jbcache->stop();
     }
     $this->app->jbdebug->mark('autocomplete::end');
     jexit();
 }
Esempio n. 2
0
 /**
  * @return string
  */
 public function getInput()
 {
     JBModelSku::model();
     $elements = array();
     $app = App::getInstance('zoo');
     $application = $app->zoo->getApplication();
     $i = 0;
     $elementsList = $app->jbentity->getItemTypesData(1);
     $typesList = $app->jbtype->getSimpleList();
     $exclude = JBModelSearchindex::model()->getExcludeTypes();
     $textHeadType = JText::_('JBZOO_FIELDS_CORE');
     $stdFields = array('' => JText::_('JBZOO_MODITEM_SELECT_OPTION'), '_itemauthor' => 'Item Author', '_itemcategory' => 'Item Category', '_itemcreated' => 'Item Created', '_itemfrontpage' => 'Item Frontpage', '_itemmodified' => 'Item Modified', '_itemname' => 'Item Name', '_itempublish_up' => 'Item Publish Up', '_itempublish_down' => 'Item Publish Down', '_itemtag' => 'Item Tag');
     $elements[$textHeadType] = array('items' => $stdFields);
     foreach ($exclude as $key => $value) {
         if ($value == 'textarea') {
             unset($exclude[$key]);
         }
     }
     foreach ($elementsList as $type => $tmpElements) {
         if (array_key_exists($type, $typesList)) {
             $appType = $application->getType($type);
             if (!$appType) {
                 continue;
             }
             foreach ($tmpElements as $key => $element) {
                 if (!in_array($element['type'], $exclude) && strpos($key, '_') === false) {
                     $instance = $appType->getElement($key);
                     if ($instance instanceof ElementJBPrice) {
                         $name = $instance->config->get('name');
                         $newEls[] = array('value' => $key, 'text' => '- ' . $name, 'disable' => true);
                         if ($params = $instance->getElements()) {
                             foreach ($params as $id => $param) {
                                 if ($param->hasFilterValue()) {
                                     $newEls[] = array('value' => $key . '__' . $id, 'text' => '-- ' . $name . ' - ' . $param->getName());
                                 }
                             }
                         }
                     } else {
                         $newEls[$element['name']] = array('value' => $key, 'text' => $element['name']);
                     }
                 }
             }
         }
         if (!empty($newEls)) {
             $elements[$typesList[$type]] = array('items' => $newEls);
         }
         unset($newEls);
     }
     if (empty($this->value)) {
         $this->value = array(array('key' => '', 'value' => ''));
     }
     foreach ($this->value as $value) {
         $value = (array) $value;
         if ($i != 0 && (!isset($value['key']) || empty($value['key']))) {
             continue;
         }
         $html[] = '<div class="jbjkeyvalue-row">';
         $html[] = JHtml::_('select.groupedlist', $elements, $this->getName($this->fieldname) . '[' . $i . '][key]', array('list.select' => isset($value['key']) ? $value['key'] : ''));
         $html[] = '<input ' . $app->jbhtml->buildAttrs(array('placeholder' => JText::_('JBZOO_JBKEYVALUE_VALUE'), 'type' => 'text', 'name' => $this->getName($this->fieldname) . '[' . $i . '][value]', 'value' => isset($value['value']) ? $value['value'] : '', 'class' => isset($class) ? $class : '')) . ' />';
         if ($i !== 0) {
             $html[] = '<a href="#jbjkeyvalue-rem" class="jsJKeyValueRemove" title="' . JText::_('JBZOO_JBKEYVALUE_ADD') . '"></a>';
         }
         $html[] = JBZOO_CLR;
         $html[] = '</div>';
         $i++;
     }
     $html[] = JBZOO_CLR;
     $html[] = '<a href="#jbjkeyvalue-add" class="jsJKeyValueAdd">' . JText::_('JBZOO_JBKEYVALUE_ADD') . '</a>';
     $html[] = JBZOO_CLR;
     return '<div class="jsJKeyValue">' . implode(PHP_EOL, $html) . '</div>' . JBZOO_CLR;
 }
Esempio n. 3
0
 /**
  * Get item by id
  * @param $sku
  * @param $appId
  * @return Item|null
  */
 public function getBySku($sku, $appId = null)
 {
     $itemId = (int) JBModelSku::model()->getItemIdBySku($sku);
     if ($itemId > 0 && ($item = $this->getById($itemId))) {
         if ($appId === null) {
             return $item;
         } elseif ((int) $item->application_id === (int) $appId) {
             return $item;
         }
     }
     return null;
 }