/** * Return children of specified category * * @retunr string Children data in JSON format */ public function get_children() { header('Content-Type: application/json'); try { $categoryId = $this->input->get('id'); if (false === $categoryId) { throw new Exception('Parent category not specified'); } $categoryModel = new Sppc_CategoryModel(); $category = $categoryModel->findObjectById($categoryId); if (is_null($category)) { throw new Exception('Specified category not found'); } $children = $category->getChildCategories(); $response = array(); foreach ($children as $child) { $childCategory = array('attributes' => array('id' => 'category_' . $child->getId()), 'data' => $child->getName()); if ($child->hasChildren()) { $childCategory['state'] = 'closed'; } $response[] = $childCategory; } echo json_encode($response); } catch (Exception $e) { echo json_encode(array()); } }
/** * Отправка описания выбранной категории в формате JSON. * */ public function ajax_get_category_details() { $categoryDetails = new stdClass(); $categoryDetails->id_category = 0; $categoryDetails->sites_in_cat = 0; $categoryDetails->sites_in_cat_and_subcat = 0; try { $categoryId = $this->input->post('id_category'); if (false === $categoryId) { throw new Sppc_Exception('Category not specified'); } $categoryModel = new Sppc_CategoryModel(); $category = $categoryModel->findObjectById($categoryId); if (is_null($category)) { throw new Sppc_Exception('Specified category not found'); } $categoryDetails->id_category = $category->getId(); $categoryDetails->description = $category->getDescription(); $siteModel = new Sppc_SiteModel(); $searchFilter = new Sppc_Site_SearchFilter(); $searchFilter->setHasCpc(true)->setCategories($category); $categoryDetails->sites_in_cat = $siteModel->getCount($searchFilter); $categories = array($category); $childs = $category->getChildCategories(true); $categories = array_merge($categories, $childs); $searchFilter->setCategories($categories); $categoryDetails->sites_in_cat_and_subcat = $siteModel->getCount($searchFilter); echo json_encode(array('message' => 'OK', 'category_details' => $categoryDetails)); } catch (Exception $e) { echo json_encode(array('message' => $e->getMessage(), 'category_details' => $categoryDetails)); } }
/** * Создание сайта * * @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; }