public function __construct(PDO $connection = null)
 {
     $this->conn = $connection;
     if ($this->conn === null) {
         $this->conn = PDOFactory::getFactory()->getConnection();
     }
     $this->logger = LoggerFactory::getFactory()->getLogger();
 }
 public function __construct($data)
 {
     if (gettype($data) === "string" || gettype($data) === "integer") {
         //parameter passed was the request ID
         $this->id = $data;
     } elseif (gettype($data) === "object" || gettype($data) === "array") {
         //parameter passed was the model
         $this->model = $data;
     } else {
         throw new Exception("Invalid parameter");
     }
     //Retrieve the logger object from the factory
     self::$logger = LoggerFactory::getFactory()->getLogger();
 }
 /**
  * Verifies that the current instance of this class exists in the database
  * @return bool
  */
 public function exists()
 {
     $conn = PDOFactory::getFactory()->getConnection();
     $logger = LoggerFactory::getFactory()->getLogger();
     if ($matching_conditions = $this->build_where_matching_conditions()) {
         $where_clause = array_shift($matching_conditions);
         $querystring = 'SELECT * FROM gr_people WHERE ' . $where_clause;
         $select_gr_people = $conn->prepare($querystring);
         //Iterate through the matching conditions and bind to the prepared statement
         foreach ($matching_conditions as $variable => $value) {
             $param[] = $variable;
             $param[] =& $value;
             call_user_func_array(array($select_gr_people, 'bindValue'), $param);
             //clear the values of $param
             $param = null;
         }
         //because the query is dynamically created, it is imperative that we verify that it worked
         if (!$select_gr_people->execute()) {
             throw new Exception($update_gr_people->errorInfo()[2]);
         } else {
             if ($select_gr_people->rowCount() > 1) {
                 //Multiple matches.. this should never happen
                 return FALSE;
             } else {
                 if ($select_gr_people->rowCount() === 1) {
                     $person = $select_gr_people->fetch(PDO::FETCH_ASSOC);
                     $this->person_id = $person['person_id'];
                     $logger->debug("1 Found person in database. Person ID (" . $person['person_id'] . ")Matched on the following criteria", $matching_conditions);
                     return TRUE;
                 } else {
                     // 0 matches
                     return FALSE;
                 }
             }
         }
     }
 }