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