Example #1
0
 /**
  * Specify the options to load
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		protected
  * @param
  * @return 		array	an array of options
  * @since 		4.0
  */
 protected function getOptions()
 {
     $this->options = array();
     if (class_exists('com_k2')) {
         $jinput = JFactory::getApplication()->input;
         $template = $jinput->get('template', null, null);
         $helper = new Com_K2();
         $this->options = $helper->getCategoryTree($template->get('language', 'general', '*'));
     }
     return $this->options;
 }
Example #2
0
 /**
  * Category details export
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.0
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $csvilog = $jinput->get('csvilog', null, null);
     $template = $jinput->get('template', null, null);
     $exportclass = $jinput->get('export.class', null, null);
     $export_fields = $jinput->get('export.fields', array(), 'array');
     $helper = new Com_K2();
     // Build something fancy to only get the fieldnames the user wants
     $userfields = array();
     foreach ($export_fields as $column_id => $field) {
         switch ($field->field_name) {
             case 'category_path':
                 $userfields[] = $db->qn('c') . '.' . $db->qn('id');
                 break;
             case 'parent_category_path':
                 $userfields[] = $db->qn('c') . '.' . $db->qn('parent');
                 break;
             case 'custom':
                 break;
             default:
                 $userfields[] = $db->qn($field->field_name);
                 break;
         }
     }
     // Build the query
     $userfields = array_unique($userfields);
     $query = $db->getQuery(true);
     $query->select(implode(",\n", $userfields));
     $query->from($db->qn("#__k2_categories", "c"));
     $selectors = array();
     // Filter by published state
     $publish_state = $template->get('publish_state', 'general');
     if ($publish_state != '' && ($publish_state == 1 || $publish_state == 0)) {
         $selectors[] = 'c.published = ' . $publish_state;
     }
     // Check if we need to attach any selectors to the query
     if (count($selectors) > 0) {
         $query->where(implode("\n AND ", $selectors));
     }
     // Ignore fields
     $ignore = array('category_path', 'parent_category_path');
     // Check if we need to group the orders together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     if (!empty($orderby)) {
         $query->order($orderby);
     }
     // Add a limit if user wants us to
     $limits = $this->getExportLimit();
     // Execute the query
     $csvidb->setQuery($query, $limits['offset'], $limits['limit']);
     $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
     // There are no records, write SQL query to log
     if (!is_null($csvidb->getErrorMsg())) {
         $this->addExportContent(JText::sprintf('COM_CSVI_ERROR_RETRIEVING_DATA', $csvidb->getErrorMsg()));
         $this->writeOutput();
         $csvilog->AddStats('incorrect', $csvidb->getErrorMsg());
     } else {
         $logcount = $csvidb->getNumRows();
         $jinput->set('logcount', $logcount);
         if ($logcount > 0) {
             $linenumber = 1;
             while ($record = $csvidb->getRow()) {
                 $csvilog->setLinenumber($linenumber++);
                 if ($template->get('export_file', 'general') == 'xml' || $template->get('export_file', 'general') == 'html') {
                     $this->addExportContent($exportclass->NodeStart());
                 }
                 foreach ($export_fields as $column_id => $field) {
                     $fieldname = $field->field_name;
                     $fieldreplace = $field->field_name . $field->column_header;
                     // Add the replacement
                     if (isset($record->{$fieldname})) {
                         $fieldvalue = CsviHelper::replaceValue($field->replace, $record->{$fieldname});
                     } else {
                         $fieldvalue = '';
                     }
                     switch ($fieldname) {
                         case 'category_path':
                             $fieldvalue = $helper->createCategoryPathById($record->id);
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'parent_category_path':
                             $fieldvalue = $helper->createCategoryPathById($record->parent);
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'custom':
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         default:
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                     }
                 }
                 // Output the data
                 $this->addExportFields($record);
                 if ($template->get('export_file', 'general') == 'xml' || $template->get('export_file', 'general') == 'html') {
                     $this->addExportContent($exportclass->NodeEnd());
                 }
                 // Output the contents
                 $this->writeOutput();
             }
         } else {
             $this->addExportContent(JText::_('COM_CSVI_NO_DATA_FOUND'));
             // Output the contents
             $this->writeOutput();
         }
     }
 }