public function getSections()
 {
     $section = ['title' => 'Volunteers', 'rows' => []];
     $tagHeaders = $this->organization->hourTags();
     $section['header'] = ['Volunteer', 'Metadata', 'Hours'];
     // $section['header'] = array_merge( $section['header'], $tagHeaders );
     $totalHours = 0;
     $totalHoursByTag = [];
     foreach ($tagHeaders as $tag) {
         $totalHoursByTag[$tag] = 0;
     }
     $volunteers = Volunteer::findAll(['where' => ['active' => true, 'organization' => $this->organization->id()]]);
     foreach ($volunteers as $volunteer) {
         $metadata = $volunteer->metadata;
         if ($metadata) {
             $metadata = urldecode(http_build_query($metadata));
         }
         $volunteerHours = $this->organization->totalHoursVolunteered($this->start, $this->end, $volunteer);
         $volunteerHoursBytag = $this->organization->totalHoursVolunteeredByTag($this->start, $this->end, $volunteer);
         $row = [$volunteer->name(), $metadata, $volunteerHours];
         // process tags
         foreach ($tagHeaders as $tag) {
             $tagHours = 0;
             if (isset($volunteerHoursBytag[$tag])) {
                 $tagHours = $volunteerHoursBytag[$tag];
             }
             // $row[] = $tagHours;
             $totalHoursByTag[$tag] += $tagHours;
         }
         $section['rows'][] = $row;
         $totalHours += $volunteerHours;
     }
     $section['footer'] = ['', 'Total Hours', number_format($totalHours)];
     // $section['footer'] = array_merge( $section['footer'], array_values( $totalHoursByTag ) );
     return [$section];
 }
示例#2
0
 public function recordHoursStep2($req, $res)
 {
     $org = $this->getOrgForAdmin($req, $res);
     if (!is_object($org)) {
         return;
     }
     $place = $req->query('place');
     if ($place) {
         $place = new VolunteerPlace($place);
         if (!$place->exists()) {
             $place = false;
         }
     }
     if (!$place) {
         return $res->redirect($org->manageUrl() . '/hours/add');
     }
     // check for previous input
     $input = $req->request('json') ? json_decode($req->request('json'), true) : $req->request();
     $start = strtotime('-5 days');
     $end = strtotime('today');
     $days = $this->daysArray($start, $end);
     // recreate days from input
     if (isset($input['days'])) {
         $days = [];
         foreach ($input['days'] as $k => $day) {
             $date = \DateTime::createFromFormat('M j, Y', $day);
             if ($date) {
                 $days[] = $this->dayArrayFromTs($date->getTimestamp());
             }
         }
     }
     $volunteers = Volunteer::findAll(['where' => ['organization' => $org->id(), 'role >= ' . Volunteer::ROLE_VOLUNTEER], 'sort' => 'id ASC']);
     $availableTags = (array) Database::select('VolunteerHourTags', 'tag', ['where' => ['organization' => $org->id()], 'fetchStyle' => 'singleColumn', 'orderBy' => 'RAND()', 'groupBy' => 'tag', 'limit' => 10]);
     return new View('hours/add2', ['org' => $org, 'title' => 'Add Volunteer Hours', 'hoursPage' => true, 'days' => $days, 'input' => $input, 'volunteers' => $volunteers, 'place' => $place, 'tags' => U::array_value($input, 'tags'), 'availableTags' => $availableTags]);
 }