/**
  * 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'];
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Constructor
  * @since Version 3.2
  * @version 3.7.5
  * @param object $db
  * @param int $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = filter_var($id, FILTER_VALIDATE_INT);
     } else {
         $this->id = $this->db->fetchOne("SELECT organisation_id FROM organisation WHERE organisation_slug = ?", $id);
     }
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         $this->id = intval($this->id);
         $this->populate();
     }
 }