Skip to content

Instantly share code, notes, and snippets.

@jblac
Created March 19, 2013 17:19
Show Gist options
  • Save jblac/5198107 to your computer and use it in GitHub Desktop.
Save jblac/5198107 to your computer and use it in GitHub Desktop.
public function getAppointmentBlocksInRange($start, $end, $agent) {
$em = $this->em;
$rsm = new ResultSetMapping();
$rsm->addScalarResult('id', 'id');
$rsm->addScalarResult('startTime', 'startTime');
$rsm->addScalarResult('startTime1', 'startTime1');
$rsm->addScalarResult('endTime', 'endTime');
$rsm->addScalarResult('endTime1', 'endTime1');
$rsm->addScalarResult('caseManager', 'caseManager');
$start = date('Y-m-d 00:00:00', strtotime($start));
$end = date('Y-m-d 23:23:23', strtotime($end));
$sql = "
SELECT
a.id as id,
DATE(a.startTime) AS startTime,
DATE(a.endTime) AS endTime,
a.startTime AS startTime1,
a.endTime AS endTime1,
CONCAT(p.`first_name`, ' ', p.last_name) as `caseManager`
FROM appointmentBlock a
JOIN `User` p ON p.id = a.`caseManager_id`
WHERE a.startTime BETWEEN :start AND :end";
if ($agent != '') {
$sql .= " AND a.caseManager_id = :agent";
}
$sql .= " GROUP BY a.startTime, a.caseManager_id";
echo $sql;
$query = $em->createNativeQuery($sql, $rsm);
$query->setParameters(array(
"start" => $start,
"end" => $end
));
if ($agent != "") {
$query->setParameters(array(
"start" => $start,
"end" => $end,
"agent" => $agent
));
}
echo "<pre>";
print_r($query->getResult());
echo "</pre>";
return $query->getResult();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment