Example #1
0
 public function savePersonRoleList($con = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['person_role_list'])) {
         // somebody has unset this widget
         return;
     }
     if (is_null($con)) {
         $con = $this->getConnection();
     }
     $c = new Criteria();
     $c->add(PersonRolePeer::PERSON_ID, $this->object->getPrimaryKey());
     PersonRolePeer::doDelete($c, $con);
     $values = $this->getValue('person_role_list');
     if (is_array($values)) {
         foreach ($values as $value) {
             $obj = new PersonRole();
             $obj->setPersonId($this->object->getPrimaryKey());
             $obj->setRoleId($value);
             $obj->save();
         }
     }
 }
Example #2
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      PersonRole $value A PersonRole object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(PersonRole $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = serialize(array((string) $obj->getPersonId(), (string) $obj->getRoleId()));
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Example #3
0
 protected function processStep3Check(sfWebRequest $request)
 {
     $default_airport = AirportPeer::getByIdent(sfConfig::get('app_default_airport_ident'));
     $this->forward404Unless($default_airport);
     $app = $this->application_temp;
     $person = $this->person;
     if (!$person instanceof Person) {
         $person = new Person();
     }
     /* @var $app ApplicationTemp */
     /* @var $person Person */
     // Person
     $tmp_arr = $app->toArray(BasePeer::TYPE_FIELDNAME);
     $tmp_arr['evening_phone'] = $tmp_arr['eve_phone'];
     $tmp_arr['evening_comment'] = $tmp_arr['eve_comment'];
     unset($tmp_arr['id']);
     $person->fromArray($tmp_arr, BasePeer::TYPE_FIELDNAME);
     $person->save();
     // Member
     $member = MemberPeer::getByPersonId($person->getId());
     if (!$member instanceof Member) {
         $member = new Member();
     }
     // Generate external id using last member is and external id
     $c = new Criteria();
     $c->add(MemberPeer::EXTERNAL_ID, NULL, Criteria::ISNOTNULL);
     $c->addDescendingOrderByColumn(MemberPeer::ID);
     $external_member = MemberPeer::doSelectOne($c);
     $external_id = $external_member->getExternalId();
     $currentExternalId = $external_id + 1;
     //print_r($external_id);
     //print_r($currentExternalId);
     $member->setActive(1);
     $member->setCoPilot($app->getApplicantCopilot());
     $member->setContact('By Email');
     $member->setDateOfBirth($app->getDateOfBirth());
     $member->setDriversLicenseState($app->getDriversLicenseState());
     $member->setDriversLicenseNumber($app->getDriversLicenseNumber());
     $member->setEmergencyContactName($app->getEmergencyContactName());
     $member->setEmergencyContactPhone($app->getEmergencyContactPhone());
     $member->setFlightStatus($app->getApplicantPilot() ? 'Verify Orientation' : 'Non-pilot');
     $member->setJoinDate(time());
     $member->setLanguages($app->getLanguagesSpoken());
     //$member->setMasterMemberId($app->getMasterMemberId());
     $member->setMemberClassId($app->getMemberClassId());
     $member->setPersonId($person->getId());
     $member->setRenewedDate(time());
     $member->setRenewalDate(strtotime('+1 year'));
     $member->setSpouseName($app->getSpouseFirstName() . ' ' . $app->getSpouseLastName());
     //external_id generate
     $member->setExternalId($currentExternalId);
     $member->setWingId($app->getWingId());
     $member->save();
     // Pilot
     if ($app->getApplicantPilot()) {
         $pilot = new Pilot();
         $pilot->setMemberId($member->getId());
         $airport = AirportPeer::getByIdent($app->getHomeBase());
         if (!$airport instanceof Airport) {
             $airport = $default_airport;
         }
         $pilot->setPrimaryAirportId($airport->getId());
         $pilot->setTotalHours($app->getTotalHours());
         $pilot->setLicenseType('Private');
         foreach (sfConfig::get('app_pilot_license_types') as $key => $val) {
             if (stripos($app->getRatings(), $key) !== false) {
                 $pilot->setLicenseType($key);
             }
         }
         $pilot->setIfr(stripos($app->getRatings(), 'ifr') !== false ? 1 : 0);
         $pilot->setMultiEngine(stripos($app->getRatings(), 'multi') !== false ? 1 : 0);
         $pilot->setSeInstructor('No');
         // @see ApplicationForm
         foreach (sfConfig::get('app_pilot_se_instructor') as $key => $val) {
             if (stripos($app->getRatings(), $key) !== false) {
                 $pilot->setSeInstructor($key);
             }
         }
         $pilot->setMeInstructor($pilot->getSeInstructor());
         $pilot->save();
         // Availability
         $availability = new Availability();
         $availability->setMemberId($member->getId());
         $availability->setNotAvailable(0);
         $availability->setNoWeekday($app->getAvailabilityWeekdays() == 0);
         $availability->setNoNight($app->getAvailabilityWeeknights() == 0);
         $availability->setLastMinute($app->getAvailabilityLastMinute());
         $availability->setAsMissionMssistant($app->getAvailabilityCopilot());
         $availability->setNoWeekend($app->getAvailabilityWeekends() == 0);
         try {
             $availability->save();
         } catch (Exception $e) {
         }
         // Primary aircraft
         if ($app->getAircraftPrimaryId() && ($aircraft = AircraftPeer::retrieveByPK($app->getAircraftPrimaryId()))) {
             $pilot_aircraft = new PilotAircraft();
             $pilot_aircraft->setMemberId($member->getId());
             $pilot_aircraft->setAircraftId($aircraft->getId());
             $pilot_aircraft->setNNumber($app->getAircraftPrimaryNNumber());
             $pilot_aircraft->setOwn($app->getAircraftPrimaryOwn());
             $pilot_aircraft->setSeats($app->getAircraftPrimarySeats());
             $pilot_aircraft->setKnownIce($app->getAircraftPrimaryIce());
             $pilot_aircraft->save();
         }
         // Secondary aircraft
         if ($app->getAircraftSecondaryId() && ($aircraft = AircraftPeer::retrieveByPK($app->getAircraftSecondaryId()))) {
             $pilot_aircraft = new PilotAircraft();
             $pilot_aircraft->setMemberId($member->getId());
             $pilot_aircraft->setAircraftId($aircraft->getId());
             $pilot_aircraft->setNNumber($app->getAircraftSecondaryNNumber());
             $pilot_aircraft->setOwn($app->getAircraftSecondaryOwn());
             $pilot_aircraft->setSeats($app->getAircraftSecondarySeats());
             $pilot_aircraft->setKnownIce($app->getAircraftSecondaryIce());
             $pilot_aircraft->save();
         }
         // Third aircraft
         if ($app->getAircraftThirdId() && ($aircraft = AircraftPeer::retrieveByPK($app->getAircraftThirdId()))) {
             $pilot_aircraft = new PilotAircraft();
             $pilot_aircraft->setMemberId($member->getId());
             $pilot_aircraft->setAircraftId($aircraft->getId());
             $pilot_aircraft->setNNumber($app->getAircraftThirdNNumber());
             $pilot_aircraft->setOwn($app->getAircraftThirdOwn());
             $pilot_aircraft->setSeats($app->getAircraftThirdSeats());
             $pilot_aircraft->setKnownIce($app->getAircraftThirdIce());
             $pilot_aircraft->save();
         }
     }
     // Application_temp
     $app->setPersonId($person->getId());
     $app->setMemberId($member->getId());
     $app->setProcessedDate(time());
     $app->save();
     // Application
     $tmp_arr = $app->toArray(BasePeer::TYPE_FIELDNAME);
     $tmp_arr['date'] = $tmp_arr['application_date'];
     $tmp_arr['company'] = $tmp_arr['company_name'];
     foreach (sfConfig::get('app_pilot_license_types') as $key => $val) {
         if (stripos($tmp_arr['ratings'], $key) !== false) {
             $tmp_arr['license_type'] = $key;
         }
     }
     $tmp_arr['ifr'] = stripos($tmp_arr['ratings'], 'ifr') !== false ? 1 : 0;
     $tmp_arr['multi_engine'] = stripos($tmp_arr['ratings'], 'multi') !== false ? 1 : 0;
     $tmp_arr['se_instructor'] = 'No';
     // @see ApplicationForm
     foreach (sfConfig::get('app_pilot_se_instructor') as $key => $val) {
         if (stripos($tmp_arr['ratings'], $key) !== false) {
             $tmp_arr['se_instructor'] = $key;
         }
     }
     $tmp_arr['me_instructor'] = $tmp_arr['se_instructor'];
     $tmp_arr['other_ratings'] = $tmp_arr['ratings'];
     $tmp_arr['fbo'] = $tmp_arr['fbo_name'];
     $tmp_arr['member_meetings'] = 0;
     $tmp_arr['executive_board'] = 0;
     $tmp_arr['dues_amount_paid'] = $tmp_arr['dues_amount_paid'] ? $tmp_arr['dues_amount_paid'] : 0;
     unset($tmp_arr['id']);
     $application = new Application();
     $application->fromArray($tmp_arr, BasePeer::TYPE_FIELDNAME);
     $application->save();
     $where = $request->getParameter('step3_redirect');
     //Ziyed  save default role for new member
     $appTemp = $this->application_temp;
     if ($appTemp->getPersonId()) {
         $person_role = new PersonRole();
         $person_role->setPersonId($appTemp->getPersonId());
         if ($appTemp->getApplicantPilot() == 1) {
             $person_role->setRoleId(27);
         } else {
             $person_role->setRoleId(31);
         }
         $person_role->save();
     }
     //Ziyed end save
     if ($where == 1) {
         $this->redirect('@member_view?id=' . $member->getId());
     } else {
         /*
                     if ($application->getEmail()) {
                         # send email failure to payment
                         $this->getComponent('mail', 'memberApplicationProcessed', array('email' => $application->getEmail(),'member_id'=>$member->getId(), 'name' => $application->getFirstName() . ' ' . $application->getLastName()));
         
                     }*/
         $this->redirect('pending_member/processComplete?id=' . $member->getId());
     }
 }
Example #4
0
 /**
  * AJAX
  * Saves all changes made to a person
  * CODE: person_create
  * CODE: person_save_roles
  */
 public function executeSave(sfWebRequest $request)
 {
     # security
     if (!$this->getUser()->hasCredential(array('Administrator', 'Staff', 'Pilot', 'Coordinator', 'Volunteer'), false)) {
         $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer());
         $this->redirect('dashboard/index');
     }
     # validate person
     $person = PersonPeer::retrieveByPK($request->getParameter('person_id'));
     if (!$person instanceof Person) {
         return $this->renderText('Data is invalid! Please refresh and try again!');
     }
     $saved_values = array();
     $errors = array();
     $form = new PersonForm($person, null, false);
     # email list
     $params = $request->getGetParameters();
     $ids = array();
     foreach ($params as $name => $value) {
         if (substr($name, 0, 11) == 'email_list_') {
             $ids[] = (int) substr($name, 11);
         }
     }
     $validator = new sfValidatorPropelChoice(array('model' => 'EmailList', 'column' => 'id', 'required' => false, 'multiple' => true, 'empty_value' => array()));
     $err = false;
     try {
         $ids = $validator->clean($ids);
     } catch (sfValidatorError $e) {
         $errors[] = 'Couldn\'t save mailing list. Please refresh and try again';
         $err = true;
     }
     if (!$err) {
         $c = new Criteria();
         $c->add(EmailListPersonPeer::PERSON_ID, $person->getId());
         EmailListPersonPeer::doDelete($c);
         foreach ($ids as $id) {
             if ($request->getParameter('email_list_' . $id) == 1) {
                 $email_list_person = new EmailListPerson();
                 $email_list_person->setListId($id);
                 $email_list_person->setPersonId($person->getId());
                 $email_list_person->save();
                 $saved_values['email_list_' . $id] = 1;
             } else {
                 $saved_values['email_list_' . $id] = 0;
             }
         }
     }
     $request_params = array_intersect_key($request->getGetParameters(), $form->getWidgetSchema()->getFields());
     $params = array_merge($person->toArray(BasePeer::TYPE_FIELDNAME), $request->getGetParameters());
     $params = array_intersect_key($params, $form->getWidgetSchema()->getFields());
     $form->bind($params);
     if (!$form->isValid()) {
         foreach ($form->getErrorSchema()->getErrors() as $field => $e) {
             $errors[] = $e->__toString();
         }
     } else {
         $form->save();
         foreach ($request_params as $field => $v) {
             $saved_values[$field] = $form->getValue($field);
         }
     }
     /*
     # email blocked
         if ($request->hasParameter('email_blocked')) {
         $v = $form->getValidator('email_blocked');
         try {
         $email_blocked = $v->clean($request->getParameter('email_blocked'));
         $person->setEmailBlocked($email_blocked == 1 ? 1 : 0);
         $saved_values['email_blocked'] = $person->getEmailBlocked();
         }catch(sfValidatorError $e) {
         $errors[] = $e->__toString();
         }
         }
     # email text only
         if ($request->hasParameter('email_text_only')) {
         $email_text_only = $request->getParameter('email_text_only');
         $person->setEmailTextOnly($email_text_only == 1 ? 1 : 0);
         $saved_values['email_text_only'] = $person->getEmailTextOnly();
         }
     # email
         if ($request->hasParameter('email')) {
         $validator = new sfValidatorEmail(array('required' => true), array('invalid' => 'Email address is invalid: %value%', 'required' => 'Email address is invalid'));
         $err = false;
         try {
         $email = $validator->clean($request->getParameter('email'));
         }catch(sfValidatorError $e) {
         $errors[] = $e->__toString();
         $err = true;
         }
         if (!$err) {
         $person->setEmail($email);
         $saved_values['email'] = $email;
         }
         }
     # city
         $person->setCity($saved_values['city'] = $request->getParameter('city'));
     # county
         $person->setCounty($saved_values['county'] = $request->getParameter('county'));
     # state
         $person->setState($saved_values['state'] = $request->getParameter('state'));
     $person->save();
     */
     # roles
     if ($request->hasParameter('roles')) {
         if ($this->getUser()->hasCredential(array('Administrator'), false) == true) {
             $roles = $request->getParameter('roles');
             $validator = new sfValidatorPropelChoice(array('model' => 'Role', 'column' => 'id', 'required' => false, 'multiple' => true, 'empty_value' => array()));
             $err = false;
             try {
                 $roles = $validator->clean($roles);
             } catch (sfValidatorError $e) {
                 $errors[] = 'Couldn\'t save roles. Please refresh and try again';
                 $err = true;
             }
             if (!$err) {
                 $c = new Criteria();
                 $c->add(PersonRolePeer::PERSON_ID, $person->getId());
                 PersonRolePeer::doDelete($c);
                 foreach ($roles as $role) {
                     $person_role = new PersonRole();
                     $person_role->setPersonId($person->getId());
                     //            if($s_role->getId()==$role){
                     //              $role=$a_role->getId();
                     //            }
                     $person_role->setRoleId($role);
                     $person_role->save();
                 }
                 $saved_values['roles'] = $roles;
             }
         } else {
             $errors[] = 'You don\'t have permission to edit person roles!';
         }
     }
     $this->errors = $errors;
     $this->saved_values = $saved_values;
 }
