1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yoeunes\Rateable\Services; |
4
|
|
|
|
5
|
|
|
class Raty |
6
|
|
|
{ |
7
|
|
|
protected $element; |
8
|
|
|
|
9
|
|
|
public function element($element) |
10
|
|
|
{ |
11
|
|
|
$this->element = $element; |
12
|
|
|
|
13
|
|
|
return $this; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function render(array $options = []) |
17
|
|
|
{ |
18
|
|
|
return $this->raty($this->raty_options($options)); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
private function raty_options(array $options = []) |
22
|
|
|
{ |
23
|
|
|
$options = array_merge(config('rateable.raty.options'), $options); |
24
|
|
|
|
25
|
|
|
return json_encode($options); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function jsrender(array $options = []) |
29
|
|
|
{ |
30
|
|
|
return '<script type="text/javascript">'.$this->render($options).'</script>'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function raty($options = '', $params = null) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$params = null !== $params ? ', '.$params : ''; |
36
|
|
|
|
37
|
|
|
return '$("'.$this->element.'").raty('.$options.$params.');'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function score($score = null) |
41
|
|
|
{ |
42
|
|
|
return $this->raty('score', $score); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function click(int $number) |
46
|
|
|
{ |
47
|
|
|
return $this->raty('click', $number); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function readOnly(bool $status) |
51
|
|
|
{ |
52
|
|
|
return $this->raty('readOnly', $status); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function cancel(bool $status) |
56
|
|
|
{ |
57
|
|
|
return $this->raty('cancel', $status); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function reload() |
61
|
|
|
{ |
62
|
|
|
return $this->raty('reload'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function set(array $params = []) |
66
|
|
|
{ |
67
|
|
|
return $this->raty(json_encode($params)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function destroy() |
71
|
|
|
{ |
72
|
|
|
return $this->raty('destroy'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function move(int $number) |
76
|
|
|
{ |
77
|
|
|
return $this->raty($number); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|