Webylon 3.1 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • FaqAdmin
  • FaqHolder
  • FaqHolder_Controller
  • FaqQuestion
  • FaqSection
  • FaqSection_Controller
  1 <?php
  2 /**
  3  * @package faq
  4  * @class FaqHolder - страница Вопрос-ответ
  5  *
  6  * @author menedem
  7  */
  8 class FaqHolder extends Page {
  9     static $icon = "faq/img/faq";
 10     
 11     static $allowed_children = array( 'FaqSection' );
 12     
 13     static $db = array(
 14         'QuestionsPerPage'=>'Int',
 15         'LastCount'=>'Int',
 16         'ShowQuestionsForm'=>'Boolean',
 17         'ShowSpamProtection'=>'Boolean',
 18         'Email'=>'Varchar(100)',
 19     );
 20     
 21     static $has_many = array(
 22         'Questions'=>'FaqQuestion'
 23     );
 24 
 25     static $defaults = array (
 26         'QuestionsPerPage' => 20,
 27         'LastCount' => 5,
 28         'ShowQuestionsForm' => 1,
 29         'ShowSpamProtection'=> 1,
 30         'AutoChild' => 0,
 31     );
 32 
 33     function getCMSFields() {
 34         $fields = parent::getCMSFields();
 35         
 36         $fields->addFieldToTab('Root.Content.Main', new NumericField('QuestionsPerPage', $this->fieldLabel('QuestionsPerPage')), 'Content');
 37         $fields->addFieldToTab('Root.Content.Main', new NumericField('LastCount', $this->fieldLabel('LastCount')), 'Content');
 38         $fields->addFieldToTab('Root.Content.Main', new CheckBoxField('ShowQuestionsForm', $this->fieldLabel('ShowQuestionsForm')), 'Content');     
 39         $fields->addFieldToTab('Root.Content.Main', new CheckBoxField('ShowSpamProtection', $this->fieldLabel('ShowSpamProtection')), 'Content');   
 40         $fields->addFieldToTab('Root.Content.Main', new EmailField('Email', sprintf('%s (%s)', $this->fieldLabel('Email'), Email::getAdminEmail())), 'Content');
 41         $fields->removeFieldFromTab('Root.Behaviour','AutoChild');
 42 
 43         return $fields;
 44     }
 45 
 46     /**
 47      * Возвращает емайл отвественного за раздел вопрос-ответ
 48      * Если емайл в разделе не указан - использует емайл администратора сайта
 49      * 
 50      * @return string
 51      */
 52     function adminEmail() {
 53         return ($this->Email) ? $this->Email : Email::getAdminEmail();
 54     }
 55 }
 56 /**
 57  * @package faq
 58  * @class FaqHolder_Controller - контроллер страницы Вопрос-ответ
 59  */
 60 class FaqHolder_Controller extends Page_Controller {
 61     
 62     
 63     function index() {
 64         if ($this->Children()->Count() == 1) {//Если в разделе только одна рубрика - то сразу в нее переходим
 65             $this->RedirectToFirstChild();
 66         } else {
 67             return parent::defaultAction('index');
 68         }
 69     }
 70     
 71     /**
 72      * возвращает форму для задания вопроса
 73      * если указано что ее нужно отображать
 74      * форму можно изменить с помощью расширений - метод updateQuestionForm(&$form)
 75      * 
 76      * @return Form
 77      */
 78     function QuestionForm() {       
 79         if (!$this->ShowQuestionsForm) {
 80             return false;
 81         }       
 82         $sections = $this->Children();      
 83         if (!$sections->Count()) {          
 84             return false;
 85         }
 86         $question = singleton('FaqQuestion');
 87         $reqFields = $question->getReqFields();
 88         $fields = $question->getQuestionFormFields($sections);          
 89         $actions = new FieldSet(new FormAction('addQuestion',_t('FaqHolder.SendQuestion','Отправить')));
 90         $form = new Form($this, "QuestionForm", $fields, $actions, new RequiredFields($reqFields));
 91         if ($this->ShowSpamProtection && class_exists('SpamProtectorManager')) {            
 92             SpamProtectorManager::update_form($form, null, array(), _t('FaqHolder.Captcha', 'Captcha')); //
 93         }
 94         $this->extend('updateQuestionForm', $form);
 95         return $form;
 96     }
 97     
 98     /**
 99      * Сохраняет вопрос из формы + отсылает email задавшему вопрос и администратору для ответа
100      * значения объекта FaqQuestion можно изменить с помощью расширений - метод onBeforeAddQuestion(&$question)
101      * 
102      * @return Page
103      */
104     function addQuestion($data, $form) {
105         $faqQuestion = Object::create("FaqQuestion");
106         $form->saveInto($faqQuestion);
107         $this->extend('onBeforeAddQuestion', $faqQuestion, $data, $form);
108         $faqQuestion->write();  
109         
110         $adminEmail = $faqQuestion->Section()->adminEmail();
111         
112         $email = new Email(Email::getAdminEmail(), $adminEmail, _t('FaqHolder.SubjectNewQuestion', 'New Question added'));
113         $email->setTemplate('EmailQuestionAdmin');
114         $email->populateTemplate( $faqQuestion );
115         $email->send();
116 
117         if ($faqQuestion->Email) {
118             $email = new Email($adminEmail, $faqQuestion->Email, _t('FaqHolder.SubjectAcceptQuestion', 'Yours question accepted'));
119             $email->setTemplate('EmailQuestionUser');
120             $email->populateTemplate( $faqQuestion );
121             $email->send();
122         }
123         
124         return $this->renderWith(array('FaqSend', 'Page'), array('Question' => $faqQuestion));
125     }
126     
127     /**
128      * Возвращает список последних опубликованных вопросов (Количество = $this->LastCount)
129      *      
130      * @return DataObjectSet
131      */
132     function LastQuestions() {      
133         if (!$this->LastCount) return false;
134         
135         return DataObject::get('FaqQuestion', "`Published` = 1 AND `FaqHolderID` = {$this->ID}", "`LastEdited` DESC", null, $this->LastCount);      
136     }
137     
138 }
139 
140 
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.1 API Docs API documentation generated by ApiGen 2.8.0