Beispiel #1
0
 /**
  * {@inheritdoc}
  *
  * @param   array $data Data to save
  *
  * @return bool
  *
  * @throws Exception
  */
 public function save($data)
 {
     // If groups data has been saved, let's assign translation method
     if (parent::save($data)) {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $workingLanguage = NenoHelper::getWorkingLanguage();
         $groupId = (int) $this->getState($this->getName() . '.id');
         $query->delete('#__neno_content_element_groups_x_translation_methods')->where(array('group_id = ' . $groupId));
         $languages = array($workingLanguage);
         if (!empty($data['languages'])) {
             $languages = array_merge($data['languages'], $languages);
         }
         $query->where('lang IN (' . implode(',', $db->quote($languages)) . ')');
         $db->setQuery($query);
         $db->execute();
         $query->clear()->insert('#__neno_content_element_groups_x_translation_methods')->columns(array('group_id', 'lang', 'translation_method_id', 'ordering'));
         $insert = false;
         if (!empty($data['translation_methods'])) {
             $ordering = 1;
             foreach ($data['translation_methods'] as $translationMethodId) {
                 if (!empty($translationMethodId)) {
                     $insert = true;
                     foreach ($languages as $language) {
                         $query->values($groupId . ',' . $db->quote($language) . ',' . $db->quote($translationMethodId) . ', ' . $ordering);
                     }
                     $ordering++;
                 }
             }
         }
         if ($insert) {
             $db->setQuery($query);
             $db->execute();
         }
         NenoHelperBackend::consolidateTranslationMethods($groupId, empty($data['translation_methods']) || $data['translation_methods'][0] == 0);
         return true;
     }
     return false;
 }