|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @property CI_DB $db |
|
5
|
|
|
*/ |
|
6
|
|
|
class Inventory_model extends CI_Model { |
|
7
|
|
|
|
|
8
|
|
|
public function __construct() |
|
9
|
|
|
{ |
|
10
|
|
|
parent::__construct(); |
|
11
|
|
|
$this->load->database(); |
|
|
|
|
|
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function get_category_list() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->db->order_by('id'); |
|
17
|
|
|
$query = $this->db->get('category'); |
|
18
|
|
|
return $query->result(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function get_category_name($id) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->db->select('name'); |
|
24
|
|
|
$this->db->where('id', $id); |
|
25
|
|
|
$query = $this->db->get('category'); |
|
26
|
|
|
$row = $query->row(); |
|
27
|
|
|
|
|
28
|
|
|
if ($row === null) |
|
29
|
|
|
{ |
|
30
|
|
|
show_error('不正な入力です。'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return $row->name; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function get_product_list($cat_id, $limit, $offset) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->db->where('category_id', $cat_id); |
|
39
|
|
|
$this->db->order_by('id'); |
|
40
|
|
|
$query = $this->db->get('product', $limit, $offset); |
|
41
|
|
|
return $query->result(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function get_product_count($cat_id) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->db->where('category_id', $cat_id); |
|
47
|
|
|
$query = $this->db->get('product'); |
|
48
|
|
|
return $query->num_rows(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function get_product_item($id) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->db->where('id', $id); |
|
54
|
|
|
$query = $this->db->get('product'); |
|
55
|
|
|
return $query->row(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function is_available_product_item($id) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->db->where('id', $id); |
|
61
|
|
|
$query = $this->db->get('product'); |
|
62
|
|
|
if ($query->num_rows() == 1) |
|
63
|
|
|
{ |
|
64
|
|
|
return TRUE; |
|
65
|
|
|
} |
|
66
|
|
|
else |
|
67
|
|
|
{ |
|
68
|
|
|
return FALSE; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
View Code Duplication |
public function get_product_by_search($q, $limit, $offset) |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
# 検索キーワードをスペースで分割し、like()メソッドでLIKE句を指定します。 |
|
75
|
|
|
# 複数回like()メソッドを呼んだ場合は、AND条件になります。 |
|
76
|
|
|
# name LIKE '%{$keyword}%' AND name LIKE '%{$keyword}%' というSQL文になります。 |
|
77
|
|
|
$keywords = explode(" ", $q); |
|
78
|
|
|
foreach ($keywords as $keyword) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->db->like('name', $keyword); |
|
81
|
|
|
} |
|
82
|
|
|
$this->db->order_by('id'); |
|
83
|
|
|
$query = $this->db->get('product', $limit, $offset); |
|
84
|
|
|
return $query->result(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
View Code Duplication |
public function get_count_by_search($q) |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
$this->db->select('name'); |
|
90
|
|
|
$keywords = explode(" ", $q); |
|
91
|
|
|
foreach ($keywords as $keyword) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->db->like('name', $keyword); |
|
94
|
|
|
} |
|
95
|
|
|
$this->db->order_by('id'); |
|
96
|
|
|
$query = $this->db->get('product'); |
|
97
|
|
|
return $query->num_rows(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.