/** * Return info about specified dimension * * @param int $id * @return array */ protected function getDimension($id) { $feEngine = $this->config->item('dimensions_frontend_engine'); $feOptions = $this->config->item('dimensions_frontend'); $beEngine = $this->config->item('dimensions_backend_engine'); $beOptions = $this->config->item('dimensions_backend'); if (isset($beOptions['cache_dir']) && !file_exists($beOptions['cache_dir'])) { mkdir($beOptions['cache_dir']); chmod($beOptions['cache_dir'], 0777); } $cache = Zend_Cache::factory($feEngine, $beEngine, $feOptions, $beOptions); if (false === ($dimension = $cache->load('dimension_' . $id))) { $dimensionModel = new Sppc_DimensionModel(); $dimensionObj = $dimensionModel->findObjectById($id); if (!is_null($dimensionObj)) { $dimension = $dimensionObj->toArray(); $cache->save($dimension, 'dimension_' . $id); } else { $dimension = array('id_dimension' => 0, 'title_size' => 35, 'text_size' => 75, 'url_size' => 35, 'max_ad_slots' => 1, 'width' => 0, 'height' => 0, 'rows_count' => 1, 'columns_count' => 1, 'type' => 'standart'); } } return $dimension; }
/** * Создание сайта * * @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; }