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 = parent::createNewItem();
48: $oItem->set('idclient', (int) $iClient, false);
49: $oItem->set('idlang', (int) $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: public function getFirstLanguageIdByClient($client) {
115: global $cfg;
116:
117: $sql = "SELECT l.idlang FROM `%s` AS cl, `%s` AS l " . "WHERE cl.idclient = %d AND cl.idlang = l.idlang LIMIT 0,1";
118:
119: $this->db->query($sql, $this->table, $cfg['tab']['lang'], $client);
120:
121: return ($this->db->nextRecord())? (int) $this->db->f('idlang') : null;
122: }
123:
124: }
125:
126: 127: 128: 129: 130: 131:
132: class cApiClientLanguage extends Item {
133:
134: 135: 136: 137: 138:
139: public $idclient;
140:
141: 142: 143: 144: 145:
146: protected $_oPropertyCollection;
147:
148: 149: 150: 151: 152: 153: 154: 155: 156:
157: public function __construct($iIdClientsLang = false, $iIdClient = false, $iIdLang = false) {
158: global $cfg;
159: parent::__construct($cfg['tab']['clients_lang'], 'idclientslang');
160:
161: if ($iIdClientsLang !== false) {
162: $this->loadByPrimaryKey($iIdClientsLang);
163: } elseif ($iIdClient !== false && $iIdLang !== false) {
164: 165: 166: 167: 168: 169: 170:
171:
172:
173: $sSQL = "SELECT %s FROM %s WHERE idclient = '%d' AND idlang = '%d'";
174: $this->db->query($sSQL, $this->primaryKey, $this->table, $iIdClient, $iIdLang);
175: if ($this->db->nextRecord()) {
176: $this->loadByPrimaryKey($this->db->f($this->primaryKey));
177: }
178: }
179: }
180:
181: 182: 183: 184: 185: 186:
187: public function loadByPrimaryKey($iIdClientsLang) {
188: if (parent::loadByPrimaryKey($iIdClientsLang) == true) {
189: $this->idclient = $this->get('idclient');
190: return true;
191: }
192: return false;
193: }
194:
195: 196: 197: 198: 199: 200: 201: 202: 203: 204:
205: public function setProperty($mType, $mName, $mValue, $client = 0) {
206: $oPropertyColl = $this->_getPropertiesCollectionInstance();
207: $oPropertyColl->setValue($this->primaryKey, $this->get($this->primaryKey), $mType, $mName, $mValue, $client);
208: }
209:
210: 211: 212: 213: 214: 215: 216: 217: 218: 219:
220: public function getProperty($mType, $mName, $client = 0) {
221: $oPropertyColl = $this->_getPropertiesCollectionInstance();
222: return $oPropertyColl->getValue($this->primaryKey, $this->get($this->primaryKey), $mType, $mName);
223: }
224:
225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235:
236: public function deleteProperty($idprop, $p2 = null, $client = 0) {
237: $oPropertyColl = $this->_getPropertiesCollectionInstance();
238: $oPropertyColl->delete($idprop);
239: }
240:
241: 242: 243: 244: 245: 246:
247: public function getPropertiesByType($mType) {
248: $oPropertyColl = $this->_getPropertiesCollectionInstance();
249: return $oPropertyColl->getValuesByType($this->primaryKey, $this->idclient, $mType);
250: }
251:
252: 253: 254: 255: 256: 257: 258: 259:
260: public function getProperties() {
261: $itemtype = cSecurity::escapeDB($this->primaryKey, $this->db);
262: $itemid = cSecurity::escapeDB($this->get($this->primaryKey), $this->db);
263: $oPropertyColl = $this->_getPropertiesCollectionInstance();
264: $oPropertyColl->select("itemtype='" . $itemtype . "' AND itemid='" . $itemid . "'", '', 'type, value ASC');
265:
266: if ($oPropertyColl->count() > 0) {
267: $aArray = array();
268:
269: while (($oItem = $oPropertyColl->next()) !== false) {
270: $aArray[$oItem->get('idproperty')]['type'] = $oItem->get('type');
271: $aArray[$oItem->get('idproperty')]['name'] = $oItem->get('name');
272: $aArray[$oItem->get('idproperty')]['value'] = $oItem->get('value');
273: }
274:
275: return $aArray;
276: } else {
277: return false;
278: }
279: }
280:
281: 282: 283: 284: 285: 286:
287: protected function _getPropertiesCollectionInstance($client = 0) {
288:
289: if (!is_object($this->_oPropertyCollection)) {
290: $this->_oPropertyCollection = new cApiPropertyCollection();
291: $this->_oPropertyCollection->changeClient($this->idclient);
292: }
293: return $this->_oPropertyCollection;
294: }
295:
296: }
297: