/
item.php
103 lines (88 loc) · 3.47 KB
/
item.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
<?php
class Model_Item extends Zend_Db_Table
{
protected $_name = 'items';
protected $_cols = array('id', 'name', 'lvl', 'type', 'slot', 'q', 'skills', 'manastoneLvl', 'manastoneCount', 'godstone', 'price', 'icon', 'image', 'links');
public function addItem($data)
{
$saveData = array(
'name' => $this->filter($data['name']),
'lvl' => $this->filter($data['lvl'], 'int'),
'type' => $this->filter($data['type'], 'int'),
'slot' => $this->filter($data['slot'], 'int'),
'q' => $this->filter($data['q'], 'int'),
'skills' => $this->filter($data['q']),
'manastoneLvl' => $this->filter($data['manastoneLvl'], 'int'),
'manastoneCount' => $this->filter($data['manastoneCount'], 'int'),
'godstone' => $this->filter($data['godstone'], 'bool'),
'price' => $this->filter($data['price']),
'icon' => $this->filter($data['icon']),
'image' => $this->filter($data['image']),
'links' => $this->filter($data['links'])
);
$data['skills'] = serialize($data['skills']);
$data['price'] = serialize($data['price']);
$row = $this->createRow($data);
return $row->save();
}
public function getItem($id)
{
$row = $this->fetchRow($this->select()->where('id = ?', (int) $id));
if (null != $row) {
/** @var Zend_Db_Table_Row $row */
$data = $row->toArray();
$data['skills'] = unserialize($data['skills']);
$data['price'] = unserialize($data['price']);
return $data;
}
return array();
}
/**
* @param $data
* @return array
*/
public function getItemsList($data)
{
$start = (!empty($data['start'])) ? (int) $data['start'] : 0;
$count = (!empty($data['count'])) ? (int) $data['count'] : 100;
unset($data['start'], $data['count']);
$sql = $this->getAdapter()->select()->from($this->_name);
/** @var Zend_Db_Select $sql */
foreach ($data as $key => $value) {
if (isset($this->_cols[$key])) {
$value = $this->filter($value);
$sql->where("{$key} LIKE ?", '%' . $value . '%');
}
}
$sql->limit($count, $start);
$result = $this->getAdapter()->query($sql)->fetchAll();
foreach ($result as &$row) {
$row['skills'] = unserialize($row['skills']);
$row['price'] = unserialize($row['price']);
}
return $result;
}
public function filter($data, $type = 'string')
{
switch ($type) {
case 'string':
default:
$filterStringTrim = new Zend_Filter_StringTrim();
$filterStripTags = new Zend_Filter_StripTags();
$data = $filterStripTags->filter($filterStringTrim->filter($data));
break;
case 'int':
$filterInt = new Zend_Filter_Int();
$data = $filterInt->filter($data);
break;
case 'bool':
$filterBool = new Zend_Filter_Boolean();
$data = $filterBool->filter($data);
break;
}
}
}
class Model_Item_User extends Model_Item
{
protected $_name = 'items-useradd';
}