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

Packages

  • 1c
    • exchange
      • catalog
  • auth
  • Booking
  • building
    • company
  • cart
    • shipping
    • steppedcheckout
  • Catalog
    • monument
  • 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         'ShowQuestionsForm'=>'Boolean',
 16         'ShowSpamProtection'=>'Boolean',
 17         'Email'=>'Varchar(100)',
 18     );
 19     
 20     static $has_many = array(
 21         'Questions'=>'FaqQuestion'
 22     );
 23 
 24     static $defaults = array (
 25         'QuestionsPerPage' => 20,   
 26         'ShowQuestionsForm' => 1,
 27         'ShowSpamProtection'=> 1,
 28         'AutoChild' => 0,
 29     );
 30 
 31     function getCMSFields() {
 32         $fields = parent::getCMSFields();
 33         
 34         $fields->addFieldToTab('Root.Content.Main', new NumericField('QuestionsPerPage', $this->fieldLabel('QuestionsPerPage')), 'Content');        
 35         $fields->addFieldToTab('Root.Content.Main', new CheckBoxField('ShowQuestionsForm', $this->fieldLabel('ShowQuestionsForm')), 'Content');     
 36         $fields->addFieldToTab('Root.Content.Main', new CheckBoxField('ShowSpamProtection', $this->fieldLabel('ShowSpamProtection')), 'Content');   
 37         $fields->addFieldToTab('Root.Content.Main', new EmailField('Email', sprintf('%s (%s)', $this->fieldLabel('Email'), Email::getAdminEmail())), 'Content');
 38         $fields->removeFieldFromTab('Root.Behaviour','AutoChild');
 39 
 40         return $fields;
 41     }
 42 
 43     /**
 44      * Возвращает емайл отвественного за раздел вопрос-ответ
 45      * Если емайл в разделе не указан - использует емайл администратора сайта
 46      * 
 47      * @return string
 48      */
 49     function adminEmail() {
 50         return ($this->Email) ? $this->Email : Email::getAdminEmail();
 51     }
 52     
 53      /**
 54      * Возвращает список популярных вопросов раздела     
 55      * 
 56      * @return DataObjectSet
 57      */
 58     function PopularQuestions() {
 59         return DataObject::get('FaqQuestion', "`Published` = 1 AND `FaqHolderID` = {$this->ID} AND Popular = 1", "`LastEdited` DESC");      
 60     }
 61 }
 62 /**
 63  * @package faq
 64  * @class FaqHolder_Controller - контроллер страницы Вопрос-ответ
 65  */
 66 class FaqHolder_Controller extends Page_Controller {
 67     
 68     
 69     function index() {
 70         if ($this->Children()->Count() == 1) {//Если в разделе только одна рубрика - то сразу в нее переходим
 71             $this->RedirectToFirstChild();
 72         } else {
 73             return parent::defaultAction('index');
 74         }
 75     }
 76     
 77     /**
 78      * возвращает форму для задания вопроса
 79      * если указано что ее нужно отображать
 80      * форму можно изменить с помощью расширений - метод updateQuestionForm(&$form)
 81      * 
 82      * @return Form
 83      */
 84     function QuestionForm() {       
 85         if (!$this->ShowQuestionsForm) {
 86             return false;
 87         }       
 88         $sections = $this->Children();      
 89         if (!$sections->Count()) {          
 90             return false;
 91         }
 92         $question = singleton('FaqQuestion');
 93         $reqFields = $question->getReqFields();
 94         $fields = $question->getQuestionFormFields($sections);          
 95         $actions = new FieldSet(new FormAction('addQuestion',_t('FaqHolder.SendQuestion','Отправить')));
 96         $form = new Form($this, "QuestionForm", $fields, $actions, new RequiredFields($reqFields));
 97         if ($this->ShowSpamProtection && class_exists('SpamProtectorManager')) {            
 98             SpamProtectorManager::update_form($form, null, array(), _t('FaqHolder.Captcha', 'Captcha')); //
 99         }
100         $this->extend('updateQuestionForm', $form);
101         return $form;
102     }
103     
104     /**
105      * Сохраняет вопрос из формы + отсылает email задавшему вопрос и администратору для ответа
106      * значения объекта FaqQuestion можно изменить с помощью расширений - метод onBeforeAddQuestion(&$question)
107      * 
108      * @return Page
109      */
110     function addQuestion($data, $form) {
111         $faqQuestion = Object::create("FaqQuestion");
112         $form->saveInto($faqQuestion);
113         $this->extend('onBeforeAddQuestion', $faqQuestion, $data, $form);
114         $faqQuestion->write();  
115         
116         $adminEmail = $faqQuestion->Section()->adminEmail();
117         
118         $email = new Email(Email::getAdminEmail(), $adminEmail, _t('FaqHolder.SubjectNewQuestion', 'New Question added'));
119         $email->setTemplate('EmailQuestionAdmin');
120         $email->populateTemplate( $faqQuestion );
121         $email->send();
122 
123         if ($faqQuestion->Email) {
124             $email = new Email($adminEmail, $faqQuestion->Email, _t('FaqHolder.SubjectAcceptQuestion', 'Yours question accepted'));
125             $email->setTemplate('EmailQuestionUser');
126             $email->populateTemplate( $faqQuestion );
127             $email->send();
128         }
129         
130         return $this->renderWith(array('FaqSend', 'Page'), array('Question' => $faqQuestion));
131     }   
132 }
[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.2 API Docs API documentation generated by ApiGen 2.8.0