/** * Создание сайта * * @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 ''; }
/** * Создание сайта * * @param array $fields параметры создаваемого канала * @return string описание ошибки ('' при успешном создании) */ public function _create($fields) { try { if ('' == $fields['format']) { throw new Sppc_Exception('Channel dimension is not selected'); } // check channel ad type $channelAdTypes = array(); if ($fields['ad_type_text']) { $channelAdTypes[] = Sppc_Channel::AD_TYPE_TEXT; } if ($fields['ad_type_image']) { $channelAdTypes[] = Sppc_Channel::AD_TYPE_IMAGE; } if (count($channelAdTypes) == 0) { throw new Sppc_Exception('At least one ad type must be selected'); } // channel ad sources if ($this->role == 'admin') { $channelAdSources = array(); if ($fields['ad_sources_advertisers'] == true) { $channelAdSources[] = Sppc_Channel::AD_SOURCE_ADVERTISERS; } if ($fields['ad_sources_xml_feeds'] == true) { $channelAdSources[] = Sppc_Channel::AD_SOURCE_XMLFEEDS; } } else { $channelAdSources = array(Sppc_Channel::AD_SOURCE_ADVERTISERS, Sppc_Channel::AD_SOURCE_XMLFEEDS); } if (count($channelAdSources) == 0) { throw new Sppc_Exception('At least one ad source must be selected'); } if (empty($fields['channel_type'])) { $fields['channel_type'] = 'contextual'; } $parentSite = null; if (isset($fields['id_site'])) { $siteModel = new Sppc_SiteModel(); $parentSite = $siteModel->findObjectById($fields['id_site']); } $dimensionModel = new Sppc_DimensionModel(); $dimension = $dimensionModel->findObjectById($fields['format']); $channelModel = new Sppc_ChannelModel(); $channel = $channelModel->createRow(); $channel->setName(trim($fields['name'])); $channel->setDescription(trim($fields['description'])); if ($fields['category'] != $parentSite->getCategory()) { $categoryModel = new Sppc_CategoryModel(); $categories = $categoryModel->find(explode(',', $fields['category'])); $channel->setCategories($categories); } $channel->setDimension($dimension); $channel->setAdTypes($channelAdTypes); $channel->setAdSettings($fields['ad_settings']); if ($fields['ad_settings'] == 'blank_color') { $channel->setBlankColor(str_replace('#', '', $fields['blank_color'])); } $channel->setChannelType($fields['channel_type']); $channel->setAdSources($channelAdSources); if (!is_null($parentSite)) { $channel->setParentSite($parentSite); $channel->addSite($parentSite); } $channel->save(); $tagModel = new Sppc_TagModel(); if ($fields["ad_settings"] == 'tag') { $tag = $tagModel->createRow($channel, $fields["tag_code"]); } else { $tag = $tagModel->createRow($channel, ''); } $tag->save(); // Сохраняем айдишник в сессию $this->session->set_userdata(get_class($this) . '_id_channel', $channel->getId()); } catch (Exception $e) { return __($e->getMessage()); } return false; }