tableName}.*, IFNULL(Individual2Rss.sorter, '') as individual_sorter, IFNULL(Individual2Rss.active, 'y') as individual_active "; } function _getJoin4Grid() { return " LEFT JOIN {$this->db->tblMember2Rss} as Individual2Rss ON Individual2Rss.id_parent = ".$this->db->quote($this->memberData['id'], 'integer')." AND Individual2Rss.id_rss = {$this->tableName}.id "; } function _getWhere4Grid($opt = array()) { $where = DBObj::_getWhere4Grid($opt); $where .= " AND {$this->tableName}.id_individual IN (0, ".$this->db->quote($this->memberData['id'], 'integer').') '.$this->addonWhere; return $where; } function initFromForm(&$frm) { $files = array(); $data = $frm->exportValues(); $data['id_individual'] = intval($this->memberData['id']); $this->arrayParseUrl2Tag($data); $this->initFromArray($data, $files); return true; } function insert($data = null, $files = null) { if (!is_null($data)) { $this->initFromArray($data, $files); } $this->_initTable(); $data = $this->_data; unset($data['id']); $fields = $this->getSimpleFieldList(); $this->id = $this->table->insert($data); if (isset($fields['sorter'])) { $data['sorter'] = $this->getSorter(" 1 AND id_parent = ".$this->db->quote($this->memberData['id'], 'integer'), 'sorter', $this->db->tblMember2Rss); if ($data['sorter'] == 0) { $data['sorter'] = 1; } } $individualRssData = array(); $individualRssData['id_parent'] = $this->db->quote($this->memberData['id'], 'integer'); $individualRssData['id_rss'] = $this->id; $individualRssData['sorter'] = $data['sorter']; $individualRssData['active'] = $data['active']; require_once('class/DB/DBTable.php'); $Individual2Rss = new DBTable('Member2Rss'); $Individual2Rss->insert($individualRssData); $this->handleFiles(); return $this->id; } function reorder($list) { require_once('class/DB/DBTable.php'); $table = new DBTable('Member2Rss'); foreach ((array)$list as $sorter => $id) { $sql = " SELECT COUNT(*) FROM {$this->db->tblMember2Rss} WHERE id_parent = ".$this->db->quote($this->memberData['id'], 'integer') ." AND id_rss = ".(int)$id; $cnt = (int)$this->db->queryOne($sql); //vdie($cnt, $sql); if (!$cnt) { $table->insert(array( 'id_parent' => $this->db->quote($this->memberData['id'], 'integer'), 'id_rss' => $id, 'active' => 'y', 'sorter' => $sorter + 1 )); } else { $table->update(array('sorter'=>$sorter + 1), 'id_parent = '.$this->db->quote($this->memberData['id'], 'integer') .' AND id_rss = '.$this->db->quote($id) ); } } return true; } function changeOption($opt) { if (!strlen($opt)) return false; $opt = $this->db->quote($opt); $opt = substr($opt, 1, strlen($opt)-2); $table = $this->db->tblMember2Rss; $field = $this->db->queryRow("SHOW COLUMNS FROM {$table} LIKE '%{$opt}%'"); if (!isset($field['field'])) return false; if (strncmp($field['type'], 'enum', 4)!=0) return false; eval("\$arrValues = ".str_replace('enum', 'array', $field['type']).';'); $sql = "SELECT `$opt` FROM {$table} WHERE id_parent = ".$this->db->quote($this->memberData['id'], 'integer') ." AND id_rss = ".$this->db->quote($this->id); $val = $this->db->queryOne($sql); if ($val === null) { require_once('class/DB/DBTable.php'); $tbl = new DBTable('Member2Rss'); $tbl->insert(array( 'id_parent' => $this->db->quote($this->memberData['id'], 'integer'), 'id_rss' => $this->id, 'active' => 'y', 'sorter' => null )); $val = 'y'; } $valPos = array_search($val, $arrValues); $val = ((isset($arrValues[$valPos+1])))?$arrValues[$valPos+1]:$arrValues[0]; $sorter = 'NULL'; if ($val == 'y') { $sql = " SELECT MAX(sorter) FROM {$this->db->tblMember2Rss} WHERE id_parent = ".$this->db->quote($this->memberData['id'], 'integer')." "; $sorter = (int)$this->db->queryOne($sql) + 1; } $sql = " UPDATE {$table} SET `$opt` = ".$this->db->quote($val).", `sorter` = {$sorter} WHERE id_parent = ".$this->db->quote($this->memberData['id'], 'integer')." AND id_rss = " . $this->db->quote($this->id)." LIMIT 1 "; $res = $this->db->query($sql); $this->_sqlError($res); } }