Ejemplo n.º 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();
         }
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return     void
  * @throws     PropelException
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     foreach (sfMixer::getCallables('BasePersonRole:delete:pre') as $callable) {
         $ret = call_user_func($callable, $this, $con);
         if ($ret) {
             return;
         }
     }
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(PersonRolePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         PersonRolePeer::doDelete($this, $con);
         $this->setDeleted(true);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     foreach (sfMixer::getCallables('BasePersonRole:delete:post') as $callable) {
         call_user_func($callable, $this, $con);
     }
 }
Ejemplo n.º 4
0
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return     int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = PersonPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related EmailTemplate objects
         $c = new Criteria(EmailTemplatePeer::DATABASE_NAME);
         $c->add(EmailTemplatePeer::PERSON_ID, $obj->getId());
         $affectedRows += EmailTemplatePeer::doDelete($c, $con);
         // delete related PasswordRequest objects
         $c = new Criteria(PasswordRequestPeer::DATABASE_NAME);
         $c->add(PasswordRequestPeer::PERSON_ID, $obj->getId());
         $affectedRows += PasswordRequestPeer::doDelete($c, $con);
         // delete related PersonRole objects
         $c = new Criteria(PersonRolePeer::DATABASE_NAME);
         $c->add(PersonRolePeer::PERSON_ID, $obj->getId());
         $affectedRows += PersonRolePeer::doDelete($c, $con);
         // delete related PersonalNote objects
         $c = new Criteria(PersonalNotePeer::DATABASE_NAME);
         $c->add(PersonalNotePeer::PERSON_ID, $obj->getId());
         $affectedRows += PersonalNotePeer::doDelete($c, $con);
     }
     return $affectedRows;
 }