Esempio n. 1
0
 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');
 }
 /**
  * Exclude object from result
  *
  * @param   LeasingCalendar $leasingCalendar Object to remove from the list of results
  *
  * @return LeasingCalendarQuery The current query, for fluid interface
  */
 public function prune($leasingCalendar = null)
 {
     if ($leasingCalendar) {
         $this->addUsingAlias(LeasingCalendarPeer::ID, $leasingCalendar->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
 /**
  * Declares an association between this object and a LeasingCalendar object.
  *
  * @param                  LeasingCalendar $v
  * @return LeasingUnitCalendar The current object (for fluent API support)
  * @throws PropelException
  */
 public function setLeasingCalendar(LeasingCalendar $v = null)
 {
     if ($v === null) {
         $this->setCalendarId(NULL);
     } else {
         $this->setCalendarId($v->getId());
     }
     $this->aLeasingCalendar = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the LeasingCalendar object, it will not be re-added.
     if ($v !== null) {
         $v->addLeasingUnitCalendar($this);
     }
     return $this;
 }
 /**
  * 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 LeasingCalendar $obj A LeasingCalendar 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
         LeasingCalendarPeer::$instances[$key] = $obj;
     }
 }
 /**
  * Filter the query by a related LeasingCalendar object
  *
  * @param   LeasingCalendar|PropelObjectCollection $leasingCalendar The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return                 LeasingUnitCalendarQuery The current query, for fluid interface
  * @throws PropelException - if the provided filter is invalid.
  */
 public function filterByLeasingCalendar($leasingCalendar, $comparison = null)
 {
     if ($leasingCalendar instanceof LeasingCalendar) {
         return $this->addUsingAlias(LeasingUnitCalendarPeer::CALENDAR_ID, $leasingCalendar->getId(), $comparison);
     } elseif ($leasingCalendar instanceof PropelObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(LeasingUnitCalendarPeer::CALENDAR_ID, $leasingCalendar->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByLeasingCalendar() only accepts arguments of type LeasingCalendar or PropelCollection');
     }
 }