Example #1
0
 /**
  * Parse a content element file.
  *
  * @param   string $groupName           Group name
  * @param   array  $contentElementFiles Content element file path
  *
  * @return bool True on success
  *
  * @throws Exception
  */
 public static function parseContentElementFiles($groupName, $contentElementFiles)
 {
     // Create an array of group data
     $groupData = array('groupName' => $groupName);
     $group = new NenoContentElementGroup($groupData);
     foreach ($contentElementFiles as $contentElementFile) {
         $xmlDoc = new DOMDocument();
         if ($xmlDoc->load($contentElementFile) === false) {
             throw new Exception(JText::_('Error reading content element file'));
         }
         $tables = $xmlDoc->getElementsByTagName('table');
         /* @var $tableData DOMElement */
         foreach ($tables as $tableData) {
             $tableName = $tableData->getAttribute('name');
             // If the table hasn't been added yet, let's add it
             if (!NenoHelper::isTableAlreadyDiscovered($tableName)) {
                 $table = new NenoContentElementTable(array('tableName' => $tableName, 'translate' => 0));
                 $fields = $tableData->getElementsByTagName('field');
                 /* @var $fieldData DOMElement */
                 foreach ($fields as $fieldData) {
                     $field = new NenoContentElementField(array('fieldName' => $fieldData->getAttribute('name'), 'translate' => intval($fieldData->getAttribute('translate')), 'table' => $table));
                     $table->addField($field);
                     // If the field has this attribute, it means this is the primary key field of the table
                     if ($fieldData->hasAttribute('referenceid')) {
                         $table->setPrimaryKey($field->getFieldName());
                     }
                 }
                 $group->addTable($table);
             }
         }
     }
     $tables = $group->getTables();
     // Checking if the group has tables
     if (!empty($tables)) {
         $group->persist();
     }
     return true;
 }
Example #2
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 #3
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 #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;
 }