/** * 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->aMember !== null) { if ($this->aMember->isModified() || $this->aMember->isNew()) { $affectedRows += $this->aMember->save($con); } $this->setMember($this->aMember); } if ($this->aAircraft !== null) { if ($this->aAircraft->isModified() || $this->aAircraft->isNew()) { $affectedRows += $this->aAircraft->save($con); } $this->setAircraft($this->aAircraft); } if ($this->isNew()) { $this->modifiedColumns[] = PilotAircraftPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = PilotAircraftPeer::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 += PilotAircraftPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collMissionLegs !== null) { foreach ($this->collMissionLegs as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** * Create a aircraft * @param array $params * @return mixed */ public static function create($params) { if (!empty($params)) { $aircraft = new Aircraft(); $aircraft->name = $params['name']; $aircraft->type_id = $params['type_id']; $aircraft->status_id = $params['status_id']; $aircraft->save(); $aircraft->refresh(); return $aircraft->id; } return false; }
/** * Add or edit aircraft * CODE:aircraft_create */ public function executeUpdate(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'); } sfContext::getInstance()->getConfiguration()->loadHelpers('Partial'); slot('nav_menu', array('reference', '')); if ($request->getParameter('id')) { $aircraft = AircraftPeer::retrieveByPK($request->getParameter('id')); $this->forward404Unless($aircraft); $this->title = 'Edit aircraft'; $success = 'Aircraft information has been successfully changed!'; } else { $aircraft = new Aircraft(); $this->title = 'Add aircraft'; $success = 'Aircraft information has been successfully created!'; } if ($request->getParameter('leg')) { $this->leg_id = $request->getParameter('leg'); } $this->form = new AircraftForm($aircraft); if ($request->isMethod('post')) { $this->referer = $request->getReferer(); $this->form->bind($request->getParameter('craft')); if ($this->form->isValid() && $this->form->getValue('cost')) { $aircraft->setMake($this->form->getValue('make')); $aircraft->setModel($this->form->getValue('model')); $aircraft->setName($this->form->getValue('name')); $aircraft->setFaa($this->form->getValue('faa')); if ($this->form->getValue('engines') == null) { $aircraft->setEngines(0); } else { $aircraft->setEngines($this->form->getValue('engines')); } if ($this->form->getValue('def_seats') == null) { $aircraft->setDefSeats(0); } else { $aircraft->setDefSeats($this->form->getValue('def_seats')); } $aircraft->setSpeed($this->form->getValue('speed')); if ($this->form->getValue('pressurized') == null) { $aircraft->setPressurized(0); } else { $aircraft->setPressurized($this->form->getValue('pressurized')); } $aircraft->setCost($this->form->getValue('cost')); $aircraft->setRange($this->form->getValue('range')); $aircraft->setAcLoad($this->form->getValue('ac_load')); if ($aircraft->isNew()) { $content = $this->getUser()->getName() . ' added new Aircraft: ' . $aircraft->getMakeModel(); ActivityPeer::log($content); } $aircraft->save(); $this->getUser()->setFlash('success', $success); $back = '@aircraft'; if ($request->getParameter('leg_id')) { $back = '@leg_edit?id=' . $request->getParameter('leg_id'); } return $this->redirect($back); } } else { # Set referer URL $this->referer = $request->getReferer() ? $request->getReferer() : '@aircraft'; } $this->aircraft = $aircraft; }