1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class PageRaterStarField extends FormField |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
private static $extra_form_selector = ''; |
|
|
|
|
6
|
|
|
|
7
|
|
|
private static $allow_comments = false; |
|
|
|
|
8
|
|
|
|
9
|
|
|
private static $allow_name = false; |
|
|
|
|
10
|
|
|
|
11
|
|
|
private static $allow_title = false; |
|
|
|
|
12
|
|
|
|
13
|
|
|
protected $rating = 0; |
14
|
|
|
|
15
|
|
|
protected $starOptions = 5; |
16
|
|
|
|
17
|
|
|
protected $moreFieldsArray = array(); |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Returns an input field, class="start field" and type="hidden" with an optional maxlength |
21
|
|
|
*/ |
22
|
|
|
public function __construct($name, $title = null, $value = "", $starOptions = null, $form = null) |
23
|
|
|
{ |
24
|
|
|
if ($starOptions) { |
25
|
|
|
$this->starOptions = $starOptions; |
26
|
|
|
} else { |
27
|
|
|
$this->starOptions = PageRating::get_number_of_stars(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
parent::__construct($name, $title, $value, $form); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected $_field_value = null; |
34
|
|
|
|
35
|
|
|
public function Field($properties = array()) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
if (! $this->_field_value) { |
38
|
|
|
Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js'); |
39
|
|
|
Requirements::javascript(THIRDPARTY_DIR .'/jquery-form/jquery.form.js'); |
40
|
|
|
Requirements::javascript('pagerater/javascript/jquery.rating.pack.js'); |
41
|
|
|
Requirements::javascript('pagerater/javascript/PageRater.js'); |
42
|
|
|
if ($this->Config()->get("extra_form_selector")) { |
43
|
|
|
Requirements::customScript("PageRater.set_extra_form_selector('".$this->Config()->get("extra_form_selector")."');"); |
44
|
|
|
} |
45
|
|
|
Requirements::themedCSS('jquery.rating', "pagerater"); |
46
|
|
|
$html = ""; |
47
|
|
|
|
48
|
|
|
$name = $this->getName(); |
49
|
|
|
$id = $this->id(); |
50
|
|
|
for ($i = 1; $i < $this->starOptions + 1; $i++) { |
51
|
|
|
if ($i == $this->Value()) { |
52
|
|
|
$html .= "<input name='$id' class='$id' type='radio' checked='checked' value='$i' />"; |
53
|
|
|
} else { |
54
|
|
|
$html .= "<input name='$id' class='$id' type='radio' value='$i' />"; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
$html .= "<input name='$name' type='hidden' id='$id' />"; |
58
|
|
|
|
59
|
|
View Code Duplication |
if ($this->Config()->get("allow_name")) { |
|
|
|
|
60
|
|
|
$fieldID = $id."_Name"; |
61
|
|
|
$nameField = TextField::create($fieldID, _t("PageRaterStarField.NAME_LABEL", "Your Name")); |
62
|
|
|
$nameField->addExtraClass("additionalComments"); |
63
|
|
|
$html .= $nameField->FieldHolder(); |
64
|
|
|
$this->moreFieldsArray[] = $fieldID; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
if ($this->Config()->get("allow_title")) { |
|
|
|
|
68
|
|
|
$fieldID = $id."_Title"; |
69
|
|
|
$titleField = TextField::create($fieldID, _t("PageRaterStarField.TITLE_LABEL", "Comment Header")); |
70
|
|
|
$titleField->addExtraClass("additionalComments"); |
71
|
|
|
$html .= $titleField->FieldHolder(); |
72
|
|
|
$this->moreFieldsArray[] = $fieldID; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
View Code Duplication |
if ($this->Config()->get("allow_comments")) { |
|
|
|
|
76
|
|
|
$fieldID = $id."_Comment"; |
77
|
|
|
$commentField = TextareaField::create($fieldID, _t("PageRaterStarField.COMMENTS_LABEL", "Any comments you may have")); |
78
|
|
|
$commentField->addExtraClass("additionalComments"); |
79
|
|
|
$html .= $commentField->FieldHolder(); |
80
|
|
|
$this->moreFieldsArray[] = $fieldID; |
81
|
|
|
} |
82
|
|
|
$moreFieldsAsString = implode("', '", $this->moreFieldsArray); |
83
|
|
|
Requirements::customScript(' |
84
|
|
|
if(typeof PageRaterVariables === "undefined") { |
85
|
|
|
var PageRaterVariables = []; |
86
|
|
|
} |
87
|
|
|
PageRaterVariables.push( |
88
|
|
|
{ |
89
|
|
|
id: \''.$id.'\', |
90
|
|
|
fields: [\''.$moreFieldsAsString.'\'] |
91
|
|
|
} |
92
|
|
|
); |
93
|
|
|
'); |
94
|
|
|
$this->_field_value = $html; |
95
|
|
|
} |
96
|
|
|
return $this->_field_value; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getRequiredFields() |
100
|
|
|
{ |
101
|
|
|
$this->Field(); |
102
|
|
|
return $this->moreFieldsArray; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.