Ejemplo n.º 1
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aPerson !== null) {
             if ($this->aPerson->isModified() || $this->aPerson->isNew()) {
                 $affectedRows += $this->aPerson->save($con);
             }
             $this->setPerson($this->aPerson);
         }
         if ($this->aRefSource !== null) {
             if ($this->aRefSource->isModified() || $this->aRefSource->isNew()) {
                 $affectedRows += $this->aRefSource->save($con);
             }
             $this->setRefSource($this->aRefSource);
         }
         if ($this->aContactType !== null) {
             if ($this->aContactType->isModified() || $this->aContactType->isNew()) {
                 $affectedRows += $this->aContactType->save($con);
             }
             $this->setContactType($this->aContactType);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = ContactPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = ContactPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += ContactPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Ejemplo n.º 2
0
 /**
  * Add or edit contact type
  * CODE:contact_type_create
  */
 public function executeUpdateType(sfWebRequest $request)
 {
     # security
     if (!$this->getUser()->hasCredential(array('Administrator'), false)) {
         $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer());
         $this->redirect('dashboard/index');
     }
     if ($request->getParameter('id')) {
         $contact_type = ContactTypePeer::retrieveByPK($request->getParameter('id'));
         $this->title = 'Edit Contact Type';
         $success = 'Contact Type Information has successfully created!';
     } else {
         $contact_type = new ContactType();
         $this->title = 'Edit Contact Type';
         $success = 'Contact Type Information has successfully created!';
     }
     $this->form = new ContactTypeForm($contact_type);
     if ($request->isMethod('post')) {
         $this->referer = $request->getReferer();
         $this->form->bind($request->getParameter('con_type'));
         if ($this->form->isValid()) {
             $contact_type->setContactTypeDesc($this->form->getValue('contact_type_desc'));
             $contact_type->save();
             $this->getUser()->setFlash('success', $success);
             $this->redirect('ctype');
         }
     } else {
         $this->referer = $request->getReferer() ? $request->getReferer() : '@ctype';
     }
     $this->contact_type = $contact_type;
 }