Exemple #1
0
 /**
  * Load element from the database
  *
  * @param   mixed $pk            it could be the ID of the element or an array of clauses
  * @param   bool  $loadExtraData Load extra data
  * @param   bool  $loadParent    Load parent
  * @param   bool  $cache         Allows to cache the result
  *
  * @return mixed|array
  */
 public static function load($pk, $loadExtraData = true, $loadParent = false, $cache = true)
 {
     $arguments = func_get_args();
     // Check if the argument is an array
     if (is_array($pk)) {
         $arguments = $pk;
     }
     if ($cache) {
         $cacheId = NenoCache::getCacheId(get_called_class() . '.' . __FUNCTION__, $arguments);
         $data = NenoCache::getCacheData($cacheId);
         if ($data === null) {
             $data = parent::load($pk, $loadExtraData, $loadParent);
             NenoCache::setCacheData($cacheId, $data);
         }
     } else {
         $data = parent::load($pk, $loadExtraData, $loadParent);
     }
     return $data;
 }
Exemple #2
0
 public static function getTranslationMethodsByTableId($tableId)
 {
     $cacheId = NenoCache::getCacheId(__FUNCTION__, func_get_args());
     if (NenoCache::getCacheData($cacheId) === null) {
         /* @var $db NenoDatabaseDriverMysqlx */
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select(array('gtm.lang', 'gtm.translation_method_id'))->from('#__neno_content_element_tables AS t')->innerJoin('#__neno_content_element_groups AS g ON t.group_id = g.id')->innerJoin('#__neno_content_element_groups_x_translation_methods AS gtm ON gtm.group_id = g.id')->where('t.id = ' . $tableId)->order('ordering ASC');
         $db->setQuery($query);
         $translationmethods = $db->loadObjectListMultiIndex('lang');
         NenoCache::setCacheData($cacheId, $translationmethods);
     }
     return NenoCache::getCacheData($cacheId);
 }
Exemple #3
0
 /**
  * Get an object with the amount of words per state
  *
  * @return stdClass
  */
 public function getWordCount()
 {
     if ($this->wordCount === null) {
         $cacheId = NenoCache::getCacheId(get_called_class() . '.' . __FUNCTION__, array($this->getId()));
         $cacheData = NenoCache::getCacheData($cacheId);
         if ($cacheData === 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', 'tr.state'))->from('#__neno_content_element_translations AS tr')->where(array('tr.content_type = ' . $db->quote('db_string'), 'tr.language LIKE ' . $db->quote($workingLanguage), 'tr.content_id = ' . $this->getId()))->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'];
                         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;
                 }
             }
             $this->wordCount->total = $this->wordCount->untranslated + $this->wordCount->queued + $this->wordCount->changed + $this->wordCount->translated;
             $cacheData = $this->wordCount;
             NenoCache::setCacheData($cacheId, $cacheData);
         }
         $this->wordCount = $cacheData;
     }
     return $this->wordCount;
 }
Exemple #4
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;
 }