/** * {@inheritdoc} * * @param bool $allFields Allows to show all the fields * @param bool $recursive Convert this method in recursive * @param bool $convertToDatabase Convert property names to database * * @return stdClass */ public function toObject($allFields = false, $recursive = false, $convertToDatabase = true) { $data = parent::toObject($allFields, $recursive, $convertToDatabase); if (!empty($this->languageFile)) { $data->languagefile_id = $this->languageFile->getId(); } if ($this->timeAdded instanceof DateTime) { $this->timeAdded = $this->timeAdded->format('Y-m-d H:i:s'); } return $data; }
/** * Get all the language files * * @return array */ public function getLanguageFiles() { if ($this->languageFiles === null) { $this->languageFiles = NenoContentElementLanguageFile::load(array('group_id' => $this->getId())); if (!is_array($this->languageFiles)) { $this->languageFiles = array($this->languageFiles); } } return $this->languageFiles; }
public function scanForContent() { $input = $this->input; // Refresh content for groups $groups = $input->get('groups', array(), 'ARRAY'); $tables = $input->get('tables', array(), 'ARRAY'); $files = $input->get('files', array(), 'ARRAY'); $workingLanguage = NenoHelper::getWorkingLanguage(); if (!empty($groups)) { foreach ($groups as $groupId) { /* @var $group NenoContentElementGroup */ $group = NenoContentElementGroup::load($groupId); if (!empty($group)) { $group->refresh($workingLanguage); } } } elseif (!empty($tables) || !empty($files)) { foreach ($tables as $tableId) { /* @var $table NenoContentElementTable */ $table = NenoContentElementTable::load($tableId); if (!empty($table) && $table->isTranslate()) { // Sync table $table->sync(); $fields = $table->getFields(false, true); if (!empty($fields)) { /* @var $field NenoContentElementField */ foreach ($fields as $field) { $field->persistTranslations(null, $workingLanguage); } } } } foreach ($files as $fileId) { /* @var $file NenoContentElementLanguageFile */ $file = NenoContentElementLanguageFile::load($fileId); if (!empty($file)) { $file->loadStringsFromFile(); $languageStrings = $file->getLanguageStrings(); if (!empty($languageStrings)) { /* @var $languageString NenoContentElementLanguageString */ foreach ($languageStrings as $languageString) { $languageString->persistTranslations($workingLanguage); } } } } } JFactory::getApplication()->redirect('index.php?option=com_neno&view=groupselements'); }
/** * Move elements * * @return void */ public function move() { $input = JFactory::getApplication()->input; $groupId = $input->getInt('group_id'); /* @var $group NenoContentElementGroup */ $group = NenoContentElementGroup::load($groupId); $tables = $input->get('tables', array(), 'array'); $files = $input->get('files', array(), 'files'); $url = JRoute::_('index.php?option=com_neno&view=groupselements', false); // Ensure that group_id was set if (empty($groupId)) { $this->setMessage(JText::_('COM_NENO_VIEW_MOVELEMENTCONFIRM_ERR_GROUP_REQUIRED'), 'error'); $this->setRedirect($url); $this->redirect(); } // Ensure that there is at least one table or file if (empty($tables) && empty($files)) { $this->setRedirect($url); $this->redirect(); } $msg = ''; // Move tables if (count($tables) > 0) { foreach ($tables as $table_id) { /* @var $table NenoContentElementTable */ $table = NenoContentElementTable::load($table_id, true, true); $table->setGroup($group); $table->persist(); } $msg .= JText::sprintf('COM_NENO_VIEW_MOVELEMENTCONFIRM_X_TABLES_MOVED', count($tables)); } // Move files if (count($files) > 0) { foreach ($files as $file_id) { /* @var $file NenoContentElementLanguageFile */ $file = NenoContentElementLanguageFile::load($file_id); $file->setGroup($group); $file->persist(); } $msg .= JText::sprintf('COM_NENO_VIEW_MOVELEMENTCONFIRM_X_FILES_MOVED', count($files)); } $this->setMessage($msg); $this->setRedirect($url); $this->redirect(); }
/** * Check if a language file has been discovered already * * @param string $languageFileName Language file name * * @return bool */ public static function isLanguageFileAlreadyDiscovered($languageFileName) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('1')->from(NenoContentElementLanguageFile::getDbTable())->where('filename = ' . $db->quote($languageFileName)); $db->setQuery($query); $result = $db->loadResult(); return $result == 1; }
/** * 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; }