public function __construct(PDO $connection = null) { $this->conn = $connection; if ($this->conn === null) { $this->conn = PDOFactory::getFactory()->getConnection(); } $this->logger = LoggerFactory::getFactory()->getLogger(); }
private function fetchRecipients() { $recipients = array(); //Get a database connection $conn = PDOFactory::getFactory()->getConnection(); //Query the appEmail database for all recipients of this type $selectRecipients = $conn->prepare("SELECT * FROM appEmail WHERE requestType = :requestType AND isActive = '1'"); $selectRecipients->bindParam(":requestType", $this->requestType); $selectRecipients->execute(); if ($selectRecipients->rowCount() > 0) { while ($row = $selectRecipients->fetch(PDO::FETCH_ASSOC)) { $recipients[] = $row['emailAddress']; } } return $recipients; }
/** * Retrieves an array of the subawards in format for the model */ private function getSubawards() { $conn = PDOFactory::getFactory()->getConnection(); $select_subawards = $conn->prepare("SELECT * FROM gr_subawards WHERE request_id = :request_id"); $select_subawards->bindParam(":request_id", $this->id); $select_subawards->execute(); //Construct array of subawards $subawards = array(); if ($select_subawards->rowCount() > 0) { while ($row = $select_subawards->fetch(PDO::FETCH_ASSOC)) { $subaward = array(); $subaward['name'] = $row['institution_name']; $pi = GrPerson::getById($row['primaryinv_id']); if ($pi) { $subaward['principalInvestigator'] = array("name" => $pi->getName(), "email" => $pi->getEmail()); } $admin = GrPerson::getById($row['gradmin_id']); if ($admin) { $subaward['grantAdmin'] = array("name" => $admin->getName(), "email" => $admin->getEmail()); } $subawards[] = $subaward; } } else { return 0; } return $subawards; }
/** * Checks the database to match a JWT * @param string $jwt JSON Web Token to search for * @return array */ public static function authenticate($jwt) { $conn = PDOFactory::getFactory()->getConnection(); $select = $conn->prepare("SELECT * FROM requester where token=:token"); $select->bindParam(":token", $jwt); $select->execute(); return $select->fetch(PDO::FETCH_ASSOC); }
/** * 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; } } } } }