Beispiel #1
0
 /**
  * Get an object with the amount of words per state
  *
  * @return stdClass
  */
 public function getWordCount()
 {
     if ($this->wordCount === null) {
         $this->wordCount = new stdClass();
         $this->wordCount->total = 0;
         $this->wordCount->untranslated = 0;
         $this->wordCount->translated = 0;
         $this->wordCount->queued = 0;
         $this->wordCount->changed = 0;
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $workingLanguage = NenoHelper::getWorkingLanguage();
         $query->select(array('SUM(word_counter) AS counter', 't.state'))->from($db->quoteName(NenoContentElementLanguageString::getDbTable()) . ' AS ls')->innerJoin($db->quoteName(NenoContentElementLanguageFile::getDbTable()) . ' AS lf ON ls.languagefile_id = lf.id')->innerJoin($db->quoteName(NenoContentElementTranslation::getDbTable()) . ' AS t ON t.content_id = ls.id AND t.content_type = ' . $db->quote('lang_string') . ' AND t.language LIKE ' . $db->quote($workingLanguage))->where('lf.group_id = ' . $this->getId())->group('t.state');
         $db->setQuery($query);
         $statistics = $db->loadAssocList('state');
         // Assign the statistics
         foreach ($statistics as $state => $data) {
             switch ($state) {
                 case NenoContentElementTranslation::NOT_TRANSLATED_STATE:
                     $this->wordCount->untranslated = (int) $data['counter'];
                     break;
                 case NenoContentElementTranslation::QUEUED_FOR_BEING_TRANSLATED_STATE:
                     $this->wordCount->queued = (int) $data['counter'];
                     break;
                 case NenoContentElementTranslation::SOURCE_CHANGED_STATE:
                     $this->wordCount->changed = (int) $data['counter'];
                     break;
                 case NenoContentElementTranslation::TRANSLATED_STATE:
                     $this->wordCount->translated = (int) $data['counter'];
                     break;
             }
         }
         $query->clear()->select(array('SUM(word_counter) AS counter', 'tr.state'))->from('#__neno_content_element_tables AS t')->innerJoin('#__neno_content_element_fields AS f ON f.table_id = t.id')->innerJoin('#__neno_content_element_translations AS tr  ON tr.content_id = f.id AND tr.content_type = ' . $db->quote('db_string') . ' AND tr.language LIKE ' . $db->quote($workingLanguage))->where(array('t.group_id = ' . $this->getId(), 't.translate IN (1,2)', 'f.translate = 1'))->group('tr.state');
         $db->setQuery($query);
         $statistics = $db->loadAssocList('state');
         // Assign the statistics
         foreach ($statistics as $state => $data) {
             switch ($state) {
                 case NenoContentElementTranslation::NOT_TRANSLATED_STATE:
                     $this->wordCount->untranslated = (int) $data['counter'] + $this->wordCount->untranslated;
                     break;
                 case NenoContentElementTranslation::QUEUED_FOR_BEING_TRANSLATED_STATE:
                     $this->wordCount->queued = (int) $data['counter'] + $this->wordCount->queued;
                     break;
                 case NenoContentElementTranslation::SOURCE_CHANGED_STATE:
                     $this->wordCount->changed = (int) $data['counter'] + $this->wordCount->changed;
                     break;
                 case NenoContentElementTranslation::TRANSLATED_STATE:
                     $this->wordCount->translated = (int) $data['counter'] + $this->wordCount->translated;
                     break;
             }
         }
         $this->wordCount->total = $this->wordCount->untranslated + $this->wordCount->queued + $this->wordCount->changed + $this->wordCount->translated;
     }
     return $this->wordCount;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  *
  * @param   mixed $data          Element 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 = new JObject($data);
     if ($data->get('content') !== null) {
         $this->element = $data->get('content');
     } elseif ($loadParent) {
         $contentId = $data->get('content_id') === null ? $data->get('contentId') : $data->get('content_id');
         if (!empty($contentId)) {
             // If it's a language string, let's create a NenoContentElementLangstring
             if ($this->contentType == self::LANG_STRING) {
                 $this->element = NenoContentElementLanguageString::load($contentId, $loadExtraData, $loadParent);
             } else {
                 $this->element = NenoContentElementField::load($contentId, $loadExtraData, $loadParent);
             }
         }
     }
     $this->charactersCounter = mb_strlen($this->getString());
     if (!$this->isNew()) {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('tm.*')->from('#__neno_translation_methods AS tm')->innerJoin('#__neno_content_element_translation_x_translation_methods AS tr_x_tm ON tr_x_tm.translation_method_id = tm.id')->where('tr_x_tm.translation_id = ' . (int) $this->id);
         $db->setQuery($query);
         $this->translationMethods = $db->loadObjectList();
     }
 }
