id_parent = $id_parent; $this->fieldsCont = (array)$fieldsCont; } function _getContArr($data, $lang) { $arr = array(); foreach ($this->fieldsCont as $field) { if (isset($data[$field][$lang])){ $arr[$field] = $data[$field][$lang]; } } return $arr; } function save($data) { require_once 'class/DB/Lang/DLang.php'; $DLang = new DLang(); foreach ($DLang->getList() as $lang){ $cont = $this->_getContArr($data, $lang['name']); $cont['lang'] = $lang['name']; $cont['id_parent'] = $this->id_parent; $where = "id_parent = ". $this->db->quote( $cont['id_parent'], 'integer' ). ' AND lang = '. $this->db->quote( $lang['name'] ); $sql = "SELECT COUNT(*) FROM {$this->table} WHERE {$where} "; if ($this->db->queryOne($sql)){ parent::update($cont, $where); }else { parent::insert($cont); } } return true; } function delete($where = '') { if (empty($where)){ $where = '1'; } $where .= ' AND id_parent = '.$this->db->quote($this->id_parent, 'integer'); return parent::delete($where); } function get() { $out = array(); $sql = "SELECT lang, ".implode(', ', $this->fieldsCont)." FROM {$this->table} WHERE id_parent = ".$this->db->quote($this->id_parent, 'integer'); $list = $this->db->queryAll($sql); // vdie($list, $sql); foreach ($list as $itm){ foreach ($this->fieldsCont as $field) { $out[$field][ $itm['lang'] ] = $itm[$field]; } } return $out; } } ?>