1 <?php
2 3 4 5 6
7 class extends ComplexTableField {
8 protected $template = "CommentTableField";
9 protected $mode;
10
11 function __construct($controller, $name, $sourceClass, $mode, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "Created", $sourceJoin = "") {
12 $this->mode = $mode;
13
14 Session::set('CommentsSection', $mode);
15
16 parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
17
18 $this->Markable = true;
19 $this->setPageSize(15);
20
21
22 $search = isset($_REQUEST['CommentSearch']) ? Convert::raw2sql($_REQUEST['CommentSearch']) : null;
23 if(!empty($_REQUEST['CommentSearch'])) {
24 $this->sourceFilter[] = "( \"Name\" LIKE '%$search%' OR \"Comment\" LIKE '%$search%')";
25 }
26 }
27
28 function FieldHolder() {
29 $ret = parent::FieldHolder();
30
31 Requirements::javascript(CMS_DIR . '/javascript/CommentTableField.js');
32
33 return $ret;
34 }
35
36 function Items() {
37 $this->sourceItems = $this->sourceItems();
38
39 if(!$this->sourceItems) {
40 return null;
41 }
42
43 $pageStart = (isset($_REQUEST['ctf'][$this->Name()]['start']) && is_numeric($_REQUEST['ctf'][$this->Name()]['start'])) ? $_REQUEST['ctf'][$this->Name()]['start'] : 0;
44 $this->sourceItems->setPageLimits($pageStart, $this->pageSize, $this->totalCount);
45
46 $output = new DataObjectSet();
47 foreach($this->sourceItems as $pageIndex=>$item) {
48 $output->push(SS_Object::create('CommentTableField_Item',$item, $this, $pageStart+$pageIndex));
49 }
50 return $output;
51 }
52
53 function HasSpamButton() {
54 return $this->mode == 'approved' || $this->mode == 'unmoderated';
55 }
56
57 function HasApproveButton() {
58 return $this->mode == 'unmoderated';
59 }
60
61 function HasHamButton() {
62 return $this->mode == 'spam';
63 }
64
65 function SearchForm() {
66 $query = isset($_GET['CommentSearch']) ? $_GET['CommentSearch'] : null;
67
68 $searchFields = new FieldGroup(
69 new TextField('CommentSearch', _t('CommentTableField.SEARCH', 'Search'), $query),
70 new HiddenField("ctf[ID]",'',$this->mode),
71 new HiddenField('CommentFieldName','',$this->name)
72 );
73
74 $actionFields = new LiteralField('CommentFilterButton','<input type="submit" name="CommentFilterButton" value="'. _t('CommentTableField.FILTER', 'Filter') .'" id="CommentFilterButton"/>');
75
76 $fieldContainer = new FieldGroup(
77 $searchFields,
78 $actionFields
79 );
80
81 return $fieldContainer->FieldHolder();
82 }
83 }
84
85 86 87 88 89
90 class extends ComplexTableField_Item {
91
92 function HasSpamButton() {
93 return $this->parent()->HasSpamButton();
94 }
95
96 function HasApproveButton() {
97 return $this->parent()->HasApproveButton();
98 }
99
100 function HasHamButton() {
101 return $this->parent()->HasHamButton();
102 }
103 }
104
105 ?>
[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.
-