Ejemplo n.º 1
0
 /**
  * Gets the timestamp of the first volunteer hour.
  * If no hours have been created yet, will use the creation date.
  *
  * @return int
  */
 public function firstHourTimestamp()
 {
     $firstHourTs = (int) Database::select('VolunteerHours', 'MIN(timestamp)', ['where' => $this->hourWhereParams(), 'single' => true]);
     if ($firstHourTs <= 0) {
         $firstHourTs = $this->created_at;
     }
     // the first  hour timestamp cannot be older than InspireVive
     $firstHourTs = max(mktime(0, 0, 0, 4, 1, 2013), $firstHourTs);
     return $firstHourTs;
 }
Ejemplo n.º 2
0
 /**
  * Gets the tags associated with this hour.
  *
  * @return array(string)
  */
 public function tags()
 {
     return (array) Database::select('VolunteerHourTags', 'tag', ['where' => ['hour' => $this->id()], 'fetchStyle' => 'singleColumn', 'orderBy' => 'tag ASC', 'groupBy' => 'tag']);
 }
Ejemplo n.º 3
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]);
 }
Ejemplo n.º 4
0
 public function reportHoursStep2($req, $res)
 {
     $org = $this->getOrg($req, $res);
     if (!is_object($org)) {
         return $org;
     }
     $currentUser = $this->app['user'];
     // make sure the user is logged in
     if (!$currentUser->isLoggedIn()) {
         setcookie('redirect', $org->url() . '/hours/report', time() + 3600, '/');
         return $res->redirect('/login');
     }
     $place = $req->query('place');
     if ($place) {
         if ($place == -1) {
             return $res->redirect($org->url() . '/places/add');
         }
         $place = new VolunteerPlace($place);
     }
     if (!$place || !$place->exists()) {
         return $res->redirect($org->url() . '/hours/add');
     }
     $dayTs = $req->request('timestamp');
     $availableTags = (array) Database::select('VolunteerHourTags', 'tag', ['where' => ['organization' => $org->id()], 'fetchStyle' => 'singleColumn', 'orderBy' => 'RAND()', 'groupBy' => 'tag', 'limit' => 10]);
     return new View('reportHours2', ['org' => $org, 'title' => 'Report Volunteer Hours', 'place' => $place, 'tags' => $req->request('tags'), 'timestamp' => $dayTs, 'hours' => $req->request('hours'), 'availableTags' => $availableTags]);
 }