Example #1
0
 /** 
  * Check that an organisation is OK to commit
  * @since Version 3.2
  * @version 3.2
  * @return boolean
  */
 private function validate()
 {
     if (empty($this->slug)) {
         $this->slug = parent::createSlug();
     }
     if (empty($this->name)) {
         throw new Exception("Organisation name cannot be empty");
     }
     if (empty($this->desc)) {
         throw new Exception("Organisation description cannot be empty");
     }
     if (empty($this->created)) {
         $this->created = time();
     }
     $nulls = ["contact_website", "contact_phone", "contact_fax", "contact_email", "logo", "flickr_photo_id"];
     foreach ($nulls as $var) {
         if (is_null($this->{$var})) {
             $this->{$var} = "";
         }
     }
     return true;
 }
 /**
  * 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'];
                     }
                 }
             }
         }
     }
 }
 /**
  * @depends testAddOrg
  */
 public function testFindOrgs($Organisation)
 {
     $Orgs = new Base();
     $Orgs->search($Organisation->name);
     $Orgs->getOrganisations();
 }