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;
 }