Exemplo n.º 1
0
 public function placesBrowse($req, $res)
 {
     $org = $this->getOrgForAdmin($req, $res);
     if (!is_object($org)) {
         return;
     }
     $limit = 100;
     $page = max(0, $req->query('page'));
     $showApproved = $req->query('approved');
     if ($showApproved === null) {
         $showApproved = true;
     }
     $query = ['where' => ['organization' => $org->id()], 'sort' => 'name ASC', 'limit' => $limit, 'start' => $page * $limit];
     if ($showApproved) {
         $query['where'][] = '(place_type = ' . VolunteerPlace::INTERNAL . ' OR (place_type = ' . VolunteerPlace::EXTERNAL . ' AND verify_approved = 1))';
     } else {
         $query['where']['place_type'] = VolunteerPlace::EXTERNAL;
         $query['where']['verify_approved'] = false;
     }
     $result = VolunteerPlace::find($query);
     $places = $result['models'];
     $count = $result['count'];
     return new View('places/browse', ['org' => $org, 'title' => 'Places', 'placesPage' => true, 'places' => $places, 'hasLess' => $page > 0, 'hasMore' => $count > $limit * ($page + 1), 'page' => $page, 'count' => $count, 'showApproved' => $showApproved, 'success' => $req->query('success')]);
 }
 /**
  * @depends testCreate
  */
 public function testFind()
 {
     // try with the organization supplied
     $places = VolunteerPlace::find(['where' => ['organization' => self::$org->id()], 'sort' => 'id ASC'])['models'];
     $this->assertCount(2, $places);
     // look for our known models
     $find = [self::$place->id(), self::$place2->id()];
     foreach ($places as $m) {
         if (($key = array_search($m->id(), $find)) !== false) {
             unset($find[$key]);
         }
     }
     $this->assertCount(0, $find);
 }