-
Notifications
You must be signed in to change notification settings - Fork 452
/
service.php
110 lines (98 loc) · 3.5 KB
/
service.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
namespace Concrete\Attribute\Rating;
use View;
use Loader;
class Service
{
public function outputDisplay($value)
{
$v = View::getInstance();
$v->requireAsset('core/rating');
$html = '';
$star1 = 'fa-star-o';
$star2 = 'fa-star-o';
$star3 = 'fa-star-o';
$star4 = 'fa-star-o';
$star5 = 'fa-star-o';
if ($value > 4) {
$star1 = 'fa-star-half-o';
}
if ($value > 14) {
$star1 = 'fa-star';
}
if ($value > 24) {
$star2 = 'fa-star-half-o';
}
if ($value > 34) {
$star2 = 'fa-star';
}
if ($value > 44) {
$star3 = 'fa-star-half-o';
}
if ($value > 54) {
$star3 = 'fa-star';
}
if ($value > 64) {
$star4 = 'fa-star-half-o';
}
if ($value > 74) {
$star4 = 'fa-star';
}
if ($value > 84) {
$star5 = 'fa-star-half-o';
}
if ($value > 94) {
$star5 = 'fa-star';
}
$html .= '<div class="ccm-attribute ccm-attribute-rating ccm-rating">';
$html .= '<div class="fa ' . $star1 . '"><a href="javascript:void(0)"></a></div>';
$html .= '<div class="fa ' . $star2 . '"><a href="javascript:void(0)"></a></div>';
$html .= '<div class="fa ' . $star3 . '"><a href="javascript:void(0)"></a></div>';
$html .= '<div class="fa ' . $star4 . '"><a href="javascript:void(0)"></a></div>';
$html .= '<div class="fa ' . $star5 . '"><a href="javascript:void(0)"></a></div>';
$html .= '</div>';
return $html;
}
public function output($field, $value)
{
$v = View::getInstance();
$v->requireAsset('core/rating');
$form = Loader::helper("form");
$v = $form->getRequestValue($field);
if ($v !== false) {
$value = $v;
}
$sanitized = preg_replace('/[^A-Za-z0-9]/i', '', $field);
$html = '<div class="ccm-attribute ccm-attribute-rating ccm-rating" data-rating-field-name="' . $sanitized . '" data-score="' . $value . '"></div>';
$html .= "<script type=\"text/javascript\">
$(function() {
$('div[data-rating-field-name={$sanitized}]').awesomeStarRating({
'name': \"{$field}\"
});
});</script>";
return $html;
/*
$html = '';
$checked1 = ($value == 20) ? 'checked' : '';
$checked2 = ($value == 40) ? 'checked' : '';
$checked3 = ($value == 60) ? 'checked' : '';
$checked4 = ($value == 80) ? 'checked' : '';
$checked5 = ($value == 100) ? 'checked' : '';
$html .= "<div class=\"ccm-rating\" id=\"ccm-rating-{$field}\">
<input name=\"{$field}\" type=\"radio\" value=\"20\" {$checked1} {$disabled}/>
<input name=\"{$field}\" type=\"radio\" value=\"40\" {$checked2} {$disabled}/>
<input name=\"{$field}\" type=\"radio\" value=\"60\" {$checked3} {$disabled} />
<input name=\"{$field}\" type=\"radio\" value=\"80\" {$checked4} {$disabled}/>
<input name=\"{$field}\" type=\"radio\" value=\"100\" {$checked5} {$disabled}/>
</div>";
if ($includeJS) {
$html .= "<script type=\"text/javascript\">
$(function() {
$('input[name=\"{$field}\"]').rating();
});
</script>";
}
return $html;
*/
}
}