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 cApiLanguageCollection extends ItemCollection {
24:
25: 26: 27:
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['lang'], 'idlang');
31: $this->_setItemClass('cApiLanguage');
32: }
33:
34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
44: public function create($name, $active, $encoding, $direction) {
45: global $auth;
46:
47: $item = $this->createNewItem();
48:
49: $item->set('name', $name, false);
50: $item->set('active', $active, false);
51: $item->set('encoding', $encoding, false);
52: $item->set('direction', $direction, false);
53: $item->set('author', $auth->auth['uid'], false);
54: $item->set('created', date('Y-m-d H:i:s'), false);
55: $item->set('lastmodified', '0000-00-00 00:00:00', false);
56: $item->store();
57:
58: return $item;
59: }
60:
61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71:
72: public function nextAccessible() {
73: global $perm, $client, $lang;
74:
75: $item = $this->next();
76:
77: $lang = (int) $lang;
78: $client = (int) $client;
79:
80: if ($item === false) {
81: return false;
82: }
83:
84: $clientsLanguageColl = new cApiClientLanguageCollection();
85: $clientsLanguageColl->select('idlang = ' . $item->get("idlang"));
86: if (($clientsLang = $clientsLanguageColl->next()) !== false) {
87: if ($client != $clientsLang->get('idclient')) {
88: $item = $this->nextAccessible();
89: }
90: }
91:
92: if ($item) {
93: if ($perm->have_perm_client('lang[' . $item->get('idlang') . ']') || $perm->have_perm_client('admin[' . $client . ']') || $perm->have_perm_client()) {
94:
95: } else {
96: $item = $this->nextAccessible();
97: }
98:
99: return $item;
100: } else {
101: return false;
102: }
103: }
104:
105: 106: 107: 108: 109: 110: 111: 112:
113: public function getLanguageName($idlang) {
114: $item = new cApiLanguage($idlang);
115: if ($item->isLoaded()) {
116: return $item->get('name');
117: } else {
118: return i18n('No language');
119: }
120: }
121:
122: }
123:
124: 125: 126: 127: 128: 129:
130: class cApiLanguage extends Item {
131: 132: 133: 134:
135: protected static $_propertiesCache = array();
136:
137: 138: 139: 140:
141: protected static $_propertiesCacheLoaded = array();
142:
143: 144: 145: 146: 147: 148:
149: public function __construct($mId = false) {
150: global $cfg;
151: parent::__construct($cfg['tab']['lang'], 'idlang');
152: $this->setFilters(array(), array());
153: if ($mId !== false) {
154: $this->loadByPrimaryKey($mId);
155: }
156: }
157:
158: 159: 160: 161: 162:
163: public function store() {
164: $this->set('lastmodified', date('Y-m-d H:i:s'), false);
165: return parent::store();
166: }
167:
168: 169: 170: 171: 172: 173: 174: 175: 176:
177: public function setField($name, $value, $bSafe = true) {
178: switch ($name) {
179: case 'active':
180: $value = (int) $value;
181: break;
182: }
183:
184: return parent::setField($name, $value, $bSafe);
185: }
186:
187: 188: 189: 190: 191: 192:
193: protected function _loadProperties($idclient = 0) {
194:
195: if (!isset(self::$_propertiesCacheLoaded[$idclient])) {
196:
197: self::$_propertiesCache[$idclient] = array();
198:
199: $itemtype = $this->db->escape($this->getPrimaryKeyName());
200: $itemid = $this->db->escape($this->get($this->getPrimaryKeyName()));
201:
202: $propColl = $this->_getPropertiesCollectionInstance($idclient);
203: $propColl->select("itemtype='$itemtype' AND itemid='$itemid'", '', 'type, value ASC');
204:
205: if (0 < $propColl->count()) {
206:
207: while (false !== $item = $propColl->next()) {
208:
209: $type = $item->get('type');
210: if (!isset(self::$_propertiesCache[$idclient][$type])) {
211: self::$_propertiesCache[$idclient][$type] = array();
212: }
213:
214: $name = $item->get('name');
215: $value = $item->get('value');
216: self::$_propertiesCache[$idclient][$type][$name] = $value;
217: }
218: }
219: }
220:
221: self::$_propertiesCacheLoaded[$idclient] = true;
222: }
223:
224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235:
236: public function getProperty($type, $name, $idclient = 0) {
237:
238:
239: if (true !== $this->isLoaded()) {
240: $this->lasterror = 'No item loaded';
241: return false;
242: }
243:
244: $this->_loadProperties($idclient);
245:
246: if (isset(
247: self::$_propertiesCache[$idclient],
248: self::$_propertiesCache[$idclient][$type],
249: self::$_propertiesCache[$idclient][$type][$name]
250: )) {
251: return self::$_propertiesCache[$idclient][$type][$name];
252: } else {
253: return false;
254: }
255: }
256:
257: }