Example #5
0
 /**
  * Member add or edit
  * CODE: member_create
  */
 public function executeUpdate(sfWebRequest $request)
 {
     $new_pilot = false;
     #Security
     if (!$this->getUser()->hasCredential(array('Administrator', 'Staff', 'Member'), false)) {
         $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer());
         $this->redirect('dashboard/index');
     }
     //FROM PERSON VIEW
     if ($request->getParameter('id')) {
         $member = MemberPeer::retrieveByPK($request->getParameter('id'));
         $this->forward404Unless($member);
         $this->title = 'Edit member';
         $success = 'Member information has been successfully changed!';
         $this->person = $member->getPerson();
     } else {
         $this->person = PersonPeer::retrieveByPK($request->getParameter('person_id'));
         $this->forward404Unless($this->person);
         $member = new Member();
         $this->title = 'Add new member';
         $success = 'Member information has been successfully created!';
     }
     $this->form = new MemberForm($member);
     $this->back = $request->getReferer();
     $this->member = $member;
     if (strstr($request->getReferer(), 'person/view')) {
         $this->f_back = 1;
     } elseif (strstr($request->getReferer(), '/member/view/id')) {
         $this->f_back = 3;
     } elseif (strstr($request->getReferer(), '/member')) {
         $this->f_back = 2;
     }
     if ($request->isMethod('post')) {
         $this->referer = $request->getReferer();
         $this->form->bind($request->getParameter('mem'));
         if ($this->form->isValid() && $this->form->getValue('member_class_id') != 0 && $this->form->getValue('flight_status')) {
             if ($request->getParameter('person_id')) {
                 $member->setPersonId($request->getParameter('person_id'));
             }
             $person = PersonPeer::retrieveByPK($request->getParameter('person_id'));
             $member->setDateOfBirth($this->form->getValue('date_of_birth'));
             $member->setWeight($this->form->getValue('weight'));
             $member->setLanguages($this->form->getValue('languages'));
             if ($this->form->getValue('wing_id') == 0) {
                 $member->setWingId(null);
             } else {
                 $member->setWingId($this->form->getValue('wing_id'));
             }
             if ($this->form->getValue('secondary_wing_id') == 0) {
                 $member->setSecondaryWingId(null);
             } else {
                 $member->setSecondaryWingId($this->form->getValue('secondary_wing_id'));
             }
             // setting external_id
             $c = new Criteria();
             $c->add(MemberPeer::EXTERNAL_ID, NULL, Criteria::ISNOTNULL);
             $c->addDescendingOrderByColumn(MemberPeer::ID);
             $external_member = MemberPeer::doSelectOne($c);
             $external_id = $external_member->getExternalId();
             $currentExternalId = $external_id + 1;
             $member->setExternalId($currentExternalId);
             $member->setJoinDate($this->form->getValue('join_date'));
             $member->setMemberClassId($this->form->getValue('member_class_id'));
             $member->setSpouseName($this->form->getValue('spouse_name'));
             $member->setCoordinatorNotes($this->form->getValue('coordinator_notes'));
             $member->setFlightStatus($this->form->getValue('flight_status'));
             if ($this->form->getValue('co_pilot') == null) {
                 $member->setCoPilot(0);
             } else {
                 $member->setCoPilot($this->form->getValue('co_pilot'));
             }
             $new_member = $member->isNew();
             if ($new_member) {
                 $content = $this->getUser()->getName() . ' added new Member: ' . $person->getFirstName();
                 ActivityPeer::log($content);
             }
             $member->save();
             //
             $wing_jobs = $request->getParameter('wing_job1[]');
             if ($request->getParameter('wing_job1')) {
                 $old_mem_wing_jobs = MemberWingJobPeer::getWingJob($member->getId());
                 foreach ($old_mem_wing_jobs as $old_mem_wing_job) {
                     $old_mem_wing_job->delete();
                 }
                 foreach ($wing_jobs as $wing_job) {
                     $member_wing_job = new MemberWingJob();
                     $member_wing_job->setMemberId($member->getId());
                     $member_wing_job->setWingJobId($wing_job);
                     $member_wing_job->save();
                 }
             }
             if (strtolower($member->getFlightStatus()) == 'command pilot') {
                 // if command-pilot then make pilot
                 $pilot = new Pilot();
                 $pilot->setMemberId($member->getId());
                 $pilot->setLicenseType('Default');
                 $pilot->setIfr(0);
                 $pilot->setMultiEngine(0);
                 $pilot->save();
                 $new_pilot = true;
             } else {
                 $new_pilot = false;
             }
             $this->getUser()->setFlash('success', $success);
             $last = $request->getParameter('back');
             $back_url = 'member/index';
             if (strstr($last, 'member/edit')) {
                 $back_url = 'member/index';
             } elseif (strstr($last, 'person/view')) {
                 if (isset($this->person)) {
                     $back_url = '@person_view?id=' . $this->person->getId();
                 }
             } elseif (strstr($last, 'member/view')) {
                 $back_url = '@member_view?id=' . $member->getId();
             }
             //with error validation back url
             if (strstr($request->getReferer(), 'last/1')) {
                 $back_url = '@person_view?id=' . $this->person->getId();
             } elseif (strstr($request->getReferer(), 'last/2')) {
                 $back_url = 'member/index';
             } elseif (strstr($request->getReferer(), 'last/3')) {
                 $back_url = '@member_view?id=' . $member->getId();
             }
             // role for new member
             if ($new_member) {
                 $role = '@Member';
                 $member_role = RolePeer::getByTitle($role);
                 if ($member_role) {
                     $person_role = new PersonRole();
                     $person_role->setPersonId($this->person->getId());
                     $person_role->setRoleId($member_role->getId());
                     $person_role->save();
                 } else {
                     $url = $this->generateUrl('default_index', array('module' => 'role'), true);
                     $this->getUser()->setFlash('warning', '"' . $role . '" role not found! Please navigate ' . $url . ' and fix.');
                 }
             }
             // role for new pilot
             if ($new_pilot) {
                 $role = '@Pilot';
                 $pilot_role = RolePeer::getByTitle($role);
                 $is_true = PersonRolePeer::getIsTrue($this->person->getId(), $pilot_role->getId());
                 if (!$is_true) {
                     $person_role = new PersonRole();
                     $person_role->setPersonId($this->person->getId());
                     $person_role->setRoleId($pilot_role->getId());
                     $person_role->save();
                 } else {
                     $url = $this->generateUrl('default_index', array('module' => 'role'), true);
                     //$this->getUser()->setFlash('warning', '"'.$role.'" role not found! Please navigate '.$url.' and fix');
                 }
             }
             $this->redirect($back_url);
         } else {
             $this->getUser()->setFlash('warning', 'Please confirm flight status and choose the member class!');
         }
     } else {
         # Set referer URL
         $this->referer = $request->getReferer() ? $request->getReferer() : 'member/index';
     }
     $this->member = $member;
 }