Esempio n. 1
0
 public function getInput()
 {
     // get app
     $app = App::getInstance('zoo');
     $categoryName = array();
     $attr = array();
     $options = array();
     $appList = JBModelApp::model()->getList();
     if ((int) $this->element->attributes()->multiple) {
         $attr['multiple'] = 'multiple';
     }
     if ((int) $this->element->attributes()->required) {
         $attr['required'] = 'required';
     }
     if ((int) $this->element->attributes()->size) {
         $attr['size'] = (int) $this->element->attributes()->size;
     } else {
         $attr['size'] = 10;
     }
     if (!empty($appList)) {
         foreach ($appList as $application) {
             $allCategories = $application->getCategories(true);
             if (!empty($allCategories)) {
                 foreach ($allCategories as $category) {
                     $categoryName[$category->id] = $category->name;
                 }
                 $options[$application->name] = $categoryName;
             }
         }
         return JHtml::_('select.groupedlist', $options, $this->getName($this->fieldname), array('list.attr' => $app->jbhtml->buildAttrs($attr), 'list.select' => $this->value, 'group.items' => null));
     }
 }
Esempio n. 2
0
 /**
  * @return null|string
  */
 public function getInput()
 {
     $app = App::getInstance('zoo');
     $idElement = uniqid('element');
     $options = array(0 => JText::_('JBZOO_FIELDS_APP'));
     $categoryList = array();
     $html = array();
     $value = array('appId' => 0, 'catId' => '');
     $appList = JBModelApp::model()->getList();
     if (!empty($appList)) {
         foreach ($appList as $application) {
             $options[$application->id] = $application->name;
             if ((int) $this->element->attributes()->show_categories !== 0) {
                 $allCategories = $application->getCategories(true);
                 $categories = $application->app->tree->buildList(0, $application->app->tree->build($allCategories, 'Category'));
                 if ((int) $this->element->attributes()->showcategories_all == 1) {
                     $categoryList[$application->id]['-1'] = ' - ' . JText::_('JBZOO_ALL') . ' - ';
                 }
                 $categoryList[$application->id]['0'] = ' - ' . JText::_('JBZOO_FIELDS_FRONTPAGE') . ' - ';
                 foreach ($categories as $category) {
                     $categoryList[$category->application_id][$category->id] = $category->treename;
                 }
             }
         }
         $html[] = '<div id="' . $idElement . '" class="application">';
         $html[] = '<div class="jbapp-list zoo-application">';
         $html[] = $app->jbhtml->select($options, "", array('class' => 'application'), $this->value);
         $html[] = '</div>';
         foreach ($categoryList as $id => $category) {
             $html[] = '<div class="jbcategory-list app-' . $id . '" style="display:none;">';
             $html[] = $app->jbhtml->select($categoryList[$id], "", '', $this->value);
             $html[] = '</div>';
             if (!empty($this->value)) {
                 $arr = explode(':', $this->value);
                 $value['catId'] = $arr[1];
             }
         }
         if (!empty($this->value)) {
             list($value['appId'], $value['catId']) = explode(':', $this->value);
         }
         $html[] = $app->jbhtml->hidden($this->getName($this->fieldname), $this->value, array('class' => 'hidden-value'));
         $html[] = '</div>';
         $html[] = $app->jbassets->widget('#' . $idElement, 'JBCategoryList', $value, true);
         $app->jbassets->jQuery();
         $app->jbassets->js("jbapp:joomla/fields/jbappcategorylist.js");
         return implode(PHP_EOL, $html);
     }
     return JText::_('JBZOO_MODCATEGORY_EMPTY_APP');
 }
Esempio n. 3
0
 /**
  * Get info for pre import step
  * @param string $file
  * @param array  $options
  * @return array
  */
 public function getInfo($file, $options)
 {
     $options = $this->app->data->create($options);
     $info = array();
     // get applications
     $applist = JBModelApp::model()->getList();
     if (!empty($applist)) {
         $info['applist'] = array();
         foreach ($applist as $app) {
             $info['applist'][$app->id] = $app->name;
         }
         reset($applist);
         $application = current($applist);
         $info['app'] = current($applist);
     }
     // get types
     $info['types'] = array();
     foreach ($info['app']->getTypes() as $type) {
         $info['types'][$type->id] = array();
         foreach ($type->getElements() as $element) {
             // filter elements
             $info['types'][$type->id][$element->getElementType()][] = $element;
         }
     }
     $info['item_count'] = 0;
     $info['columns'] = array();
     // get params
     $separator = $options->get('separator', ',') ? $options->get('separator', ',') : ',';
     $enclosure = $options->get('enclosure', '"') ? $options->get('enclosure', '"') : '"';
     $containsHeaders = (int) $options->get('header', 1);
     // get column names and row count
     $rowCount = 0;
     if (($handle = fopen($file, "r")) !== false) {
         while (($data = fgetcsv($handle, 0, $separator, $enclosure)) !== false) {
             if ($rowCount == 0) {
                 if ($containsHeaders) {
                     $info['columns'] = $data;
                 } else {
                     $info['columns'] = array_fill(0, count($data), '');
                 }
             }
             $rowCount++;
         }
         fclose($handle);
     }
     $info['count'] = $containsHeaders ? $rowCount - 1 : $rowCount;
     return $info;
 }