Пример #1
0
 public function testimonials($tags = '')
 {
     if (!$tags) {
         $tags = '';
     }
     $tags = trim($tags, ' ');
     $tags = trim($tags, ',');
     // Trim any excess commas off the list
     $tagsArray = explode(',', $tags);
     // Convert the list to an array
     // Now we have an array of testimonial tags - we need to filter for them in the select
     $testimonials = new Datasource_Cms_Testimonials();
     $testimonialsArray = $testimonials->getByTags($tagsArray);
     return $this->view->partialLoop('templates/partials/testimonial.phtml', $testimonialsArray);
 }
 /**
  * Edit an existing site page
  *
  * @return void
  */
 public function editAction()
 {
     $this->view->currentPage = 'pages';
     $siteID = $this->getRequest()->getParam('site');
     if ($siteID == '') {
         $siteID = 1;
     }
     if ($this->getRequest()->isPost()) {
         // Save changes
         $this->_savePage($siteID);
     } else {
         // Edit page
         $pageID = $this->getRequest()->getParam('id');
         $page = new Datasource_Cms_Pages();
         $pageEdit = $page->getByID($pageID);
         $passThrough = $this->_helper->getHelper('FlashMessenger')->getMessages();
         if (count($passThrough) > 0) {
             if (isset($passThrough[0]['saved'])) {
                 if ($passThrough[0]['saved'] == true) {
                     $this->view->saved = true;
                 }
             }
             if (isset($passThrough[0]['errorMessage'])) {
                 $this->view->errorMessage = $passThrough[0]['errorMessage'];
             }
         }
         $this->view->pageContent = $pageEdit['pageContent'];
         $this->view->pageTitle = $pageEdit['pageTitle'];
         $this->view->pageURL = $pageEdit['url'];
         $this->view->pageID = $pageID;
         $this->view->metaKeywords = $pageEdit['keywords'];
         $this->view->metaDescription = $pageEdit['description'];
         $this->view->urlEditable = $pageEdit['urlEditable'] == 1 ? true : false;
         $meta = $page->getMeta($pageID);
         $metaFieldData = $page->getMetaFields($pageID);
         foreach ($metaFieldData as &$metaRow) {
             if (isset($meta[$metaRow['metaName']])) {
                 $metaRow['value'] = $meta[$metaRow['metaName']];
             }
         }
         $metaFieldList = $this->view->partialLoop('partials/edit-page-metafield.phtml', $metaFieldData);
         $this->view->metaFields = $metaFieldList;
         // Load the possible testimonial tags from the database
         $testimonials = new Datasource_Cms_Testimonials();
         $this->view->testimonialTags = $testimonials->getPossibleTags();
         // Load the possible header quote tags from the database
         $quotes = new Datasource_Cms_HeaderQuotes();
         $this->view->quoteTags = $quotes->getPossibleTags();
         $templates = new Datasource_Cms_Page_Template();
         $templateArray = $templates->getAll($siteID);
         foreach ($templateArray as &$template) {
             $template['current'] = $template['id'] == $pageEdit['layoutID'] ? true : false;
         }
         $templateList = $this->view->partialLoop('partials/edit-page-templatefield.phtml', $templateArray);
         $this->view->templateFields = $templateList;
     }
 }
 /**
  * Save a new testimonial, or changes to an existing testimonial. If it's a new entry the function will return the ID for the record
  *
  * @return int
  */
 protected function _saveTestimonial()
 {
     $requiredText = new Zend_Validate();
     $requiredText->addValidator(new Zend_Validate_NotEmpty());
     $tagFilter = new Zend_Filter();
     $tagFilter->addFilter(new Zend_Filter_StringTrim());
     $tagFilter->addFilter(new Zend_Filter_StringTrim(','));
     $filters = array('id' => 'Digits', 'person' => 'StringTrim', 'quote' => 'StringTrim', 'tags' => $tagFilter);
     $validators = array('id' => array('allowEmpty' => true), 'person' => $requiredText, 'quote' => array('allowEmpty' => true), 'tags' => $requiredText);
     $input = new Zend_Filter_Input($filters, $validators, $_POST);
     if ($input->isValid()) {
         $testimonial = new Datasource_Cms_Testimonials();
         // Data is all valid, formatted and sanitized so we can save it in the database
         if (!$input->id) {
             // This is a new testimonial so we need to create a new ID
             $testimonialID = $testimonial->addNew($input->person, $input->quote, $input->tags);
         } else {
             // This is an existing article so we can just update the data
             $testimonial->saveChanges($input->id, $input->person, $input->quote, $input->tags);
             $testimonialID = $input->id;
         }
         // Changes saved - so send them back with a nice success message
         $this->_helper->getHelper('FlashMessenger')->addMessage(array('saved' => true));
         $this->_helper->getHelper('Redirector')->goToUrl('/cms-admin/testimonials/edit?id=' . $testimonialID);
     } else {
         // Invalid data in form
         /*
         print_r($_POST);
         print_r($input->getErrors());
         print_r($input->getInvalid());
         */
     }
 }