static function for_query($query) { $db = Get::db('songwork'); $res = array(); $db->query($query); while ($x = $db->next_record()) { $res[$x['id']] = new Consultation($x); } return $res; }
static function popular() { $db = Get::db('songwork'); $res = array(); $db->query("SELECT id, name, COUNT(*) FROM documents_tags LEFT JOIN tags ON documents_tags.tag_id=tags.id GROUP BY id, name ORDER BY COUNT(*) DESC"); while ($x = $db->next_record()) { $res[$x['id']] = new Tag($x); } return $res; }
static function get_by_person($p) { if (!is_a($p, 'Person') || intval($p->id) == 0) { return false; } $db = Get::db('songwork'); $db->query("SELECT * FROM admins WHERE person_id=" . $p->id); if ($db->num_rows() == 0) { return false; } $x = new Administrator($db->next_record()); $x->set_person($p); return $x; }
function __construct($id_or_array) { $this->db = Get::db($this->dbname); if (is_array($id_or_array)) { $this->me = $id_or_array; $this->id = intval($id_or_array['id']); } elseif (is_int($id_or_array) || is_string($id_or_array) && ctype_digit($id_or_array)) { $this->id = intval($id_or_array); $this->db->query("SELECT * FROM {$this->tablename} WHERE id=" . $this->id); if ($this->db->num_rows() == 0) { $this->failed = true; } $this->me = $this->db->next_record(); } }
function testCookie() { $p = new Person(3); $p->set_auth(); # get what the cookie would have been $db = Get::db('songwork'); $db->query("SELECT * FROM logins WHERE person_id=3"); $x = $db->next_record(); $cookie_value = $x['cookie_id'] . ':' . $x['cookie_tok']; $_COOKIE['ok'] = $cookie_value; $p = Person::get_by_cookie(); $this->assertType('Person', $p); $this->assertEquals(3, $p->id); $this->assertEquals('Yoko', $p->firstname()); $_COOKIE['ok'] = $cookie_value . 'x'; $p = Person::get_by_cookie(); $this->assertFalse($p); }
static function with_ids($array_of_ids) { # clean incoming array, just in case of bad info $real_ids = array(); foreach ($array_of_ids as $maybe_id) { if (is_integer($maybe_id) || is_string($maybe_id) && ctype_digit($maybe_id)) { $real_ids[] = intval($maybe_id); } } if (count($real_ids) == 0) { return array(); } $db = Get::db('songwork'); $res = array(); $db->query("SELECT * FROM persons WHERE id IN (" . join(',', $real_ids) . ")"); while ($x = $db->next_record()) { $res[$x['id']] = new Person($x); } return $res; }
static function pulldown_for_currency($currency) { if (!Currency::is_valid($currency)) { return false; } $res = array(); $db = Get::db('songwork'); $db->query("SELECT code, millicents FROM pricerefs WHERE currency='{$currency}' ORDER BY millicents ASC"); while ($x = $db->next_record()) { $m = new Money($x['millicents'], $currency); $res[$x['code']] = $m->show_with_code(); } return $res; }
static function consultable() { $db = Get::db('songwork'); $res = array(); $db->query("SELECT * FROM teachers WHERE available='t' ORDER BY id ASC"); while ($x = $db->next_record()) { $res[$x['id']] = new Teacher($x); } return $res; }
static function all() { $db = Get::db('songwork'); $res = array(); $db->query("SELECT * FROM students ORDER BY id DESC"); while ($x = $db->next_record()) { $res[$x['id']] = new Student($x); } return $res; }