예제 #1
0
파일: scan.php 프로젝트: javigomez/neno
 /**
  * Execute the task
  *
  * @param   array $taskData Task data
  *
  * @return bool True on success, false otherwise
  */
 public function run($taskData)
 {
     /* @var $group NenoContentElementGroup */
     $group = NenoContentElementGroup::load(array('_order' => array('id' => 'asc'), '_limit' => 1, '_offset' => $taskData['group'] - 1));
     $group->refresh();
     NenoTaskMonitor::addTask('scan', array('group' => $taskData['group'] + 1));
 }
예제 #2
0
파일: file.php 프로젝트: andresmaeso/neno
 /**
  * Constructor
  *
  * @param   mixed $data          File data
  * @param   bool  $loadExtraData Load extra data flag
  * @param   bool  $loadParent    Load parent flag
  */
 public function __construct($data, $loadExtraData = true, $loadParent = false)
 {
     parent::__construct($data);
     $data = (array) $data;
     if (!empty($this->filename)) {
         $languageFileData = explode('.', $this->filename);
         $this->language = $languageFileData[0];
     }
     if (!empty($data['groupId'])) {
         $this->group = NenoContentElementGroup::load($data['groupId'], $loadExtraData);
     }
     if ($loadExtraData && !$this->isNew()) {
         $this->loadExtraData();
     }
 }
예제 #3
0
파일: neno.php 프로젝트: javigomez/neno
 /**
  * Event triggered before uninstall an extension
  *
  * @param   int $extensionId Extension ID
  *
  * @return void
  */
 public function onExtensionBeforeUninstall($extensionId)
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('group_id')->from('#__neno_content_element_groups_x_extensions')->where('extension_id = ' . (int) $extensionId);
     $db->setQuery($query);
     $groupId = $db->loadResult();
     if (!empty($groupId)) {
         /* @var $group NenoContentElementGroup */
         $group = NenoContentElementGroup::load($groupId);
         if (!empty($group)) {
             $group->remove();
         }
     }
 }
예제 #4
0
파일: table.php 프로젝트: andresmaeso/neno
 /**
  * {@inheritdoc}
  *
  * @param   mixed $data          Table data
  * @param   bool  $loadExtraData Load Extra data flag
  * @param   bool  $loadParent    Load parent flag
  */
 public function __construct($data, $loadExtraData = true, $loadParent = false)
 {
     parent::__construct($data);
     $data = (array) $data;
     // Make sure the name of the table is properly formatted.
     $this->tableName = NenoHelper::unifyTableName($this->tableName);
     $this->primaryKey = is_array($this->primaryKey) ? json_encode($this->primaryKey) : json_decode($this->primaryKey);
     if (!empty($data['groupId']) && $loadParent) {
         $this->group = NenoContentElementGroup::load($data['groupId'], $loadExtraData);
     }
     // Init the field list
     $this->fields = null;
     if (!$this->isNew()) {
         $this->getFields($loadExtraData);
         if ($loadExtraData) {
             $this->getWordCount();
             $this->getRecordCount();
         }
     }
 }
예제 #5
0
파일: neno.php 프로젝트: andresmaeso/neno
 /**
  * This event discover/sync tables
  *
  * @param string $tableName Table name
  *
  * @return void
  */
 public function onDatabaseStructure($tableName)
 {
     $db = JFactory::getDbo();
     // Unify table name
     $tableName = str_replace($db->getPrefix(), '#__', $tableName);
     /* @var $table NenoContentElementTable */
     $table = NenoContentElementTable::load(array('table_name' => $tableName));
     if (empty($table)) {
         $otherGroup = NenoContentElementGroup::load(array('other_group' => 1));
         $table = NenoHelper::createTableInstance($tableName, $otherGroup);
         $table->persist();
     } else {
         $table->sync();
     }
 }
예제 #6
0
파일: strings.php 프로젝트: javigomez/neno
 /**
  * Load elements using AJAX
  *
  * @return void
  *
  * @throws Exception
  */
 public function getElements()
 {
     $input = JFactory::getApplication()->input;
     $groupId = $input->getInt('group_id');
     if (!empty($groupId)) {
         /* @var $group NenoContentElementGroup */
         $group = NenoContentElementGroup::load($groupId);
         $tables = $group->getTables(false, false, true);
         $files = $group->getLanguageFiles();
         $displayData = array();
         /* @var $model NenoModelStrings */
         $model = $this->getModel();
         $displayData['tables'] = NenoHelper::convertNenoObjectListToJObjectList($tables);
         //Remove fields marked as Don't translate
         foreach ($displayData['tables'] as $table) {
             foreach ($table->fields as $key => $field) {
                 if (!$field->translate) {
                     unset($table->fields[$key]);
                 }
             }
         }
         $displayData['files'] = NenoHelper::convertNenoObjectListToJObjectList($files);
         $displayData['state'] = $model->getState();
         $tablesHTML = JLayoutHelper::render('multiselecttables', $displayData, JPATH_NENO_LAYOUTS);
         echo $tablesHTML;
     }
     JFactory::getApplication()->close();
 }
