Skip to content

Instantly share code, notes, and snippets.

@markbalt
Created November 28, 2012 17:01
Show Gist options
  • Save markbalt/4162541 to your computer and use it in GitHub Desktop.
Save markbalt/4162541 to your computer and use it in GitHub Desktop.
Run SQL query using Propel PDO Connection
/**
* Get available reserved cabinets not in this project for this customer
*
* @return array
*/
public function getReservedCabinetChoices()
{
$id = $this->getId();
$con = Propel::getConnection();
$arr = array();
// include cabinets from this project
$sql = "SELECT
pc.id,
c.`name`
FROM
cabinet c
JOIN `row` r ON c.row_id = r.id
LEFT JOIN project_cabinet pc ON pc.cabinet_id = c.id
LEFT JOIN project p ON p.id = pc.project_id
WHERE pc.project_id <> ".$this->getId()." AND pc.is_reserved = 1 AND p.customer_id = ".$this->getCustomerId()." AND r.facility_id = ".$this->getFacilityId()." ORDER BY r.`order`, c.`order`";
$stmt = $con->prepare($sql);
$stmt->execute();
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $up) {
$arr[$up['id']] = $up['name'];
}
$stmt = null;
return $arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment