/**
  * Table constructor
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param 		$db	object	A database connector object
  * @return
  * @since 		3.0
  */
 public function __construct($db)
 {
     $jinput = JFactory::getApplication()->input;
     $template = $jinput->get('template', null, null);
     // Find which table we are importing
     $tbl = $template->get('custom_table');
     // Find the primare key for this table
     $pk = CsviHelper::getPrimaryKey($tbl);
     parent::__construct('#__' . $tbl, $pk, $db);
 }
Пример #2
0
 /**
  * Import the available fields in steps
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		3.5
  */
 public function getAvailableFieldsSingle()
 {
     $db = JFactory::getDbo();
     $jinput = JFactory::getApplication()->input;
     $queries = array();
     // Load the session data
     $session = JFactory::getSession();
     $option = $jinput->get('option');
     $csvilog = unserialize($session->get($option . '.csvilog'));
     $lines = unserialize($session->get($option . '.linesprocessed'));
     if (empty($lines)) {
         $lines = 0;
     }
     $lines++;
     // Set the line number
     $csvilog->setLinenumber($lines);
     $errors = false;
     $process = false;
     // Load a table to index
     while (!$process) {
         $query = $db->getQuery(true);
         $query->select('template_table, component')->from('#__csvi_template_tables')->where('indexed = 0')->where($db->qn('template_table') . ' != ' . $db->qn('template_type_name'))->group($db->qn('template_table'));
         $db->setQuery($query, 0, 1);
         $table = $db->loadObject();
         if (is_object($table)) {
             // Set the table name
             $showtable = $table->template_table;
             // Check if the table exists
             $tables = $db->getTableList();
             if (in_array($db->getPrefix() . $showtable, $tables)) {
                 // Get the primary key for the table
                 $primarykey = CsviHelper::getPrimaryKey($showtable);
                 $fields = $this->DbFields($showtable, true);
                 if (is_array($fields)) {
                     $process = true;
                     // Process all fields
                     foreach ($fields as $name => $value) {
                         // Check if the field is a primary field
                         if ($primarykey == $name) {
                             $primary = 1;
                         } else {
                             $primary = 0;
                         }
                         if ($name) {
                             $q = "INSERT IGNORE INTO " . $db->qn('#__csvi_available_fields') . " VALUES (" . "0," . $db->q($name) . "," . $db->q($name) . "," . $db->q($value) . "," . $db->q($table->component) . "," . $db->q($primary) . ")";
                             $db->setQuery($q);
                             if (!$db->query()) {
                                 $errors = true;
                             }
                         }
                     }
                     // foreach
                     // Check for any errors
                     if (!$errors) {
                         $jinput->set('updatetable', $showtable);
                         $csvilog->AddStats('added', JText::sprintf('COM_CSVI_AVAILABLE_FIELDS_HAVE_BEEN_ADDED', $showtable));
                     } else {
                         $csvilog->AddStats('error', JText::_('COM_CSVI_AVAILABLE_FIELDS_HAVE_NOT_BEEN_ADDED'));
                     }
                 }
                 // is_array
             }
             // Set the table to indexed
             $query = $db->getQuery(true);
             $query->update('#__csvi_template_tables')->set('indexed = 1')->where('template_table = ' . $db->quote($showtable))->where('component = ' . $db->quote($table->component));
             $db->setQuery($query);
             $db->query();
             // Assign the tables to the session
             $session->set($option . '.linesprocessed', serialize($lines));
             $continue = true;
         } else {
             $jinput->set('csvilog', $csvilog);
             // Clear the session
             $session->set($option . '.csvilog', serialize('0'));
             $session->set($option . '.linesprocessed', serialize('0'));
             // Set the run ID
             $jinput->set('run_id', $csvilog->getId());
             $continue = false;
             $process = true;
         }
         // Assign the log to the session
         $session->set($option . '.csvilog', serialize($csvilog));
     }
     return $continue;
 }