Example #1
0
 public function executeSaveFilterForm(sfWebRequest $request)
 {
     //get all filters
     $f_date_range1 = $request->getParameter('date_range1');
     $f_date_range2 = $request->getParameter('date_range2');
     $weekdays = $request->getParameter('weekdays', array());
     $f_wing = $request->getParameter('wing_id');
     $f_ident = $request->getParameter('ident');
     $f_city = $request->getParameter('city');
     $f_zipcode = $request->getParameter('zipcode');
     $f_state = $request->getParameter('state');
     $f_location_type = $request->getParameter('location_type');
     $f_origin = $request->getParameter('origin');
     $f_dest = $request->getParameter('dest');
     $needs_pilot = $request->getParameter('needs_pilot');
     $co_pilot = $request->getParameter('co_pilot');
     $ifr = $request->getParameter('ifr');
     //mission types selected by default
     $arr = array();
     if (sizeof($this->mission_types) > 0) {
         foreach ($this->mission_types as $ru) {
             $arr[] = $ru->getId();
         }
     }
     $selected_types = $request->getParameter('selected_types[]', $arr);
     $f_filled = $request->getParameter('filled');
     $f_open = $request->getParameter('open');
     $f_maxpass = $request->getParameter('max_pass');
     $f_maxwei = $request->getParameter('max_weight');
     $f_maxdist = $request->getParameter('max_distance');
     $f_mineff = $request->getParameter('min_efficiency');
     $ignore_availability = $request->getParameter('ignore_availability');
     $member_id = $request->getParameter('member_id');
     #save filter
     $is_filter_saved = UserFilterPeer::getByPersonId($this->getUser()->getId());
     if (!$is_filter_saved || !$is_filter_saved instanceof UserFilter) {
         $is_filter_saved = new UserFilter();
     }
     $is_filter_saved->setPersonId($this->getUser()->getId());
     $is_filter_saved->setDateRange1($f_date_range1);
     $is_filter_saved->setDateRange2($f_date_range2);
     $is_filter_saved->setDay1($weekdays[0] ? 1 : 0);
     $is_filter_saved->setDay2($weekdays[1] ? 1 : 0);
     $is_filter_saved->setDay3($weekdays[2] ? 1 : 0);
     $is_filter_saved->setDay4($weekdays[3] ? 1 : 0);
     $is_filter_saved->setDay5($weekdays[4] ? 1 : 0);
     $is_filter_saved->setDay6($weekdays[5] ? 1 : 0);
     $is_filter_saved->setDay7($weekdays[6] ? 1 : 0);
     $is_filter_saved->setWing($f_wing);
     $is_filter_saved->setIdent($f_ident);
     $is_filter_saved->setCity($f_city);
     $is_filter_saved->setZipcode($f_zipcode);
     $is_filter_saved->setState($f_state);
     $is_filter_saved->setOrgin($f_origin);
     $is_filter_saved->setDest($f_dest);
     $is_filter_saved->setIsPilot($needs_pilot);
     $is_filter_saved->setIsMa($co_pilot);
     $is_filter_saved->setIfrBackup($ifr);
     $is_filter_saved->setFilled($f_filled);
     $is_filter_saved->setOpen($f_open);
     $is_filter_saved->setMaxPassenger($f_maxpass);
     $is_filter_saved->setMaxWeight($f_maxwei);
     $is_filter_saved->setMaxDistance($f_maxdist);
     $is_filter_saved->setMaxEffciency($f_mineff);
     $is_filter_saved->setAvailability($ignore_availability);
     $is_filter_saved->save();
     //now save selected mission types
     //before delete all previous mission types saved
     $c = new Criteria();
     $c->add(UserFilterMissionTypesPeer::USER_FILTER_ID, $is_filter_saved->getId());
     foreach (UserFilterMissionTypesPeer::doSelect($c) as $rUs) {
         $rUs->delete();
     }
     //now add
     foreach ($selected_types as $key => $value) {
         $rUs = new UserFilterMissionTypes();
         $rUs->setUserFilterId($is_filter_saved->getId());
         $rUs->setMissionTypeId($value);
         $is_filter_saved->addUserFilterMissionTypes($rUs);
     }
     $is_filter_saved->save();
     $this->getUser()->setFlash('success', 'Your current filters has saved!');
 }