public function update($id, $params, $id_entity = -1) { $jsonLayout = $params['layout_json']; unset($params['layout_json']); if (isset($params['url'])) { if (!$this->check_unique_url($params['url'], $id)) { return "Site with such URL is already exists"; } } $this->db->where(array($this->_id_field_name => $id, 'id_entity_publisher' => $id_entity))->update($this->_table_name, $params); ////////////////////////////////////////// // Register layout try { $siteModel = new Sppc_SiteModel(); $site = $siteModel->findObjectById($id); if (is_null($site)) { throw new Exception('Site was not found'); } $siteLayoutModel = new Sppc_Site_LayoutModel(); $siteLayoutModel->updateFromJson($site, $jsonLayout); } catch (Exception $e) { } ////////////////////////////////////////// return ""; }
/** * Создание сайта * * @param array $fields параметры создаваемого сайта * @return string описание ошибки ('' при успешном создании) */ public function _create($fields) { $siteModel = new Sppc_SiteModel(); $site = $siteModel->createRow(); /* @var Sppc_Site $site */ $categoryModel = new Sppc_CategoryModel(); $category = $categoryModel->find(explode(',', $fields['category'])); $site->setUrl(trim($fields['domain'])); $site->setName(trim($fields['title'])); $site->setCreationDate(Zend_Date::now()); $site->setDescription(trim($fields['description'])); $site->setCategories($category); $site->setIdEntityPublisher($this->user_id); $siteStatus = 'active'; if ($this->role != 'admin') { $siteConfirmationRequired = (bool) $this->global_variables->get('SitesOwnershipConfirmationRequired', 0, '0'); $siteAdminApproveRequired = (bool) $this->global_variables->get('ApproveSites', 0, '0'); if ($siteConfirmationRequired) { $siteStatus = 'unapproved'; } else { if ($siteAdminApproveRequired) { $siteStatus = 'pending'; } } } $site->setStatus($siteStatus); if (array_key_exists('id_channel', $fields)) { $channelModel = new Sppc_ChannelModel(); $channel = $channelModel->findObjectById($fields['id_channel']); if (!is_null($channel)) { $site->addChannel($channel); } } try { $site->save(); } catch (Exception $e) { return $e->getMessage(); } $siteLayoutModel = new Sppc_Site_LayoutModel(); $siteLayoutModel->updateFromJson($site, trim($fields['layout_json'])); if (strtolower($fields['thumb_id']) != 'default') { $from = $this->config->item('path_to_images') . 'thumbs/' . $fields['thumb_id'] . '.jpeg'; $to = $this->config->item('path_to_images') . 'thumbs/' . $site->getId() . '.jpeg'; if (file_exists($to)) { unlink($to); } rename($from, $to); } if ($this->role != 'admin' && $siteConfirmationRequired) { redirect($this->role . '/edit_site/create_complete/' . $site->getId()); exit; } return ''; }
public function _save($idSite, $fields) { try { if (isset($fields['layout_json'])) { $siteModel = new Sppc_SiteModel(); $site = $siteModel->findObjectById($idSite); $siteLayoutModel = new Sppc_Site_LayoutModel(); $siteLayoutModel->updateFromJson($site, $fields['layout_json']); } } catch (Exception $e) { $this->_set_notification('There is an error while saving your site data:' . $e->getMessage(), 'error'); return $e->getMessage(); } $this->_set_notification('Site layout was saved', 'notification', true); return ''; }