@@ -311,6 +311,9 @@ |
||
311 | 311 | } |
312 | 312 | |
313 | 313 | # 携帯端末かどうかを判定し、ビューをロードするプライベートメソッドです。 |
314 | + /** |
|
315 | + * @param string $file |
|
316 | + */ |
|
314 | 317 | private function _load_view($file, $data = '') |
315 | 318 | { |
316 | 319 | # 携帯端末の場合は、「_mobile」がファイル名に付くビューファイルをロードします。 |
@@ -5,6 +5,12 @@ |
||
5 | 5 | private $CI; |
6 | 6 | |
7 | 7 | // ページネーションの生成 |
8 | + |
|
9 | + /** |
|
10 | + * @param string $path |
|
11 | + * @param integer $total |
|
12 | + * @param integer $uri_segment |
|
13 | + */ |
|
8 | 14 | public function get_links($path, $total, $uri_segment) |
9 | 15 | { |
10 | 16 | # ページネーションクラスをロードします。 |
@@ -20,6 +20,9 @@ |
||
20 | 20 | $this->CI->form_validation->set_error_delimiters($prefix, $suffix); |
21 | 21 | } |
22 | 22 | |
23 | + /** |
|
24 | + * @param string $field |
|
25 | + */ |
|
23 | 26 | protected function set_rules( |
24 | 27 | $field, $label = '', $rules = array(), $errors = array() |
25 | 28 | ) |
@@ -10,6 +10,9 @@ |
||
10 | 10 | $this->CI->load->library('form_validation'); |
11 | 11 | } |
12 | 12 | |
13 | + /** |
|
14 | + * @param string $rules |
|
15 | + */ |
|
13 | 16 | public function validate($value, $rules, $errors = []) |
14 | 17 | { |
15 | 18 | $this->CI->form_validation->reset_validation(); |
@@ -18,6 +18,9 @@ discard block |
||
18 | 18 | return $query->result(); |
19 | 19 | } |
20 | 20 | |
21 | + /** |
|
22 | + * @param string $id |
|
23 | + */ |
|
21 | 24 | public function get_category_name($id) |
22 | 25 | { |
23 | 26 | $this->db->select('name'); |
@@ -27,6 +30,11 @@ discard block |
||
27 | 30 | return $row->name; |
28 | 31 | } |
29 | 32 | |
33 | + /** |
|
34 | + * @param string $cat_id |
|
35 | + * @param string|null $limit |
|
36 | + * @param string $offset |
|
37 | + */ |
|
30 | 38 | public function get_product_list($cat_id, $limit, $offset) |
31 | 39 | { |
32 | 40 | $this->db->where('category_id', $cat_id); |
@@ -35,6 +43,9 @@ discard block |
||
35 | 43 | return $query->result(); |
36 | 44 | } |
37 | 45 | |
46 | + /** |
|
47 | + * @param string $cat_id |
|
48 | + */ |
|
38 | 49 | public function get_product_count($cat_id) |
39 | 50 | { |
40 | 51 | $this->db->where('category_id', $cat_id); |
@@ -49,6 +60,9 @@ discard block |
||
49 | 60 | return $query->row(); |
50 | 61 | } |
51 | 62 | |
63 | + /** |
|
64 | + * @param integer $id |
|
65 | + */ |
|
52 | 66 | public function is_available_product_item($id) |
53 | 67 | { |
54 | 68 | $this->db->where('id', $id); |
@@ -63,6 +77,11 @@ discard block |
||
63 | 77 | } |
64 | 78 | } |
65 | 79 | |
80 | + /** |
|
81 | + * @param string $q |
|
82 | + * @param string|null $limit |
|
83 | + * @param string $offset |
|
84 | + */ |
|
66 | 85 | public function get_product_by_search($q, $limit, $offset) |
67 | 86 | { |
68 | 87 | # 検索キーワードをスペースで分割し、like()メソッドでLIKE句を指定します。 |
@@ -78,6 +97,9 @@ discard block |
||
78 | 97 | return $query->result(); |
79 | 98 | } |
80 | 99 | |
100 | + /** |
|
101 | + * @param string $q |
|
102 | + */ |
|
81 | 103 | public function get_count_by_search($q) |
82 | 104 | { |
83 | 105 | $this->db->select('name'); |
@@ -17,242 +17,242 @@ |
||
17 | 17 | |
18 | 18 | class Twig |
19 | 19 | { |
20 | - /** |
|
21 | - * @var array Paths to Twig templates |
|
22 | - */ |
|
23 | - private $paths = []; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var array Twig Environment Options |
|
27 | - * @see http://twig.sensiolabs.org/doc/api.html#environment-options |
|
28 | - */ |
|
29 | - private $config = []; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var array Functions to add to Twig |
|
33 | - */ |
|
34 | - private $functions_asis = [ |
|
35 | - 'base_url', 'site_url', |
|
36 | - ]; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array Functions with `is_safe` option |
|
40 | - * @see http://twig.sensiolabs.org/doc/advanced.html#automatic-escaping |
|
41 | - */ |
|
42 | - private $functions_safe = [ |
|
43 | - 'form_open', 'form_close', 'form_error', 'form_hidden', 'set_value', |
|
20 | + /** |
|
21 | + * @var array Paths to Twig templates |
|
22 | + */ |
|
23 | + private $paths = []; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var array Twig Environment Options |
|
27 | + * @see http://twig.sensiolabs.org/doc/api.html#environment-options |
|
28 | + */ |
|
29 | + private $config = []; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var array Functions to add to Twig |
|
33 | + */ |
|
34 | + private $functions_asis = [ |
|
35 | + 'base_url', 'site_url', |
|
36 | + ]; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array Functions with `is_safe` option |
|
40 | + * @see http://twig.sensiolabs.org/doc/advanced.html#automatic-escaping |
|
41 | + */ |
|
42 | + private $functions_safe = [ |
|
43 | + 'form_open', 'form_close', 'form_error', 'form_hidden', 'set_value', |
|
44 | 44 | // 'form_open_multipart', 'form_upload', 'form_submit', 'form_dropdown', |
45 | 45 | // 'set_radio', 'set_select', 'set_checkbox', |
46 | - ]; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var bool Whether functions are added or not |
|
50 | - */ |
|
51 | - private $functions_added = FALSE; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var Twig_Environment |
|
55 | - */ |
|
56 | - private $twig; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var Twig_Loader_Filesystem |
|
60 | - */ |
|
61 | - private $loader; |
|
62 | - |
|
63 | - public function __construct($params = []) |
|
64 | - { |
|
65 | - if (isset($params['functions'])) |
|
66 | - { |
|
67 | - $this->functions_asis = |
|
68 | - array_unique( |
|
69 | - array_merge($this->functions_asis, $params['functions']) |
|
70 | - ); |
|
71 | - unset($params['functions']); |
|
72 | - } |
|
73 | - if (isset($params['functions_safe'])) |
|
74 | - { |
|
75 | - $this->functions_safe = |
|
76 | - array_unique( |
|
77 | - array_merge($this->functions_safe, $params['functions_safe']) |
|
78 | - ); |
|
79 | - unset($params['functions_safe']); |
|
80 | - } |
|
81 | - |
|
82 | - if (isset($params['paths'])) |
|
83 | - { |
|
84 | - $this->paths = $params['paths']; |
|
85 | - unset($params['paths']); |
|
86 | - } |
|
87 | - else |
|
88 | - { |
|
89 | - $this->paths = [VIEWPATH]; |
|
90 | - } |
|
91 | - |
|
92 | - // default Twig config |
|
93 | - $this->config = [ |
|
94 | - 'cache' => APPPATH . 'cache/twig', |
|
95 | - 'debug' => ENVIRONMENT !== 'production', |
|
96 | - 'autoescape' => 'html', |
|
97 | - ]; |
|
98 | - |
|
99 | - $this->config = array_merge($this->config, $params); |
|
100 | - } |
|
101 | - |
|
102 | - protected function resetTwig() |
|
103 | - { |
|
104 | - $this->twig = null; |
|
105 | - $this->createTwig(); |
|
106 | - } |
|
107 | - |
|
108 | - protected function createTwig() |
|
109 | - { |
|
110 | - // $this->twig is singleton |
|
111 | - if ($this->twig !== null) |
|
112 | - { |
|
113 | - return; |
|
114 | - } |
|
115 | - |
|
116 | - if ($this->loader === null) |
|
117 | - { |
|
118 | - $this->loader = new \Twig_Loader_Filesystem($this->paths); |
|
119 | - } |
|
120 | - |
|
121 | - $twig = new \Twig_Environment($this->loader, $this->config); |
|
122 | - |
|
123 | - if ($this->config['debug']) |
|
124 | - { |
|
125 | - $twig->addExtension(new \Twig_Extension_Debug()); |
|
126 | - } |
|
127 | - |
|
128 | - $this->twig = $twig; |
|
129 | - } |
|
130 | - |
|
131 | - protected function setLoader($loader) |
|
132 | - { |
|
133 | - $this->loader = $loader; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Registers a Global |
|
138 | - * |
|
139 | - * @param string $name The global name |
|
140 | - * @param mixed $value The global value |
|
141 | - */ |
|
142 | - public function addGlobal($name, $value) |
|
143 | - { |
|
144 | - $this->createTwig(); |
|
145 | - $this->twig->addGlobal($name, $value); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Renders Twig Template and Set Output |
|
150 | - * |
|
151 | - * @param string $view Template filename without `.twig` |
|
152 | - * @param array $params Array of parameters to pass to the template |
|
153 | - */ |
|
154 | - public function display($view, $params = []) |
|
155 | - { |
|
156 | - $CI =& get_instance(); |
|
157 | - $CI->output->set_output($this->render($view, $params)); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Renders Twig Template and Returns as String |
|
162 | - * |
|
163 | - * @param string $view Template filename without `.twig` |
|
164 | - * @param array $params Array of parameters to pass to the template |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - public function render($view, $params = []) |
|
168 | - { |
|
169 | - $this->createTwig(); |
|
170 | - // We call addFunctions() here, because we must call addFunctions() |
|
171 | - // after loading CodeIgniter functions in a controller. |
|
172 | - $this->addFunctions(); |
|
173 | - |
|
174 | - $view = $view . '.twig'; |
|
175 | - return $this->twig->render($view, $params); |
|
176 | - } |
|
177 | - |
|
178 | - protected function addFunctions() |
|
179 | - { |
|
180 | - // Runs only once |
|
181 | - if ($this->functions_added) |
|
182 | - { |
|
183 | - return; |
|
184 | - } |
|
185 | - |
|
186 | - // as is functions |
|
187 | - foreach ($this->functions_asis as $function) |
|
188 | - { |
|
189 | - if (function_exists($function)) |
|
190 | - { |
|
191 | - $this->twig->addFunction( |
|
192 | - new \Twig_SimpleFunction( |
|
193 | - $function, |
|
194 | - $function |
|
195 | - ) |
|
196 | - ); |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - // safe functions |
|
201 | - foreach ($this->functions_safe as $function) |
|
202 | - { |
|
203 | - if (function_exists($function)) |
|
204 | - { |
|
205 | - $this->twig->addFunction( |
|
206 | - new \Twig_SimpleFunction( |
|
207 | - $function, |
|
208 | - $function, |
|
209 | - ['is_safe' => ['html']] |
|
210 | - ) |
|
211 | - ); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - // customized functions |
|
216 | - if (function_exists('anchor')) |
|
217 | - { |
|
218 | - $this->twig->addFunction( |
|
219 | - new \Twig_SimpleFunction( |
|
220 | - 'anchor', |
|
221 | - [$this, 'safe_anchor'], |
|
222 | - ['is_safe' => ['html']] |
|
223 | - ) |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - $this->functions_added = TRUE; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @param string $uri |
|
232 | - * @param string $title |
|
233 | - * @param array $attributes [changed] only array is acceptable |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public function safe_anchor($uri = '', $title = '', $attributes = []) |
|
237 | - { |
|
238 | - $uri = html_escape($uri); |
|
239 | - $title = html_escape($title); |
|
240 | - |
|
241 | - $new_attr = []; |
|
242 | - foreach ($attributes as $key => $val) |
|
243 | - { |
|
244 | - $new_attr[html_escape($key)] = html_escape($val); |
|
245 | - } |
|
246 | - |
|
247 | - return anchor($uri, $title, $new_attr); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @return \Twig_Environment |
|
252 | - */ |
|
253 | - public function getTwig() |
|
254 | - { |
|
255 | - $this->createTwig(); |
|
256 | - return $this->twig; |
|
257 | - } |
|
46 | + ]; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var bool Whether functions are added or not |
|
50 | + */ |
|
51 | + private $functions_added = FALSE; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var Twig_Environment |
|
55 | + */ |
|
56 | + private $twig; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var Twig_Loader_Filesystem |
|
60 | + */ |
|
61 | + private $loader; |
|
62 | + |
|
63 | + public function __construct($params = []) |
|
64 | + { |
|
65 | + if (isset($params['functions'])) |
|
66 | + { |
|
67 | + $this->functions_asis = |
|
68 | + array_unique( |
|
69 | + array_merge($this->functions_asis, $params['functions']) |
|
70 | + ); |
|
71 | + unset($params['functions']); |
|
72 | + } |
|
73 | + if (isset($params['functions_safe'])) |
|
74 | + { |
|
75 | + $this->functions_safe = |
|
76 | + array_unique( |
|
77 | + array_merge($this->functions_safe, $params['functions_safe']) |
|
78 | + ); |
|
79 | + unset($params['functions_safe']); |
|
80 | + } |
|
81 | + |
|
82 | + if (isset($params['paths'])) |
|
83 | + { |
|
84 | + $this->paths = $params['paths']; |
|
85 | + unset($params['paths']); |
|
86 | + } |
|
87 | + else |
|
88 | + { |
|
89 | + $this->paths = [VIEWPATH]; |
|
90 | + } |
|
91 | + |
|
92 | + // default Twig config |
|
93 | + $this->config = [ |
|
94 | + 'cache' => APPPATH . 'cache/twig', |
|
95 | + 'debug' => ENVIRONMENT !== 'production', |
|
96 | + 'autoescape' => 'html', |
|
97 | + ]; |
|
98 | + |
|
99 | + $this->config = array_merge($this->config, $params); |
|
100 | + } |
|
101 | + |
|
102 | + protected function resetTwig() |
|
103 | + { |
|
104 | + $this->twig = null; |
|
105 | + $this->createTwig(); |
|
106 | + } |
|
107 | + |
|
108 | + protected function createTwig() |
|
109 | + { |
|
110 | + // $this->twig is singleton |
|
111 | + if ($this->twig !== null) |
|
112 | + { |
|
113 | + return; |
|
114 | + } |
|
115 | + |
|
116 | + if ($this->loader === null) |
|
117 | + { |
|
118 | + $this->loader = new \Twig_Loader_Filesystem($this->paths); |
|
119 | + } |
|
120 | + |
|
121 | + $twig = new \Twig_Environment($this->loader, $this->config); |
|
122 | + |
|
123 | + if ($this->config['debug']) |
|
124 | + { |
|
125 | + $twig->addExtension(new \Twig_Extension_Debug()); |
|
126 | + } |
|
127 | + |
|
128 | + $this->twig = $twig; |
|
129 | + } |
|
130 | + |
|
131 | + protected function setLoader($loader) |
|
132 | + { |
|
133 | + $this->loader = $loader; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Registers a Global |
|
138 | + * |
|
139 | + * @param string $name The global name |
|
140 | + * @param mixed $value The global value |
|
141 | + */ |
|
142 | + public function addGlobal($name, $value) |
|
143 | + { |
|
144 | + $this->createTwig(); |
|
145 | + $this->twig->addGlobal($name, $value); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Renders Twig Template and Set Output |
|
150 | + * |
|
151 | + * @param string $view Template filename without `.twig` |
|
152 | + * @param array $params Array of parameters to pass to the template |
|
153 | + */ |
|
154 | + public function display($view, $params = []) |
|
155 | + { |
|
156 | + $CI =& get_instance(); |
|
157 | + $CI->output->set_output($this->render($view, $params)); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Renders Twig Template and Returns as String |
|
162 | + * |
|
163 | + * @param string $view Template filename without `.twig` |
|
164 | + * @param array $params Array of parameters to pass to the template |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + public function render($view, $params = []) |
|
168 | + { |
|
169 | + $this->createTwig(); |
|
170 | + // We call addFunctions() here, because we must call addFunctions() |
|
171 | + // after loading CodeIgniter functions in a controller. |
|
172 | + $this->addFunctions(); |
|
173 | + |
|
174 | + $view = $view . '.twig'; |
|
175 | + return $this->twig->render($view, $params); |
|
176 | + } |
|
177 | + |
|
178 | + protected function addFunctions() |
|
179 | + { |
|
180 | + // Runs only once |
|
181 | + if ($this->functions_added) |
|
182 | + { |
|
183 | + return; |
|
184 | + } |
|
185 | + |
|
186 | + // as is functions |
|
187 | + foreach ($this->functions_asis as $function) |
|
188 | + { |
|
189 | + if (function_exists($function)) |
|
190 | + { |
|
191 | + $this->twig->addFunction( |
|
192 | + new \Twig_SimpleFunction( |
|
193 | + $function, |
|
194 | + $function |
|
195 | + ) |
|
196 | + ); |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + // safe functions |
|
201 | + foreach ($this->functions_safe as $function) |
|
202 | + { |
|
203 | + if (function_exists($function)) |
|
204 | + { |
|
205 | + $this->twig->addFunction( |
|
206 | + new \Twig_SimpleFunction( |
|
207 | + $function, |
|
208 | + $function, |
|
209 | + ['is_safe' => ['html']] |
|
210 | + ) |
|
211 | + ); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + // customized functions |
|
216 | + if (function_exists('anchor')) |
|
217 | + { |
|
218 | + $this->twig->addFunction( |
|
219 | + new \Twig_SimpleFunction( |
|
220 | + 'anchor', |
|
221 | + [$this, 'safe_anchor'], |
|
222 | + ['is_safe' => ['html']] |
|
223 | + ) |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + $this->functions_added = TRUE; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @param string $uri |
|
232 | + * @param string $title |
|
233 | + * @param array $attributes [changed] only array is acceptable |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public function safe_anchor($uri = '', $title = '', $attributes = []) |
|
237 | + { |
|
238 | + $uri = html_escape($uri); |
|
239 | + $title = html_escape($title); |
|
240 | + |
|
241 | + $new_attr = []; |
|
242 | + foreach ($attributes as $key => $val) |
|
243 | + { |
|
244 | + $new_attr[html_escape($key)] = html_escape($val); |
|
245 | + } |
|
246 | + |
|
247 | + return anchor($uri, $title, $new_attr); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @return \Twig_Environment |
|
252 | + */ |
|
253 | + public function getTwig() |
|
254 | + { |
|
255 | + $this->createTwig(); |
|
256 | + return $this->twig; |
|
257 | + } |
|
258 | 258 | } |