Beispiel #3
0
 /**
  * Load Original from a translation
  *
  * @param   int $translationId   Translation Id
  * @param   int $translationType Translation Type (DB Content or Language String)
  *
  * @return string|null
  */
 public static function getTranslationOriginalText($translationId, $translationType)
 {
     $cacheId = NenoCache::getCacheId(__FUNCTION__, func_get_args());
     $cachedData = NenoCache::getCacheData($cacheId);
     if ($cachedData === null) {
         /* @var $db NenoDatabaseDriverMysqlX */
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $translationElementId = self::getContentIdByTranslationId($translationId);
         // If the translation comes from database content, let's load it
         if ($translationType == NenoContentElementTranslation::DB_STRING) {
             list($fieldName, $tableName) = self::getOriginalText($translationElementId);
             $whereValues = self::getWhereValuesForTranslation($translationId);
             $string = self::getFieldContentFromTranslationData($fieldName, $tableName, $whereValues);
         } else {
             $query->clear()->select('string')->from(NenoContentElementLanguageString::getDbTable())->where('id = ' . $translationElementId);
             $db->setQuery($query);
             $string = $db->loadResult();
         }
         NenoCache::setCacheData($cacheId, $string);
         $cachedData = $string;
     }
     return $cachedData;
 }
Beispiel #4
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;
 }
Beispiel #5
0
 /**
  * Discover the element
  *
  * @return bool True on success
  */
 public function discoverElement()
 {
     NenoHelper::setSetupState(JText::sprintf('COM_NENO_INSTALLATION_MESSAGE_PARSING_GROUP_TABLE', $this->group->getGroupName(), $this->getFilename()), 2);
     // Check if there are children not discovered
     $languageString = NenoContentElementLanguageString::load(array('discovered' => 0, '_limit' => 1, 'languagefile_id' => $this->id));
     if (empty($languageString)) {
         $this->setDiscovered(true)->persist();
     } else {
         NenoSettings::set('installation_level', '2.2');
         NenoSettings::set('discovering_element_1.2', $this->id);
     }
 }
Beispiel #6
0
 /**
  * Load Original from a translation
  *
  * @param   int $translationId   Translation Id
  * @param   int $translationType Translation Type (DB Content or Language String)
  *
  * @return string|null
  */
 public static function getTranslationOriginalText($translationId, $translationType)
 {
     $cacheId = NenoCache::getCacheId(__FUNCTION__, func_get_args());
     $cachedData = NenoCache::getCacheData($cacheId);
     if ($cachedData === null) {
         /* @var $db NenoDatabaseDriverMysqlX */
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $string = null;
         $query->select('content_id')->from('#__neno_content_element_translations')->where('id = ' . $translationId);
         $db->setQuery($query);
         $translationElementId = (int) $db->loadResult();
         // If the translation comes from database content, let's load it
         if ($translationType == NenoContentElementTranslation::DB_STRING) {
             $queryCacheId = NenoCache::getCacheId('originalTextQuery', array($translationElementId));
             $queryCacheData = NenoCache::getCacheData($queryCacheId);
             if ($queryCacheData === null) {
                 $query->clear()->select(array('f.field_name', 't.table_name'))->from('`#__neno_content_element_fields` AS f')->innerJoin('`#__neno_content_element_tables` AS t ON f.table_id = t.id')->where('f.id = ' . $translationElementId);
                 $db->setQuery($query);
                 $row = $db->loadRow();
                 NenoCache::setCacheData($queryCacheId, $row);
                 $queryCacheData = $row;
             }
             list($fieldName, $tableName) = $queryCacheData;
             $query->clear()->select(array('f.field_name', 'ft.value'))->from('`#__neno_content_element_fields_x_translations` AS ft')->innerJoin('`#__neno_content_element_fields` AS f ON f.id = ft.field_id')->where('ft.translation_id = ' . $translationId);
             $db->setQuery($query);
             $whereValues = $db->loadAssocList('field_name');
             $query->clear()->select($db->quoteName($fieldName))->from($tableName);
             foreach ($whereValues as $whereField => $where) {
                 $query->where($db->quoteName($whereField) . ' = ' . $db->quote($where['value']));
             }
             $db->setQuery($query);
             $string = $db->loadResult();
         } else {
             $query->clear()->select('string')->from(NenoContentElementLanguageString::getDbTable())->where('id = ' . $translationElementId);
             $db->setQuery($query);
             $string = $db->loadResult();
         }
         NenoCache::setCacheData($cacheId, $string);
         $cachedData = $string;
     }
     return $cachedData;
 }