function get_n_users_from_query(&$_search = NULL) { if (!$_search) { $_search = array(); } $query = new FreechSqlQuery(); $sql = "SELECT COUNT(*) FROM {t_user}"; $sql .= " WHERE 1"; foreach ($_search as $key => $value) { if (is_int($value)) { $sql .= " AND {$key}={" . $key . '}'; } else { $sql .= " AND {$key} LIKE {" . $key . '}'; } $query->set_var($key, $value); } $query->set_sql($sql); $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; }
function _delete_permission($_group_id, $_action) { $sql = "DELETE FROM {t_permission}"; $sql .= " WHERE group_id={group_id} AND name={name}"; $query = new FreechSqlQuery($sql); $query->set_var('group_id', $_group_id); $query->set_var('name', $_action); $this->db->_Execute($query->sql()) or die('GroupDB::_delete_permission'); }