/** * Check for existing groups with the same name * * @param string Name to check * @return string A group name which is unique for the current use */ private function unique_groupname($name) { $checkname = $name; $num = 2; $hit = false; do { $sql_result = $this->db->query("SELECT 1 FROM " . $this->db->table_name($this->db_groups) . " WHERE del<>1" . " AND user_id=?" . " AND name=?", $this->user_id, $checkname); // append number to make name unique if ($hit = $this->db->num_rows($sql_result)) { $checkname = $name . ' ' . $num++; } } while ($hit > 0); return $checkname; }
/** * Create a new saved search record linked with this user * * @param array $data Hash array with col->value pairs to save * * @return int The inserted search ID or false on error */ function insert_search($data) { if (!$this->ID) { return false; } $insert_cols[] = 'user_id'; $insert_values[] = (int) $this->ID; $insert_cols[] = $this->db->quoteIdentifier('type'); $insert_values[] = (int) $data['type']; $insert_cols[] = $this->db->quoteIdentifier('name'); $insert_values[] = $data['name']; $insert_cols[] = $this->db->quoteIdentifier('data'); $insert_values[] = serialize($data['data']); $sql = "INSERT INTO " . $this->db->table_name('searches') . " (" . join(', ', $insert_cols) . ")" . " VALUES (" . join(', ', array_pad(array(), sizeof($insert_values), '?')) . ")"; call_user_func_array(array($this->db, 'query'), array_merge(array($sql), $insert_values)); return $this->db->insert_id('searches'); }