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');
 }
 /**
  * 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 LeasingUnitCalendar $obj A LeasingUnitCalendar object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         LeasingUnitCalendarPeer::$instances[$key] = $obj;
     }
 }
 /**
  * Exclude object from result
  *
  * @param   LeasingUnitCalendar $leasingUnitCalendar Object to remove from the list of results
  *
  * @return LeasingUnitCalendarQuery The current query, for fluid interface
  */
 public function prune($leasingUnitCalendar = null)
 {
     if ($leasingUnitCalendar) {
         $this->addUsingAlias(LeasingUnitCalendarPeer::ID, $leasingUnitCalendar->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }