/** * 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 corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aLeasingCalendar !== null) { if ($this->aLeasingCalendar->isModified() || $this->aLeasingCalendar->isNew()) { $affectedRows += $this->aLeasingCalendar->save($con); } $this->setLeasingCalendar($this->aLeasingCalendar); } if ($this->aLeasingUnit !== null) { if ($this->aLeasingUnit->isModified() || $this->aLeasingUnit->isNew()) { $affectedRows += $this->aLeasingUnit->save($con); } $this->setLeasingUnit($this->aLeasingUnit); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
public function saveCalendarAction() { $request = $this->getRequest(); $calendar = LeasingCalendarPeer::getCalendarByPostId($request->request->get('calendar_post_id')); $units = json_decode($request->request->get('units')); if (empty($calendar)) { $calendar = new LeasingCalendar(); } $calendar->setName($request->request->get('name')); $calendar->setCalendarPostId($request->request->get('calendar_post_id')); $calendar->setAvailability($request->request->get('availability')); $calendar->setStartDate($request->request->get('start_date')); $calendar->setEndDate($request->request->get('end_date')); $calendar->save(); $uc = LeasingUnitCalendarPeer::getUnitCalendarByCalendarId($calendar->getId()); if (empty($uc)) { foreach ($units as $unit) { $u = LeasingUnitPeer::getUnitByPostId($unit); $uc = new LeasingUnitCalendar(); $uc->setCalendarId($calendar->getId()); $uc->setUnitId($u->getId()); $uc->setStatus(C::ACTIVE); $uc->save(); } } else { foreach ($uc as $u) { $u->setStatus(C::DELETE); $u->save(); } foreach ($units as $unit) { $fl = 0; $lu = LeasingUnitPeer::getUnitByPostId($unit); foreach ($uc as $u) { if ($u->getUnitId() == $lu->getId()) { $fl = 1; $u->setStatus(C::ACTIVE); $u->save(); } } if ($fl == 0) { $u = new LeasingUnitCalendar(); $u->setCalendarId($calendar->getId()); $u->setUnitId($u->getId()); $u->setStatus(C::ACTIVE); $u->save(); } } } return new RedirectResponse('http://leasing.dmcihomes.com.local/wp-admin/post.php'); }