1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22:
23: class cApiTypeCollection extends ItemCollection {
24:
25: 26: 27:
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['type'], 'idtype');
31: $this->_setItemClass('cApiType');
32: }
33:
34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:
46: public function create($type, $description, $code = '', $status = 0, $author = '', $created = '', $lastmodified = '') {
47: global $auth;
48:
49: if (empty($author)) {
50: $author = $auth->auth['uname'];
51: }
52: if (empty($created)) {
53: $created = date('Y-m-d H:i:s');
54: }
55: if (empty($lastmodified)) {
56: $lastmodified = date('Y-m-d H:i:s');
57: }
58:
59: $item = $this->createNewItem();
60:
61: $item->set('type', $type);
62: $item->set('description', $description);
63: $item->set('code', $code);
64: $item->set('status', $status);
65: $item->set('author', $author);
66: $item->set('created', $created);
67: $item->set('lastmodified', $lastmodified);
68: $item->store();
69:
70: return $item;
71: }
72:
73: }
74:
75: 76: 77: 78: 79: 80:
81: class cApiType extends Item {
82:
83: 84: 85: 86: 87: 88:
89: public function __construct($id = false) {
90: global $cfg;
91: parent::__construct($cfg['tab']['type'], 'idtype');
92: $this->setFilters(array(), array());
93: if ($id !== false) {
94: $this->loadByPrimaryKey($id);
95: }
96: }
97:
98: 99: 100: 101: 102: 103: 104:
105: public function loadByType($type) {
106: $aProps = array(
107: 'type' => $type
108: );
109: $aRecordSet = $this->_oCache->getItemByProperties($aProps);
110: if ($aRecordSet) {
111:
112: $this->loadByRecordSet($aRecordSet);
113: return true;
114: } else {
115: $where = $this->db->prepare("type = '%s'", $type);
116: return $this->_loadByWhereClause($where);
117: }
118: }
119:
120: 121: 122: 123: 124: 125: 126: 127: 128: 129:
130: public function setField($name, $value, $safe = true) {
131: if ('status' === $name) {
132: $value = (int) $value;
133: }
134:
135: return parent::setField($name, $value, $safe);
136: }
137:
138: }
139: