1 <?php
2 3 4 5 6 7
8 class FaqSection extends Page {
9
10 static $icon = "faq/img/faq";
11
12 static $allowed_children = 'none';
13
14 static $db = array(
15 'Email'=>'Varchar(100)',
16 );
17
18 static $has_many = array(
19 'Questions'=>'FaqQuestion'
20 );
21
22 function getCMSFields() {
23 $fields = parent::getCMSFields();
24 $fields->addFieldToTab('Root.Content.Main', new EmailField('Email', sprintf('%s (%s)', $this->fieldLabel('Email'), $this->Parent()->adminEmail())), 'Content');
25 $tablefield = new ComplexTableField(
26 $this,
27 'Questions',
28 'FaqQuestion',
29 array(
30 'Question' => 'Question',
31
32
33 'Email' => 'Email',
34 'Created' => _t('FaqQuestion.db_Created'),
35 'AnswerDate' => 'AnswerDate',
36 'PublishedTitle' => 'Published',
37 'SendAnswerTitle' => 'SendAnswer'
38
39 ),
40 'getCMSFields_forPopup',
41 "`SectionID` = {$this->ID}",
42 "`Created` DESC"
43 );
44 $fields->insertAfter(new Tab("Questions", _t('FaqSection.tab_Questions','Questions')), 'Main');
45 $fields->addFieldToTab('Root.Content.Questions', $tablefield);
46 return $fields;
47 }
48
49 50 51 52 53 54
55 function adminEmail() {
56 return ($this->Email) ? $this->Email : $this->Parent()->adminEmail();
57 }
58
59 function onAfterDelete() {
60 parent::onAfterDelete();
61 if ($this->IsDeletedFromStage && !$this->ExistsOnLive) {
62 if ($this->Questions()) {
63 foreach($this->Questions() as $question)
64 $question->delete();
65 }
66 }
67
68 }
69
70 71 72 73 74
75 function SectionQuestions() {
76 $offset = 0;
77 if (isset($_GET['start'])) {
78 $offset = (int) $_GET['start'];
79 }
80 $pageSize = $this->Parent()->QuestionsPerPage;
81 $rs = DataObject::get('FaqQuestion', "`Published` = 1 AND `SectionID` = {$this->ID}", "`LastEdited` DESC", '', "$offset,$pageSize");
82
83 return $rs;
84 }
85 }
86 87 88 89
90 class FaqSection_Controller extends Page_Controller {
91
92 93 94 95 96 97
98 function QuestionForm() {
99 $parentController = new FaqHolder_controller($this->Parent());
100 $form = $parentController->QuestionForm();
101 if ($form) {
102 $form->loadDataFrom( array('SectionID' => $this->ID));
103 }
104 return $form;
105 }
106
107 function Questions() {
108 $questions = $this->SectionQuestions();
109 if ($this->hasMethod('setSEOVars')) {
110 $this->setSEOVars($questions);
111 }
112 return $questions;
113 }
114
115 }
116
117
[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.
-