Exemple #1
0
 /**
  * Get a particular element using the level
  *
  * @param   string $level Hierarchy level
  *
  * @return NenoContentElementInterface|null
  */
 protected function getElementByLevel($level)
 {
     $element = null;
     $elementId = NenoSettings::get('discovering_element_' . $level);
     $this->initPercents();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     switch ($level) {
         // Groups
         case '0':
             // This means to get a group that haven't been discovered yet
             $extensions = $db->quote(NenoHelper::whichExtensionsShouldBeTranslated());
             $query->clear()->select('e.*')->from('`#__extensions` AS e')->where(array('e.type IN (' . implode(',', $extensions) . ')', 'e.name NOT LIKE \'com_neno\'', 'NOT EXISTS (SELECT 1 FROM #__neno_content_element_groups_x_extensions AS ge WHERE ge.extension_id = e.extension_id)'))->order('name');
             $db->setQuery($query, 0, 1);
             $extension = $db->loadAssoc();
             if (!empty($extension)) {
                 // Check if this extension has been discovered already
                 $groupId = NenoHelper::isExtensionAlreadyDiscovered($extension['extension_id']);
                 if ($groupId !== false) {
                     $group = NenoContentElementGroup::load($groupId);
                 } else {
                     $group = new NenoContentElementGroup(array('group_name' => $extension['name']));
                 }
                 /* @var $group NenoContentElementGroup */
                 $group->addExtension($extension['extension_id']);
                 $extensionName = NenoHelper::getExtensionName($extension);
                 $languageFiles = NenoHelper::getLanguageFiles($extensionName);
                 $tables = NenoHelper::getComponentTables($group, $extensionName);
                 $group->setAssignedTranslationMethods(NenoHelper::getTranslationMethodsForLanguages());
                 // If the group contains tables and/or language strings, let's save it
                 if (!empty($tables) || !empty($languageFiles)) {
                     $group->setLanguageFiles($languageFiles)->setTables($tables);
                 }
                 $element = $group;
             } else {
                 $element = NenoHelperBackend::groupingTablesNotDiscovered(false);
             }
             break;
             // Tables
         // Tables
         case '1.1':
             // This means to get a table which has fields that haven't been discovered yet.
             if (empty($elementId)) {
                 // Get one table that hasn't been discovered yet
                 $table = NenoContentElementTable::load(array('discovered' => 0, '_limit' => 1, 'translate' => 1, 'group_id' => NenoSettings::get('discovering_element_0')), false, true);
             } else {
                 $table = NenoContentElementTable::load($elementId, false, true);
             }
             if (!empty($table)) {
                 $element = $table;
             }
             break;
             // Language files
         // Language files
         case '1.2':
             // This means to get a language file which has language strings that haven't been discovered yet.
             if ($elementId == null) {
                 // Get one table that hasn't been discovered yet
                 $languageFile = NenoContentElementLanguageFile::load(array('discovered' => 0, '_limit' => 1, 'group_id' => NenoSettings::get('discovering_element_0')), false, true);
             } else {
                 $languageFile = NenoContentElementLanguageFile::load($elementId, false, true);
             }
             if (!empty($languageFile)) {
                 $element = $languageFile;
             }
             break;
             // Fields
         // Fields
         case '2.1':
             // This means to get a field that hasn't been completed yet.
             if ($elementId == null) {
                 // Get one table that hasn't been discovered yet
                 $field = NenoContentElementField::load(array('discovered' => 0, '_limit' => 1, 'translate' => 1), false, true);
             } else {
                 $field = NenoContentElementField::load($elementId);
             }
             if (!empty($field) && $field) {
                 $element = $field;
             }
             break;
             // Language strings
         // Language strings
         case '2.2':
             // This means to get a language string that hasn't been completed yet.
             if ($elementId == null) {
                 // Get one table that hasn't been discovered yet
                 $languageString = NenoContentElementLanguageString::load(array('discovered' => 0, '_limit' => 1), false, true);
             } else {
                 $languageString = NenoContentElementLanguageString::load($elementId);
             }
             if (!empty($languageString)) {
                 $element = $languageString;
             }
             break;
     }
     return $element;
 }