Exemplo n.º 1
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;
 }