Ejemplo n.º 1
0
 /**
  * Gets the total number of hours volunteered broken down by tags.
  *
  * @param int       $start
  * @param int       $end
  * @param Volunteer $volunteer
  *
  * @return array
  */
 public function totalHoursVolunteeredByTag($start = false, $end = false, Volunteer $volunteer = null)
 {
     $where = $this->hourWhereParams('h');
     if (!$start) {
         $start = 0;
     }
     if (!$end) {
         $end = time() + 3600;
     }
     $where['h.approved'] = true;
     $where[] = 'h.timestamp >= ' . $start;
     $where[] = 'h.timestamp <= ' . $end;
     if ($volunteer) {
         $where['h.uid'] = $volunteer->id();
     }
     $totalsByTag = (array) Database::select('VolunteerHourTags t LEFT JOIN VolunteerHours h ON t.hour=h.id', 't.tag AS tag, SUM(h.hours) AS hours', ['where' => $where, 'groupBy' => 't.tag']);
     $tags = [];
     foreach ($totalsByTag as $row) {
         $tags[$row['tag']] = (int) $row['hours'];
     }
     return $tags;
 }