/**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = CcShowInstancesPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setDbId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setDbStarts($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setDbEnds($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setDbShowId($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setDbRecord($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setDbRebroadcast($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setDbOriginalShow($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setDbRecordedFile($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setDbTimeFilled($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setDbCreated($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setDbLastScheduled($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setDbModifiedInstance($arr[$keys[11]]);
     }
 }
Exemple #2
0
 /**
  * Method to invalidate the instance pool of all tables related to cc_files
  * by a foreign key with ON DELETE CASCADE
  */
 public static function clearRelatedInstancePool()
 {
     // Invalidate objects in CcShowInstancesPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcShowInstancesPeer::clearInstancePool();
     // Invalidate objects in CcPlaylistcontentsPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcPlaylistcontentsPeer::clearInstancePool();
     // Invalidate objects in CcSchedulePeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcSchedulePeer::clearInstancePool();
 }
 /**
  * Selects a collection of CcShowSchedule objects pre-filled with all related objects.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of CcShowSchedule objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     CcShowSchedulePeer::addSelectColumns($criteria);
     $startcol2 = CcShowSchedulePeer::NUM_COLUMNS - CcShowSchedulePeer::NUM_LAZY_LOAD_COLUMNS;
     CcShowInstancesPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (CcShowInstancesPeer::NUM_COLUMNS - CcShowInstancesPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(CcShowSchedulePeer::INSTANCE_ID, CcShowInstancesPeer::ID, $join_behavior);
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = CcShowSchedulePeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = CcShowSchedulePeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://www.propelorm.org/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = CcShowSchedulePeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             CcShowSchedulePeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined CcShowInstances rows
         $key2 = CcShowInstancesPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = CcShowInstancesPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = CcShowInstancesPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 CcShowInstancesPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (CcShowSchedule) to the collection in $obj2 (CcShowInstances)
             $obj2->addCcShowSchedule($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
 /**
  * Find object by primary key
  * Use instance pooling to avoid a database query if the object exists
  * <code>
  * $obj  = $c->findPk(12, $con);
  * </code>
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con an optional connection object
  *
  * @return    CcShowInstances|array|mixed the result, formatted by the current formatter
  */
 public function findPk($key, $con = null)
 {
     if (null !== ($obj = CcShowInstancesPeer::getInstanceFromPool((string) $key)) && $this->getFormatter()->isObjectFormatter()) {
         // the object is alredy in the instance pool
         return $obj;
     } else {
         // the object has not been requested yet, or the formatter is not an object formatter
         $criteria = $this->isKeepQuery() ? clone $this : $this;
         $stmt = $criteria->filterByPrimaryKey($key)->getSelectStatement($con);
         return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
     }
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(CcShowInstancesPeer::DATABASE_NAME);
         $criteria->add(CcShowInstancesPeer::ID, $pks, Criteria::IN);
         $objs = CcShowInstancesPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Exemple #6
0
 public function resizeShow($deltaDay, $deltaMin, $instanceId)
 {
     $con = Propel::getConnection();
     if ($deltaDay > 0) {
         return _("Shows can have a max length of 24 hours.");
     }
     $utcTimezone = new DateTimeZone("UTC");
     $nowDateTime = new DateTime("now", $utcTimezone);
     //keep track of cc_show_day entries we need to update
     $showDayIds = array();
     /*
      * If the resized show is an edited instance of a repeating show we
      * need to treat it as a separate show and not resize the other instances
      * 
      * Also, if the resized show has edited instances, we need to exclude
      * those from the resize
      */
     $ccShow = CcShowQuery::create()->findPk($this->_showId);
     if ($ccShow->isRepeating()) {
         //convert instance to local timezone
         $ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId);
         $startsDT = $ccShowInstance->getDbStarts(null);
         $timezone = $ccShow->getFirstCcShowDay()->getDbTimezone();
         $startsDT->setTimezone(new DateTimeZone($timezone));
         /* Get cc_show_day for the current instance. If we don't find one
          * we know it is a repeat interval of one of cc_show_days first
          * show and we can assume we aren't resizing a modified instance
          */
         $ccShowDay = CcShowDaysQuery::create()->filterByDbFirstShow($startsDT->format("Y-m-d"))->filterByDbStartTime($startsDT->format("H:i:s"))->filterByDbShowId($this->_showId)->findOne();
         /* Check if this cc_show_day rule is non-repeating. If it is, then
          * we know this instance was edited out of the repeating sequence
          */
         if (!$ccShowDay || $ccShowDay->getDbRepeatType() != -1) {
             $ccShowDays = $ccShow->getRepeatingCcShowDays();
             foreach ($ccShowDays as $day) {
                 array_push($showDayIds, $day->getDbId());
             }
             $excludeIds = $ccShow->getEditedRepeatingInstanceIds();
             //exlcude edited instances from resize
             $showInstances = CcShowInstancesQuery::create()->filterByDbShowId($this->_showId)->filterByDbModifiedInstance(false)->filterByDbId($excludeIds, criteria::NOT_IN)->find();
         } elseif ($ccShowDay->getDbRepeatType() == -1) {
             array_push($showDayIds, $ccShowDay->getDbId());
             //treat edited instance as separate show for resize
             $showInstances = CcShowInstancesQuery::create()->filterByDbId($instanceId)->find();
         }
     } else {
         $ccShowDays = $ccShow->getCcShowDayss();
         foreach ($ccShowDays as $day) {
             array_push($showDayIds, $day->getDbId());
         }
         $showInstances = CcShowInstancesQuery::create()->filterByDbShowId($this->_showId)->find($con);
     }
     /* Check two things:
        1. If the show being resized and any of its repeats end in the past
        2. If the show being resized and any of its repeats overlap
           with other scheduled shows */
     //keep track of instance ids for update show instances start/end times
     $instanceIds = array();
     $displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
     //check if new show time overlaps with any other shows
     foreach ($showInstances as $si) {
         array_push($instanceIds, $si->getDbId());
         $startsDateTime = $si->getDbStarts(null);
         $endsDateTime = $si->getDbEnds(null);
         /* The user is moving the show on the calendar from the perspective
            of local time.  * incase a show is moved across a time change
            border offsets should be added to the local * timestamp and
            then converted back to UTC to avoid show time changes */
         $startsDateTime->setTimezone($displayTimezone);
         $endsDateTime->setTimezone($displayTimezone);
         //$newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin);
         $newEndsDateTime = Application_Model_ShowInstance::addDeltas($endsDateTime, $deltaDay, $deltaMin);
         if ($newEndsDateTime->getTimestamp() < $nowDateTime->getTimestamp()) {
             return _("End date/time cannot be in the past");
         }
         //convert our new starts/ends to UTC.
         //$newStartsDateTime->setTimezone($utc);
         $newEndsDateTime->setTimezone($utcTimezone);
         $overlapping = Application_Model_Schedule::checkOverlappingShows($startsDateTime, $newEndsDateTime, true, $si->getDbId());
         if ($overlapping) {
             return _("Cannot schedule overlapping shows.\nNote: Resizing a repeating show " . "affects all of its repeats.");
         }
     }
     $hours = $deltaMin / 60;
     $hours = $hours > 0 ? floor($hours) : ceil($hours);
     $mins = abs($deltaMin % 60);
     $sql_gen = "UPDATE cc_show_instances " . "SET ends = (ends + :deltaDay1::INTERVAL + :interval1::INTERVAL) " . "WHERE (id IN (" . implode($instanceIds, ",") . ") " . "AND ends > :current_timestamp1) " . "AND ((ends + :deltaDay2::INTERVAL + :interval2::INTERVAL - starts) <= interval '24:00')";
     Application_Common_Database::prepareAndExecute($sql_gen, array(':deltaDay1' => "{$deltaDay} days", ':interval1' => "{$hours}:{$mins}", ':current_timestamp1' => $nowDateTime->format("Y-m-d H:i:s"), ':deltaDay2' => "{$deltaDay} days", ':interval2' => "{$hours}:{$mins}"), "execute");
     $sql_gen = "UPDATE cc_show_days " . "SET duration = (CAST(duration AS interval) + :deltaDay3::INTERVAL + :interval3::INTERVAL) " . "WHERE id IN (" . implode($showDayIds, ",") . ") " . "AND ((CAST(duration AS interval) + :deltaDay4::INTERVAL + :interval4::INTERVAL) <= interval '24:00')";
     Application_Common_Database::prepareAndExecute($sql_gen, array(':deltaDay3' => "{$deltaDay} days", ':interval3' => "{$hours}:{$mins}", ':deltaDay4' => "{$deltaDay} days", ':interval4' => "{$hours}:{$mins}"), "execute");
     $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
     $con->beginTransaction();
     try {
         //update the status flag in cc_schedule.
         /* Since we didn't use a propel object when updating
          * cc_show_instances table we need to clear the instances
          * so the correct information is retrieved from the db
          */
         CcShowInstancesPeer::clearInstancePool();
         $instances = CcShowInstancesQuery::create()->filterByDbEnds($nowDateTime->format("Y-m-d H:i:s"), Criteria::GREATER_THAN)->filterByDbId($instanceIds, Criteria::IN)->find($con);
         foreach ($instances as $instance) {
             $instance->updateScheduleStatus($con);
         }
         $con->commit();
     } catch (Exception $e) {
         $con->rollback();
         Logging::info("Couldn't update schedule status.");
         Logging::info($e->getMessage());
     }
     Application_Model_RabbitMq::PushSchedule();
 }
Exemple #7
0
 /**
  * Method to invalidate the instance pool of all tables related to cc_show
  * by a foreign key with ON DELETE CASCADE
  */
 public static function clearRelatedInstancePool()
 {
     // Invalidate objects in CcShowInstancesPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcShowInstancesPeer::clearInstancePool();
     // Invalidate objects in CcShowDaysPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcShowDaysPeer::clearInstancePool();
     // Invalidate objects in CcShowRebroadcastPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcShowRebroadcastPeer::clearInstancePool();
     // Invalidate objects in CcShowHostsPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     CcShowHostsPeer::clearInstancePool();
 }