Пример #1
0
 /**
  * Refresh NenoContentElementGroup data
  *
  * @param   string|null $language Language to update. Null for none
  *
  * @return void
  */
 public function refresh($language = null)
 {
     $tables = NenoHelper::getComponentTables($this);
     if (!$this->isOtherGroup()) {
         $elementName = NenoHelper::getElementNameByGroupId($this->id);
         $languageFiles = NenoHelper::getLanguageFiles($elementName);
     }
     // If there are tables, let's assign to the group
     if (!empty($tables)) {
         $this->setTables($tables);
     }
     // If there are language strings, let's assign to the group
     if (!empty($languageFiles)) {
         $this->setLanguageFiles($languageFiles);
     }
     $this->sync();
     // If there are tables or language strings assigned, save the group
     if (!empty($tables) || !empty($languageFiles)) {
         $this->persist();
     }
     // Once the structure is saved, let's go through the translations.
     if (!empty($tables)) {
         /* @var $table NenoContentElementTable */
         foreach ($tables as $table) {
             if ($table->isTranslate()) {
                 $fields = $table->getFields(false, true);
                 /* @var $field NenoContentElementField */
                 foreach ($fields as $field) {
                     $field->persistTranslations(null, $language);
                 }
             }
         }
     }
     if (!empty($languageFiles)) {
         /* @var $languageFile NenoContentElementLanguageFile */
         foreach ($languageFiles as $languageFile) {
             if ($languageFile->loadStringsFromFile()) {
                 $languageStrings = $languageFile->getLanguageStrings();
                 /* @var $languageString NenoContentElementLanguageString */
                 foreach ($languageStrings as $languageString) {
                     $languageString->persistTranslations($language);
                 }
             }
         }
     }
 }