/** * Action - getlocations * get geographic coordinates * * Access to the action is possible in the following paths: * - /blogmanager/getlocations?user_id=1234&post_id=2345 * * @return void */ public function getlocationsAction() { $request = $this->getRequest(); $post_id = $request->getPost('post_id'); $user_id = $request->getPost('user_id'); $ret = array('post_id' => 0); $post = new Default_Model_DbTable_BlogPost($this->db); if ($post->loadForUser($user_id, $post_id)) { $ret['post_id'] = $post->getId(); $ret['locations'] = array(); foreach ($post->locations as $location) { $location_id = $location->getId(); $details_url = $this->getUrl('details', 'blogmanager') . "?post_id={$post_id}&location_id={$location_id}"; $ret['locations'][] = array('location_id' => $location_id, 'latitude' => $location->latitude, 'longitude' => $location->longitude, 'description' => $location->description, 'content' => $location->content, 'correction' => $location->correction, 'details' => $location->details ? $details_url : ''); } } $this->sendJson($ret); }
/** * Initialization form */ public function init() { parent::init(); //---------------- Форма ---------------- // Указываем action формы $urlAction = $this->getUrl('edit', 'blogmanager'); $urlAction .= '?id=' . $this->post->getId(); $this->setAction($urlAction); //Зададим метод передачи данных $this->setMethod('post'); // Задаем атрибут class для формы $this->setAttrib('class', 'myfrm'); $this->setAttrib('id', 'blogpost-form'); //------------ Добавим краткое название блога -------------- $elTitle = new Zend_Form_Element_Text('title', array('label' => 'Название', 'maxlength' => '255', 'size' => '60', 'required' => true, 'validators' => array(array('StringLength', true, array(0, 255))), 'filters' => array(array('StringTrim'), array('StripTags')))); //Установим название, если блог существует $this->addElement($elTitle); if ($this->post->profile->title) { $this->setDefault('title', $this->post->profile->title); } //---------------- Дата создания записи в блоге ---------------- // Элемент "Дата создания". Элемент содержит нестандартный декоратор - javascript календарь $elDatePost = new Zend_Form_Element_Text('ts_created', array('label' => 'Дата создания', 'maxlength' => '10', 'required' => true, 'validators' => array(array('Date', true, array('locale' => $this->_language))), 'filters' => array('StringTrim'))); // Удаляем все существующие декораторы, назначенные по умолчанию $elDatePost->clearDecorators(); // Назначаем новые, включая наш декоратор Calendar // Это необходимо для того что бы изображение календаря размещалось сразу за полем ввода $elDatePost->addDecorator('ViewHelper')->addDecorator('Calendar')->addDecorator('Errors')->addDecorator('HtmlTag', array('tag' => 'dd'))->addDecorator('Label', array('tag' => 'dt')); $this->addElement($elDatePost); //Установим дату по умолчанию // $tsCreated = $this->post->ts_created; $locale = Default_Plugin_SysBox::getTranslateLocale(); $format = Default_Plugin_SimpleDate::get_format_display_date($locale); $sd = new Default_Plugin_SimpleDate($this->post->ts_created); $this->setDefault('ts_created', $sd->to_display_date($format)); //---------- Добавим элемент описания сообщения в блоге ------------ //$this->addElement('textarea', 'content', array( $elDescription = new Zend_Form_Element_Textarea('ckeditor_description', array('label' => $this->Translate('Краткое описание сообщения') . ':', 'required' => false, 'validators' => array(), 'filters' => array('Sanitize'))); $this->addElement($elDescription); //Установим краткое описание сообщения, если оно существует if ($this->post->profile->description) { $this->setDefault('ckeditor_description', $this->post->profile->description); } //---------- Добавим элемент содержания блога ------------ //$this->addElement('textarea', 'content', array( $elContent = new Zend_Form_Element_Textarea('ckeditor_content', array('label' => $this->Translate('Ваше сообщение') . ':', 'required' => true, 'filters' => array('Sanitize'))); $this->addElement($elContent); //Установим содержания блога, если оно существует if ($this->post->profile->content) { $this->setDefault('ckeditor_content', $this->post->profile->content); } //-------- Добавим кнопки -------------- //Установим значение кнопки сохранить $this->addElement('submit', 'save', array('ignore' => true, 'label' => 'Сохранить')); $this->getElement('save')->setAttrib('class', 'btn btn-primary'); //Перезапишем стандартные декораторы, для размещения двух кнопок рядом $this->getElement('save')->setDecorators(array('ViewHelper')); //Установим значение кнопки закрыть $this->addElement('submit', 'close', array('ignore' => true, 'label' => 'Закрыть')); $this->getElement('close')->setAttrib('class', 'btn'); //Перезапишем стандартные декораторы, для размещения двух кнопок рядом $this->getElement('close')->setDecorators(array('ViewHelper')); //---------------- Группа данные блога ---------------- // Группируем элементы // Группа полей связанных с авторизационными данными $this->addDisplayGroup(array('title', 'ts_created', 'ckeditor_description', 'ckeditor_content', 'save', 'close'), 'blogDataGroup', array('legend' => 'Подробная информация')); }
/** * Action - view * view user post * * Access to the action is possible in the following paths: * router pattern - user/:username/view/:url/* * - /user/user1/view/prosto-fleshka * * @return void */ public function viewAction() { // Определим какую закладку нужно открыть $viewTab = isset($this->_params["view"]) ? $this->_params["view"] : "post"; $url = trim($this->_request->getUserParam('url')); // if no URL was specified, return to the user home page if (strlen($url) == 0) { $urlCustom = $this->getCustomUrl(array('username' => $this->user->username, 'action' => 'index'), 'user'); $this->_redirector->gotoUrl($urlCustom, array('prependBase' => FALSE)); } // try and load the post $post = new Default_Model_DbTable_BlogPost($this->db); $post->loadLivePost($this->user->getId(), $url); // if the post wasn't loaded redirect to postNotFound if (!$post->isSaved()) { $this->_forward('postnotfound'); return; } // Получим дерево комментариев $treeComments = $post->getTreeComments(); // Получим количество комментариев $countComments = $post->getCommentsCount(); // Инициализируем форму добавления комментария $formAddComment = new Default_Form_AddComment($this->user->username, $post->getId()); // build options for the archive breadcrumbs link $archiveOptions = array('username' => $this->user->username, 'year' => date('Y', $post->ts_created), 'month' => date('m', $post->ts_created)); // определим дату $date = new Zend_Date($post->ts_created, 'U'); $dtFormat = $date->get('YYYY MMMM'); $this->_breadcrumbs->addStep($dtFormat, $this->getCustomUrl($archiveOptions, 'archive')); $this->_breadcrumbs->addStep($post->profile->title); // make the post available to the template $this->view->post = $post; $this->view->treeComments = $treeComments; $this->view->countComments = $countComments; $this->view->formAddComment = $formAddComment; $this->view->viewTab = $viewTab; }