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 FaqQuestion - объект Вопрос
  5  *
  6  * @author menedem
  7  */
  8 class FaqQuestion extends DataObject {
  9 
 10     static $db = array(      
 11       'Question' => 'Text',
 12       'Answer' => 'Text',
 13       'Email' => 'Varchar',
 14       'SenderIP' => 'Varchar',
 15       'Published' => 'Boolean',       
 16       'SendAnswer' => 'Boolean',
 17       'AnswerDate' => 'SSDatetime',   
 18    );
 19 
 20     static $has_one = array(
 21         'AnswerUser' => 'Member',
 22         'FaqHolder' => 'FaqHolder',
 23         'Section' => 'FaqSection',
 24     );
 25 
 26     static $searchable_fields = array(
 27         'Question', 'Answer', 'Email'
 28     );
 29 
 30     static $summary_fields = array(
 31         'Question', 'Created', 'AnswerDate', 'PublishedTitle', 'SendAnswerTitle'
 32     );
 33     
 34     static $reqFields = array('Section', 'Email', 'Question');
 35     
 36     public function canEdit($member = null) {
 37         if(Permission::checkMember($member, 'ADMIN') || Permission::checkMember($member, 'CMS_ACCESS_FaqAdmin')) 
 38             return true;
 39         return false;
 40     }
 41     
 42     public function canDelete($member = null) {
 43         if(Permission::checkMember($member, 'ADMIN') || Permission::checkMember($member, 'CMS_ACCESS_FaqAdmin')) 
 44             return true;
 45         return false;
 46     }
 47         
 48     /**
 49      * Возвращает список обязательных полей
 50      * список полей можно менять 2 способами:
 51      * - через вызов в конфиге сайта FaqQuestion::setReqFields()
 52      * - через расширение для FaqQuestion (метод updateRequiredFields(&$fields))
 53      * 
 54      * @return array
 55      */
 56     function getReqFields() {
 57         $fields = self::$reqFields;
 58         $siteConfig = SiteConfig::current_site_config();
 59         if ($siteConfig->hasMethod('SiteAgreementField') && ($rulesField = $siteConfig->SiteAgreementField())) {
 60             $fields[] = $rulesField->Name();
 61         }
 62         $this->extend('updateRequiredFields', $fields);
 63         return $fields;
 64     }
 65 
 66     /**
 67      * Изменяет значение обязательных полей для формы вопроса
 68      * 
 69      * @param array $value 
 70      */
 71     static function setReqFields($value) {
 72         self::$reqFields = $value;
 73     }
 74 
 75     function getCMSFields() {
 76         $fields = parent::getCMSFields();
 77         $fields->addFieldToTab('Root.Main', new DatetimeField('Created', _t('FaqQuestion.db_Created','Created')), 'SenderIP');
 78         $fields->replaceField('SendAnswer',$fields->dataFieldByName('SendAnswer')->performReadonlyTransformation());
 79         $fields->replaceField('AnswerDate',$fields->dataFieldByName('AnswerDate')->performReadonlyTransformation());        
 80         $fields->replaceField('Created',$fields->dataFieldByName('Created')->performReadonlyTransformation());      
 81         $fields->replaceField('AnswerUserID',$fields->dataFieldByName('AnswerUserID')->performReadonlyTransformation());        
 82         $fields->replaceField('SenderIP',$fields->dataFieldByName('SenderIP')->performReadonlyTransformation());        
 83         $fields->replaceField('SectionID',$fields->dataFieldByName('SectionID')->performReadonlyTransformation());      
 84         $fields->removeByName('FaqHolderID');
 85         //$fields->removeByName('SectionID');           
 86         return $fields;
 87     }   
 88     
 89     /**
 90      * Проверка параметров и посылка ответа (если есть) перед сохранением вопроса 
 91      */
 92     function OnBeforeWrite() {
 93     
 94         if (!$this->ID && isset($_SERVER['REMOTE_ADDR'])) {
 95             $this->SenderIP = $_SERVER['REMOTE_ADDR'];
 96         }
 97         
 98         $this->FaqHolderID = $this->Section()->ParentID;
 99         
100         if ($this->Answer && $this->SendAnswer == 0 && $this->Email) {      
101             $adminEmail = $this->Section()->adminEmail();           
102             $email = new Email($adminEmail, $this->Email, _t('FaqQuestion.SubjectAnswer', 'You got an answer'));
103             $email->setTemplate('EmailAnswer');
104             $email->populateTemplate( $this );
105             $email->send();
106             $this->SendAnswer = 1;
107         }
108         
109         if ($this->Answer && ! $this->AnswerDate) {
110             $this->AnswerDate = date('Y-m-d H:i:s');
111             $this->AnswerUser = Member::currentUser();
112         }
113         
114         if ($this->Published && !$this->Answer) {
115             $this->Published = 0;
116             Form::messageForForm( 'ComplexTableField_Popup_DetailForm', 'Нелья опубликовать вопрос без ответа!', 'warning');            
117         }
118         parent::OnBeforeWrite();
119     }
120     
121     /**     
122      * Возвращает красивое имя поля (0-Нет, 1-Да)
123      * @return String
124      */
125     function getPublishedTitle() {
126         $ans = ($this->Published) ? 'YES' : 'NO';
127         return _t("FaqQuestion." . $ans, $ans);
128     }
129     
130     /**     
131      * Возвращает красивое имя поля (0-Нет, 1-Да)
132      * @return String
133      */
134     function getSendAnswerTitle() {
135         $ans = ($this->SendAnswer) ? 'YES' : 'NO';
136         return _t("FaqQuestion." . $ans, $ans);
137         
138     }   
139     
140     
141     /**     
142      * Возвращает поля для формы задания вопроса
143      * в расширегниях можно изменить список полей меотодом updateQuestionFields(&$fields)
144      *
145      * @return FieldSet
146      */
147     function getQuestionFormFields($sections) { 
148         if ($sections->Count() == 1) {
149             $sectionField = new HiddenField('SectionID', null, $sections->items[0]->ID);
150         } else {
151             $sectionField = new DropdownField('SectionID', _t('FaqQuestion.has_one_Section','Section'), $sections->toDropdownMap());
152         }       
153         $fields = new FieldSet(
154             $sectionField, 
155             new EmailField('Email',_t('FaqQuestion.db_Email','Обратный e-mail')),
156             new TextareaField('Question',_t('FaqQuestion.db_Question','Текст обращения'))
157         );
158         $siteConfig = SiteConfig::current_site_config();
159         if ($siteConfig->hasMethod('SiteAgreementField') && ($rulesField = $siteConfig->SiteAgreementField())) {
160             $fields->push($rulesField);
161         }
162         $this->extend('updateQuestionFields', $fields);     
163         return $fields;
164     }
165     
166 }
167 
168 
[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