예제 #7
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;
 }
예제 #8
0
 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');
 }
예제 #9
0
 /**
  * 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();
 }
예제 #10
0
파일: helper.php 프로젝트: andresmaeso/neno
 /**
  * Discover extension
  *
  * @param   array $extension Extension data
  *
  * @return bool
  */
 public static function discoverExtension(array $extension)
 {
     // Check if this extension has been discovered already
     $groupId = self::isExtensionAlreadyDiscovered($extension['extension_id']);
     if ($groupId !== false) {
         $group = NenoContentElementGroup::load($groupId);
     } else {
         $group = new NenoContentElementGroup(array('group_name' => $extension['name']));
     }
     $group->addExtension($extension['extension_id']);
     $extensionName = self::getExtensionName($extension);
     $languageFiles = self::getLanguageFiles($extensionName);
     $tables = self::getComponentTables($group, $extensionName);
     $group->setAssignedTranslationMethods(self::getTranslationMethodsForLanguages());
     // If the group contains tables and/or language strings, let's save it
     if (!empty($tables) || !empty($languageFiles)) {
         $group->setLanguageFiles($languageFiles)->setTables($tables)->persist();
     } else {
         $group->persist();
     }
     return true;
 }
예제 #11
0
 /**
  * {@inheritdoc}
  *
  * @param   mixed $pk Primary key
  *
  * @return bool
  */
 public function delete($pk = null)
 {
     /* @var $group NenoContentElementGroup */
     $group = NenoContentElementGroup::load($pk);
     return $group->remove();
 }
예제 #12
0
 /**
  * Load item
  *
  * @param null|mixed $pk Pk data
  *
  * @return JObject
  */
 public function getItem($pk = null)
 {
     $item = parent::getItem();
     if (!empty($item->id)) {
         /* @var $group NenoContentElementGroup */
         $group = NenoContentElementGroup::load($item->id);
         $item = $group->prepareDataForView();
     }
     return $item;
 }
예제 #13
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;
 }
예제 #14
0
 public function getTranslationMethodSelector()
 {
     $app = JFactory::getApplication();
     $input = $this->input;
     $n = $input->getInt('n', 0);
     $groupId = $input->getInt('group_id');
     $selectedMethods = $input->get('selected_methods', array(), 'ARRAY');
     $translationMethods = NenoHelper::loadTranslationMethods();
     if (!empty($groupId)) {
         $group = NenoContentElementGroup::load($groupId)->prepareDataForView();
     } else {
         $group = new stdClass();
         $group->assigned_translation_methods = array();
     }
     // Ensure that we know what was selected for the previous selector
     if ($n > 0 && !isset($selectedMethods[$n - 1]) || $n > 0 && $selectedMethods[$n - 1] == 0) {
         JFactory::getApplication()->close();
     }
     // As a safety measure prevent more than 5 selectors and always allow only one more selector than already selected
     if ($n > 4 || $n > count($selectedMethods) + 1) {
         $app->close();
     }
     // Reduce the translation methods offered depending on the parents
     if ($n > 0 && !empty($selectedMethods)) {
         $parentMethod = $selectedMethods[$n - 1];
         $acceptableFollowUpMethodIds = $translationMethods[$parentMethod]->acceptable_follow_up_method_ids;
         $acceptableFollowUpMethods = explode(',', $acceptableFollowUpMethodIds);
         foreach ($translationMethods as $k => $translationMethod) {
             if (!in_array($k, $acceptableFollowUpMethods)) {
                 unset($translationMethods[$k]);
             }
         }
     }
     // If there are no translation methods left then return nothing
     if (!count($translationMethods)) {
         $app->close();
     }
     // Prepare display data
     $displayData = array();
     $displayData['translation_methods'] = $translationMethods;
     $displayData['assigned_translation_methods'] = $group->assigned_translation_methods;
     $displayData['n'] = $n;
     $selectorHTML = JLayoutHelper::render('translationmethodselector', $displayData, JPATH_NENO_LAYOUTS);
     echo $selectorHTML;
     $app->close();
 }