/** * @param integer $themeId * @param array $values */ public function saveThemeControls($themeId, $values) { $controls = $this->findThemeControls($themeId); $namedControls = array(); foreach ($controls as $value) { $namedControls[$value['key']] = $value; } foreach ($values as $key => $value) { if (!array_key_exists($key, $namedControls)) { continue; } if (is_array($value)) { if (empty($value) || $namedControls[$key]['type'] === 'image' && (int) $value['error'] > 0) { continue; } } elseif (trim($value) === trim($namedControls[$key]['defaultValue']) || trim($value) === 'default') { $this->themeControlValueDao->deleteByTcNameAndThemeId($namedControls[$key]['key'], $themeId); continue; } $obj = $this->themeControlValueDao->findByTcNameAndThemeId($namedControls[$key]['key'], $themeId); if ($namedControls[$key]['type'] === 'image' && (int) $value['error'] === 0) { try { list($width, $height) = getimagesize($value['tmp_name']); $image = $this->addImage($value); $value = 'url(' . OW::getStorage()->getFileUrl($this->getUserfileImagesDir() . $image->getFilename()) . ')'; //temp solution for assigning theme img data in master pages $curentValue = json_decode(OW::getConfig()->getValue('base', 'master_page_theme_info'), true); $curentValue[$themeId][$namedControls[$key]['key']] = array('src' => OW::getStorage()->getFileUrl($this->getUserfileImagesDir() . $image->getFilename()), 'width' => $width, 'height' => $height); OW::getConfig()->saveConfig('base', 'master_page_theme_info', json_encode($curentValue)); } catch (Exception $e) { continue; } } if ($obj === null) { $obj = new BOL_ThemeControlValue(); $obj->setThemeControlKey($namedControls[$key]['key']); } $obj->setValue(trim($value)); $obj->setThemeId($themeId); $this->themeControlValueDao->save($obj); } }
/** * @param integer $themeId * @param array $values */ public function saveThemeControls($themeId, $values) { $controls = $this->findThemeControls($themeId); $namedControls = array(); foreach ($controls as $value) { $namedControls[$value["key"]] = $value; } foreach ($values as $key => $value) { if (!array_key_exists($key, $namedControls) || is_array($value) && empty($value)) { continue; } if (is_string($value) && in_array(trim($value), array("default", trim($namedControls[$key]["defaultValue"])))) { $this->themeControlValueDao->deleteByTcNameAndThemeId($namedControls[$key]["key"], $themeId); continue; } $obj = $this->themeControlValueDao->findByTcNameAndThemeId($namedControls[$key]["key"], $themeId); if ($namedControls[$key]["type"] == "image") { list($width, $height) = getimagesize($value["tmp_name"]); $image = $this->addImage($value); if ($image === null) { continue; } $value = "url(" . OW::getStorage()->getFileUrl($this->getUserfileImagesDir() . $image->getFilename()) . ")"; //TODO remove hotfix temp solution for assigning theme img data in master pages $curentValue = json_decode(OW::getConfig()->getValue("base", "master_page_theme_info"), true); $curentValue[$themeId][$namedControls[$key]["key"]] = array("src" => OW::getStorage()->getFileUrl($this->getUserfileImagesDir() . $image->getFilename()), "width" => $width, "height" => $height); OW::getConfig()->saveConfig("base", "master_page_theme_info", json_encode($curentValue)); } if ($obj === null) { $obj = new BOL_ThemeControlValue(); $obj->setThemeControlKey($namedControls[$key]["key"]); } $obj->setValue(trim($value)); $obj->setThemeId($themeId); $this->themeControlValueDao->save($obj); } }