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 cApiClientLanguageCollection extends ItemCollection {
25:
26: 27: 28:
29: public function __construct() {
30: global $cfg;
31: parent::__construct($cfg['tab']['clients_lang'], 'idclientslang');
32: $this->_setItemClass('cApiClientLanguage');
33:
34:
35: $this->_setJoinPartner('cApiClientCollection');
36: $this->_setJoinPartner('cApiLanguageCollection');
37: }
38:
39: 40: 41: 42: 43: 44: 45:
46: public function create($iClient, $iLang) {
47: $oItem = $this->createNewItem();
48: $oItem->set('idclient', $iClient, false);
49: $oItem->set('idlang', $iLang, false);
50: $oItem->store();
51: return $oItem;
52: }
53:
54: 55: 56: 57: 58: 59: 60:
61: public function hasLanguageInClients($iLang, array $aClientIds) {
62: $iLang = (int) $iLang;
63: $aClientIds = array_map('intval', $aClientIds);
64: $sWhere = 'idlang=' . $iLang . ' AND idclient IN (' . implode(',', $aClientIds) . ')';
65: return $this->flexSelect('', '', $sWhere);
66: }
67:
68: 69: 70: 71: 72: 73:
74: public function getLanguagesByClient($client) {
75: $list = array();
76: $sql = "SELECT idlang FROM `%s` WHERE idclient=%d";
77: $this->db->query($sql, $this->table, $client);
78: while ($this->db->nextRecord()) {
79: $list[] = $this->db->f("idlang");
80: }
81: return $list;
82: }
83:
84: 85: 86: 87: 88: 89: 90:
91: public function getLanguageNamesByClient($client) {
92: global $cfg;
93:
94: $list = array();
95: $sql = "SELECT l.idlang AS idlang, l.name AS name
96: FROM `%s` AS cl, `%s` AS l
97: WHERE idclient=%d AND cl.idlang = l.idlang
98: ORDER BY idlang ASC";
99:
100: $this->db->query($sql, $this->table, $cfg['tab']['lang'], $client);
101: while ($this->db->nextRecord()) {
102: $list[$this->db->f('idlang')] = $this->db->f('name');
103: }
104:
105: return $list;
106: }
107:
108: 109: 110: 111: 112: 113: 114: 115:
116: public function getAllLanguagesByClient($client) {
117: global $cfg;
118:
119: $list = array();
120: $sql = "SELECT *
121: FROM `%s` AS cl, `%s` AS l
122: WHERE cl.idclient=%d AND cl.idlang = l.idlang
123: ORDER BY l.idlang ASC";
124:
125: $this->db->query($sql, $this->table, $cfg['tab']['lang'], $client);
126: while ($this->db->nextRecord()) {
127: $list[$this->db->f('idlang')] = $this->db->toArray();
128: }
129:
130: return $list;
131: }
132:
133: 134: 135: 136: 137: 138:
139: public function getFirstLanguageIdByClient($client) {
140: global $cfg;
141:
142: $sql = "SELECT l.idlang FROM `%s` AS cl, `%s` AS l " . "WHERE cl.idclient = %d AND cl.idlang = l.idlang LIMIT 0,1";
143:
144: $this->db->query($sql, $this->table, $cfg['tab']['lang'], $client);
145:
146: return ($this->db->nextRecord()) ? (int) $this->db->f('idlang') : NULL;
147: }
148: }
149:
150: 151: 152: 153: 154: 155:
156: class cApiClientLanguage extends Item {
157:
158: 159: 160: 161: 162:
163: public $idclient;
164:
165: 166: 167: 168: 169:
170: protected $_oPropertyCollection;
171:
172: 173: 174: 175: 176: 177: 178: 179: 180:
181: public function __construct($iIdClientsLang = false, $iIdClient = false, $iIdLang = false) {
182: global $cfg;
183: parent::__construct($cfg['tab']['clients_lang'], 'idclientslang');
184:
185: if ($iIdClientsLang !== false) {
186: $this->loadByPrimaryKey($iIdClientsLang);
187: } elseif ($iIdClient !== false && $iIdLang !== false) {
188: 189: 190: 191: 192: 193: 194:
195:
196:
197: $sSQL = "SELECT %s FROM %s WHERE idclient = '%d' AND idlang = '%d'";
198: $this->db->query($sSQL, $this->primaryKey, $this->table, $iIdClient, $iIdLang);
199: if ($this->db->nextRecord()) {
200: $this->loadByPrimaryKey($this->db->f($this->primaryKey));
201: }
202: }
203: }
204:
205: 206: 207: 208: 209: 210:
211: public function loadByPrimaryKey($iIdClientsLang) {
212: if (parent::loadByPrimaryKey($iIdClientsLang) == true) {
213: $this->idclient = $this->get('idclient');
214: return true;
215: }
216: return false;
217: }
218:
219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229:
230: public function setProperty($mType, $mName, $mValue, $client = 0) {
231: $oPropertyColl = $this->_getPropertiesCollectionInstance();
232: $oPropertyColl->setValue($this->primaryKey, $this->get($this->primaryKey), $mType, $mName, $mValue, $client);
233: }
234:
235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245:
246: public function getProperty($mType, $mName, $client = 0) {
247: $oPropertyColl = $this->_getPropertiesCollectionInstance();
248: return $oPropertyColl->getValue($this->primaryKey, $this->get($this->primaryKey), $mType, $mName);
249: }
250:
251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261:
262: public function deleteProperty($idprop, $p2 = NULL, $client = 0) {
263: $oPropertyColl = $this->_getPropertiesCollectionInstance();
264: $oPropertyColl->delete($idprop);
265: }
266:
267: 268: 269: 270: 271: 272:
273: public function getPropertiesByType($mType) {
274: $oPropertyColl = $this->_getPropertiesCollectionInstance();
275: return $oPropertyColl->getValuesByType($this->primaryKey, $this->idclient, $mType);
276: }
277:
278: 279: 280: 281: 282: 283: 284:
285: public function getProperties() {
286: $itemtype = $this->db->escape($this->primaryKey);
287: $itemid = $this->db->escape($this->get($this->primaryKey));
288: $oPropertyColl = $this->_getPropertiesCollectionInstance();
289: $oPropertyColl->select("itemtype='" . $itemtype . "' AND itemid='" . $itemid . "'", '', 'type, value ASC');
290:
291: if ($oPropertyColl->count() > 0) {
292: $aArray = array();
293:
294: while (($oItem = $oPropertyColl->next()) !== false) {
295: $aArray[$oItem->get('idproperty')]['type'] = $oItem->get('type');
296: $aArray[$oItem->get('idproperty')]['name'] = $oItem->get('name');
297: $aArray[$oItem->get('idproperty')]['value'] = $oItem->get('value');
298: }
299:
300: return $aArray;
301: } else {
302: return false;
303: }
304: }
305:
306: 307: 308: 309: 310: 311: 312:
313: protected function _getPropertiesCollectionInstance($client = 0) {
314:
315: if (!is_object($this->_oPropertyCollection)) {
316: $this->_oPropertyCollection = new cApiPropertyCollection();
317: $this->_oPropertyCollection->changeClient($this->idclient);
318: }
319: return $this->_oPropertyCollection;
320: }
321:
322: 323: 324: 325: 326: 327: 328:
329: public function setField($name, $value, $bSafe = true) {
330: switch ($name) {
331: case 'idclient':
332: $value = (int) $value;
333: break;
334: case 'idlang':
335: $value = (int) $value;
336: break;
337: }
338:
339: return parent::setField($name, $value, $bSafe);
340: }
341:
342: }
343: