tableName . '`.*, `ContactGroup`.`title` AS `group_title` '; return $sql; } function _getJoin4Grid() { $sql = 'JOIN `' . $this->tableNameDB . '2Group` AS `ContactPerson2Group` ' . 'ON `ContactPerson2Group`.`id_person` = `' . $this->tableName . '`.`id` '; $sql .= 'JOIN `' . $this->db->tblContactGroup . '` AS `ContactGroup` ' . 'ON `ContactGroup`.`id` = `ContactPerson2Group`.`id_group` '; return $sql; } function _getGroup4Grid() { $sql = 'GROUP BY `' . $this->tableName . '`.`id` '; return $sql; } function getFromDB($id, $field = false) { $data = parent::getFromDB($id); $data['groups'] = $this->_getDependencyFromDb( $this->db->tblContactGroup, 'id', $this->tableNameDB . '2Group', 'id_person', 'id_group', $id ); return $this->getSubElem($data, $field); } function insert($data = null, $files = null) { if (!is_null($data)) { $this->initFromArray($data, $files); } $this->_initTable(); $data = $this->_data; unset($data['id']); $this->id = $this->table->insert($data); $this->updateIds($this->tableNameDB . '2Group', 'id_person', 'id_group', $this->_data['groups']); $this->handleFiles(); return $this->id; } function update($data = null, $files = null) { if (!is_null($data)) { $this->initFromArray($data, $files); } $this->_initTable(); $this->table->update($this->_data, 'id = '. $this->db->quote($this->id, 'integer') ); $this->updateIds($this->tableNameDB . '2Group', 'id_person', 'id_group', $this->_data['groups']); $this->handleFiles(); return true; } function delete() { $this->deleteIds($this->tableNameDB . '2Group', 'id_person'); parent::delete(); } function setFilter($filter) { if (isset($filter['query'])) { $this->_filterQuery = (string)$filter['query']; unset($filter['query']); } $this->_filter = $filter; } function _filterSql() { require_once('class/DB/DBObj/Filter.php'); if (false === ($sql = DBObj_Filter::perseQr($this->db, $this->_filterFields, $this->_filterQuery))) { $sql = ''; } foreach ($this->_filter as $field => $value) { if (empty($value)) { continue; } switch ($field) { case 'id_group': $sql .= ' AND `' . $this->tableName . '2Group`.`' . $field . '` = ' . $this->db->quote($value, 'integer'); break; } } return empty($sql) ? false : $sql; } public function getFilter($field = false) { if (false === $field) { return $this->_filter; } if (array_key_exists($field, $this->_filter)) { return $this->_filter[$field]; } return null; } function truncate() { $sql = 'TRUNCATE TABLE `' . $this->tableNameDB . '`'; $this->db->query($sql); $sql = 'TRUNCATE TABLE `' . $this->tableNameDB . '2Group`'; $this->db->query($sql); } }