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