/** * Moves the entire thread from the given forum into another forum. */ function move_thread($_thread_id, $_forum_id) { $this->db->StartTrans(); $sql = 'UPDATE {t_thread} SET forum_id={forum_id} WHERE id={id}'; $query = new FreechSqlQuery($sql); $query->set_int('id', $_thread_id); $query->set_int('forum_id', $_forum_id); $this->db->_Execute($query->sql()) or die('ForumDB::move_thread(): 1'); $sql = 'UPDATE {t_posting} SET forum_id={forum_id}'; $sql .= ' WHERE thread_id={id}'; $query->set_sql($sql); $this->db->_Execute($query->sql()) or die('ForumDB::move_thread(): 2'); $this->db->CompleteTrans(); }
/** * Returns the number of all users whose name is similar to the * given one. * $_name: The name for which to find similar users. */ function count_similar_users_from_name($_name) { if (!$_name) { die('UserDB::count_similar_users_from_name(): Invalid name.'); } $user = new User(); $user->set_name($_name); $soundex = $user->get_soundexed_name(); $query = new FreechSqlQuery(); $sql = "SELECT COUNT(*) FROM {t_user}"; $sql .= " WHERE soundexname={soundexname}"; $query->set_sql($sql); $query->set_string('soundexname', $soundex); $n_users = $this->db->GetOne($query->sql()); if (!$n_users) { return 0; } return $n_users; }
/** * Returns all items that match the given criteria. * $_search: The search values. */ function &get_items_from_query(&$_search, $_limit = -1, $_offset = 0) { // Get a list of item ids. $query = new FreechSqlQuery(); $sql = 'SELECT m.id'; $sql .= ' FROM {t_modlog} m'; $sql .= ' WHERE 1'; foreach ($_search as $key => $value) { if (is_int($value)) { $sql .= " AND m.{$key}={" . $key . '}'; } else { $sql .= " AND m.{$key} LIKE {" . $key . '}'; } $query->set_var($key, $value); } $sql .= ' ORDER BY m.id DESC'; $query->set_sql($sql); $res = $this->db->SelectLimit($query->sql(), (int) $_limit, (int) $_offset); // Now fetch the items, including attributes. $sql = 'SELECT m.*,'; $sql .= ' a.attribute_name,a.attribute_type,a.attribute_value,'; $sql .= ' UNIX_TIMESTAMP(m.created) created'; $sql .= ' FROM {t_modlog} m'; $sql .= ' LEFT JOIN {t_modlog_attribute} a ON a.modlog_id=m.id'; $sql .= ' WHERE 0'; while (!$res->EOF) { $row = $res->FetchObj(); $sql .= ' OR m.id=' . $row->id; $res->MoveNext(); } $sql .= ' ORDER BY m.id DESC'; $query = new FreechSqlQuery($sql); $res = $this->db->_Execute($query->sql()); $list = array(); while ($item = $this->_pop_item_from_result($res)) { array_push($list, $item); } return $list; }
/** * Insert a new group or save an existing one. * * $_group: The group to be saved. * Returns: The id of the (maybe newly inserted) group. */ function save_group(&$_group) { if (!is_object($_group)) { die('GroupDB::save_group(): Invalid arg.'); } $query = new FreechSqlQuery(); $query->set_int('id', $_group->get_id()); $query->set_string('name', $_group->get_name()); $query->set_bool('is_special', $_group->is_special()); $query->set_int('status', $_group->get_status()); if ($_group->get_id() < 1) { $sql = "INSERT INTO {t_group}"; $sql .= " ("; $sql .= " id, name, is_special, status, created"; $sql .= " )"; $sql .= " VALUES ("; $sql .= " {id}, {name}, {is_special}, {status}, NULL"; $sql .= " )"; $query->set_sql($sql); $this->db->StartTrans(); $this->db->_Execute($query->sql()) or die('GroupDB::save_group: Ins'); $newid = $this->db->Insert_ID(); $_group->set_id($newid); $this->_save_permissions($_group); $this->db->CompleteTrans(); return $newid; } $sql = "UPDATE {t_group} SET"; $sql .= " id={id},"; $sql .= " name={name},"; $sql .= " is_special={is_special},"; $sql .= " status={status}"; $sql .= " WHERE id={id}"; $query->set_sql($sql); $this->db->StartTrans(); $this->db->_Execute($query->sql()) or die('GroupDB::save_group(): Upd'); $this->_save_permissions($_group); $this->db->CompleteTrans(); return $_group->get_id(); }