Example #1
0
 public function getProgressCounters()
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $subqueryTotal = $db->getQuery(true);
     $subqueryProcessed = $db->getQuery(true);
     $subqueryTotal->select('COUNT(*)')->from($this->table->getTableName());
     $subqueryProcessed->select('COUNT(*)')->from($this->table->getTableName());
     $primaryKeyData = $this->getTable()->getPrimaryKey();
     $breakpoint = NenoSettings::get('field_breakpoint', null);
     if (!empty($breakpoint)) {
         $breakpoint = json_decode($breakpoint, true);
         foreach ($primaryKeyData as $primaryKey) {
             if (!empty($breakpoint[$primaryKey])) {
                 $subqueryProcessed->where($db->quoteName($primaryKey) . ' < ' . $breakpoint[$primaryKey]);
             }
         }
     } else {
         $subqueryProcessed = 0;
     }
     $query->select(array('(' . (string) $subqueryTotal . ') AS total', '(' . (string) $subqueryProcessed . ') AS processed'));
     $db->setQuery($query);
     $progressCounters = $db->loadAssoc();
     return $progressCounters;
 }
Example #2
0
 /**
  * Grouping tables that haven't been discovered
  *
  * @param   bool $persist Persist the group
  *
  * @return NenoContentElementGroup
  */
 public static function groupingTablesNotDiscovered($persist = true)
 {
     /* @var $db NenoDatabaseDriverMysqlx */
     $db = JFactory::getDbo();
     // Get all the tables that haven't been detected using naming convention.
     $tablesNotDiscovered = self::getTablesNotDiscovered();
     $tablesAdded = false;
     $otherGroup = null;
     if (!empty($tablesNotDiscovered)) {
         // Check if this group exists already
         $query = $db->getQuery(true);
         $query->select('g.id')->from('#__neno_content_element_groups AS g')->where('NOT EXISTS (SELECT 1 FROM #__neno_content_element_groups_x_extensions AS ge WHERE ge.group_id = g.id)');
         $db->setQuery($query);
         $groupId = $db->loadResult();
         if (!empty($groupId)) {
             /* @var $otherGroup NenoContentElementGroup */
             $otherGroup = NenoContentElementGroup::load($groupId);
         } else {
             $otherGroup = new NenoContentElementGroup(array('group_name' => 'Other'));
         }
         $tablesIgnored = NenoHelper::getDoNotTranslateTables();
         foreach ($tablesNotDiscovered as $tableNotDiscovered) {
             if (!in_array($tableNotDiscovered, $tablesIgnored)) {
                 // Create an array with the table information
                 $tableData = array('tableName' => $tableNotDiscovered, 'primaryKey' => $db->getPrimaryKey($tableNotDiscovered), 'translate' => 1, 'group' => $otherGroup);
                 // Create ContentElement object
                 $table = new NenoContentElementTable($tableData);
                 // Get all the columns a table contains
                 $fields = $db->getTableColumns($table->getTableName());
                 foreach ($fields as $fieldName => $fieldType) {
                     $fieldData = array('fieldName' => $fieldName, 'fieldType' => $fieldType, 'translate' => NenoContentElementField::isTranslatableType($fieldType), 'table' => $table);
                     $field = new NenoContentElementField($fieldData);
                     $table->addField($field);
                 }
                 $otherGroup->addTable($table);
                 $tablesAdded = true;
             }
         }
         $otherGroup->setAssignedTranslationMethods(NenoHelper::getTranslationMethodsForLanguages());
         if ($persist) {
             $otherGroup->persist();
         }
     }
     if (!$tablesAdded) {
         $otherGroup = null;
     }
     return $otherGroup;
 }
Example #3
0
 /**
  * Create Table instance
  *
  * @param string                  $tableName Table name
  * @param NenoContentElementGroup $group     Group
  *
  * @return NenoContentElementTable
  */
 public static function createTableInstance($tableName, NenoContentElementGroup $group)
 {
     /* @var $db NenoDatabaseDriverMysqlx */
     $db = JFactory::getDbo();
     // Create an array with the table information
     $tableData = array('tableName' => $tableName, 'primaryKey' => $db->getPrimaryKey($tableName), 'translate' => !$group->isOtherGroup(), 'group' => $group);
     // Create ContentElement object
     $table = new NenoContentElementTable($tableData);
     // Get all the columns a table contains
     $fields = $db->getTableColumns($table->getTableName());
     foreach ($fields as $fieldName => $fieldType) {
         $fieldData = array('fieldName' => $fieldName, 'fieldType' => $fieldType, 'translate' => NenoContentElementField::isTranslatableType($fieldType), 'table' => $table);
         $field = new NenoContentElementField($fieldData);
         $table->addField($field);
     }
     return $table;
 }
Example #4
0
 /**
  * Get all the tables of the component that matches with the Joomla naming convention.
  *
  * @param   NenoContentElementGroup $group             Component name
  * @param   string                  $tablePattern      Table Pattern
  * @param   bool                    $includeDiscovered Included tables that have been discovered already
  *
  * @return array
  */
 public static function getComponentTables(NenoContentElementGroup $group, $tablePattern = null, $includeDiscovered = true)
 {
     /* @var $db NenoDatabaseDriverMysqlx */
     $db = JFactory::getDbo();
     $tables = $db->getComponentTables($tablePattern === null ? $group->getGroupName() : $tablePattern);
     $result = array();
     for ($i = 0; $i < count($tables); $i++) {
         // Get Table name
         $tableName = self::unifyTableName($tables[$i]);
         $table = null;
         $tablesIgnored = self::getDoNotTranslateTables();
         if (!in_array($tableName, $tablesIgnored)) {
             if (!self::isTableAlreadyDiscovered($tableName)) {
                 // Create an array with the table information
                 $tableData = array('tableName' => $tableName, 'primaryKey' => $db->getPrimaryKey($tableName), 'translate' => 1, 'group' => $group);
                 // Create ContentElement object
                 $table = new NenoContentElementTable($tableData);
                 // Get all the columns a table contains
                 $fields = $db->getTableColumns($table->getTableName());
                 foreach ($fields as $fieldName => $fieldType) {
                     $fieldData = array('fieldName' => $fieldName, 'fieldType' => $fieldType, 'translate' => NenoContentElementField::isTranslatableType($fieldType), 'table' => $table);
                     $field = new NenoContentElementField($fieldData);
                     $table->addField($field);
                 }
             } elseif ($includeDiscovered) {
                 $table = NenoContentElementTable::load(array('table_name' => $tableName, 'group_id' => $group->getId()));
             }
         }
         if (!empty($table)) {
             $result[] = $table;
         }
     }
     return $result;
 }