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