-
Notifications
You must be signed in to change notification settings - Fork 1
/
Item.php
92 lines (82 loc) · 1.87 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
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Item Model
*
* @package MG/Item
* @category Model
* @author Maxim Kerstens
* @copyright (c) 2013 Modular Gaming
* @license BSD http://www.modulargaming.com/license
*/
class MG_Model_Item extends ORM {
protected $_table_columns = array(
'id' => NULL,
'type_id' => NULL,
'name' => NULL,
'description' => NULL,
'image' => NULL,
'status' => NULL,
'unique' => NULL,
'transferable' => NULL,
'commands' => NULL,
);
protected $_belongs_to = array(
'type' => array(
'model' => 'Item_Type',
'foreign_key' => 'type_id'
),
);
protected $_serialize_columns = array('commands');
protected $_load_with = array('type');
public function rules()
{
return array(
'name' => array(
array('not_empty'),
array('max_length', array(':value', 50)),
),
'description' => array(
array('not_empty'),
),
'image' => array(
array('not_empty'),
array('max_length', array(':value', 200)),
),
'status' => array(
array('not_empty'),
array('in_array', array(':value', array('draft', 'released', 'retired'))),
),
'commands' => array(
array('not_empty'),
array('Item::validate_commands', array(':validation', ':value'))
)
);
}
/**
* Create the url to the item's image
* @return string
*/
public function img()
{
return URL::site('media/image/items/'.$this->type->img_dir.$this->image);
}
/**
* Check if the item isn't a draft or retired.
* @return boolean
*/
public function in_circulation()
{
return ($this->status == 'released');
}
/**
* Get the item's name based on an amount
*
* @param integer $amount
*
* @return string
*/
public function name($amount)
{
return $amount.' '.Inflector::plural($this->name, $amount);
}
} // End Item Model