/** * Constructor * @since Version 3.2 * @version 3.7.5 * @param object $db * @param int $id */ public function __construct() { foreach (func_get_args() as $arg) { if (filter_var($arg, FILTER_VALIDATE_INT)) { $this->id = $arg; } } try { parent::__construct(); } catch (Exception $e) { throw new Exception($e->getMessage()); } if ($this->id) { // Retrieve this organisation from the database if ($this->db instanceof \sql_db) { $query = "SELECT o.* FROM organisation AS o WHERE organisation_id = " . $this->db->real_escape_string($this->id); if ($rs = $this->db->query($query)) { $row = $rs->fetch_assoc(); // Populate the vars above $this->name = $row['organisation_name']; $this->desc = $row['organisation_desc']; $this->created = $row['organisation_dateadded']; $this->owner = $row['organisation_owner']; $this->contact_website = $row['organisation_website']; $this->contact_phone = $row['organisation_phone']; $this->contact_fax = $row['organisation_fax']; $this->contact_email = $row['organisation_email']; $this->logo = $row['organisation_logo']; $this->flickr_photo_id = $row['flickr_photo_id']; // Get the roles for this org $query = "SELECT * FROM organisation_roles WHERE organisation_id = " . $this->db->real_escape_string($this->id); if ($rs = $this->db->query($query)) { while ($row = $rs->fetch_assoc()) { $this->roles[$row['role_id']] = $row['role_name']; } } else { throw new Exception($this->db->error . "\n" . $query); } } else { throw new Exception("Could not find organisation ID " . $this->id); throw new Exception($this->db->error . "\n" . $query); } } else { $query = "SELECT o.* FROM organisation AS o WHERE organisation_id = ?"; if ($row = $this->db->fetchRow($query, $this->id)) { $this->name = $row['organisation_name']; $this->desc = $row['organisation_desc']; $this->created = $row['organisation_dateadded']; $this->owner = $row['organisation_owner']; $this->contact_website = $row['organisation_website']; $this->contact_phone = $row['organisation_phone']; $this->contact_fax = $row['organisation_fax']; $this->contact_email = $row['organisation_email']; $this->logo = $row['organisation_logo']; $this->flickr_photo_id = $row['flickr_photo_id']; $this->slug = $row['organisation_slug']; if (empty($this->slug)) { $this->slug = parent::createSlug(); } $this->url = parent::makePermaLink($this->slug); // Get the roles for this organisation $query = "SELECT * FROM organisation_roles WHERE organisation_id = ?"; if ($result = $this->db->fetchAll($query, $this->id)) { foreach ($result as $row) { $this->roles[$row['role_id']] = $row['role_name']; } } } } } }
/** * Populate this object * @since Version 3.9.1 * @return void */ private function populate() { $timer = Debug::getTimer(); $this->mckey = sprintf("railpage:organisations.organisation=%d", $this->id); if (!($row = $this->Memcached->fetch($this->mckey))) { $query = "SELECT o.* FROM organisation AS o WHERE organisation_id = ?"; $row = $this->db->fetchRow($query, $this->id); $this->Memcached->save($this->mckey, $row); } $lookup = ["name" => "organisation_name", "desc" => "organisation_desc", "created" => "organisation_dateadded", "owner" => "organisation_owner", "contact_website" => "organisation_website", "contact_phone" => "organisation_phone", "contact_fax" => "organisation_fax", "contact_email" => "organisation_email", "loco" => "organisation_logo", "flickr_photo_id" => "flickr_photo_id", "slug" => "organisation_slug"]; foreach ($lookup as $var => $val) { $this->{$var} = $row[$val]; } /* $this->name = $row['organisation_name']; $this->desc = $row['organisation_desc']; $this->created = $row['organisation_dateadded']; $this->owner = $row['organisation_owner']; $this->contact_website = $row['organisation_website']; $this->contact_phone = $row['organisation_phone']; $this->contact_fax = $row['organisation_fax']; $this->contact_email = $row['organisation_email']; $this->logo = $row['organisation_logo']; $this->flickr_photo_id = $row['flickr_photo_id']; $this->slug = $row['organisation_slug']; */ if (empty($this->slug)) { $this->slug = parent::createSlug(); } $this->url = parent::makePermaLink($this->slug); $this->loadRoles(); Debug::logEvent(__METHOD__, $timer); }