/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this CcSubjs is new, it will return * an empty collection; or if this CcSubjs has previously * been saved, it will retrieve related CcFiless from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in CcSubjs. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelCollection|array CcFiles[] List of CcFiles objects */ public function getCcFilessJoinCcMusicDirs($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = CcFilesQuery::create(null, $criteria); $query->joinWith('CcMusicDirs', $join_behavior); return $this->getCcFiless($query, $con); }
public static function RecallByPartialFilepath($partial_path) { $path_info = Application_Model_MusicDir::splitFilePath($partial_path); if (is_null($path_info)) { return null; } $music_dir = Application_Model_MusicDir::getDirByPath($path_info[0]); $files = CcFilesQuery::create()->filterByDbDirectory($music_dir->getId())->filterByDbFilepath("{$path_info['1']}%")->find(); $res = array(); foreach ($files as $file) { $storedFile = new Application_Model_StoredFile(); $storedFile->_file = $file; $res[] = $storedFile; } return $res; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this CcMusicDirs is new, it will return * an empty collection; or if this CcMusicDirs has previously * been saved, it will retrieve related CcFiless from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in CcMusicDirs. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelCollection|array CcFiles[] List of CcFiles objects */ public function getCcFilessJoinCcSubjsRelatedByDbEditedby($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = CcFilesQuery::create(null, $criteria); $query->joinWith('CcSubjsRelatedByDbEditedby', $join_behavior); return $this->getCcFiless($query, $con); }
private function retrieveMediaFiles($id, $type) { $files = array(); if ($type === "audioclip") { $file = CcFilesQuery::create()->findPK($id, $this->con); if (is_null($file) || !$file->getDbFileExists()) { throw new Exception("A selected File does not exist!"); } else { $data = $this->fileInfo; $data["id"] = $id; $data["cliplength"] = $file->getDbLength(); $data["cueout"] = $file->getDbLength(); $defaultFade = Application_Model_Preference::GetDefaultFade(); if (isset($defaultFade)) { //fade is in format SS.uuuuuu $data["fadein"] = $defaultFade; $data["fadeout"] = $defaultFade; } $files[] = $data; } } elseif ($type === "playlist") { $pl = new Application_Model_Playlist($id); $contents = $pl->getContents(); foreach ($contents as $plItem) { if ($plItem['type'] == 0) { $data["id"] = $plItem['item_id']; $data["cliplength"] = $plItem['length']; $data["cuein"] = $plItem['cuein']; $data["cueout"] = $plItem['cueout']; $data["fadein"] = $plItem['fadein']; $data["fadeout"] = $plItem['fadeout']; $data["type"] = 0; $files[] = $data; } elseif ($plItem['type'] == 1) { $data["id"] = $plItem['item_id']; $data["cliplength"] = $plItem['length']; $data["cuein"] = $plItem['cuein']; $data["cueout"] = $plItem['cueout']; $data["fadein"] = "00.500000"; //$plItem['fadein']; $data["fadeout"] = "00.500000"; //$plItem['fadeout']; $data["type"] = 1; $files[] = $data; } elseif ($plItem['type'] == 2) { // if it's a block $bl = new Application_Model_Block($plItem['item_id']); if ($bl->isStatic()) { foreach ($bl->getContents() as $track) { $data["id"] = $track['item_id']; $data["cliplength"] = $track['length']; $data["cuein"] = $track['cuein']; $data["cueout"] = $track['cueout']; $data["fadein"] = $track['fadein']; $data["fadeout"] = $track['fadeout']; $data["type"] = 0; $files[] = $data; } } else { $dynamicFiles = $bl->getListOfFilesUnderLimit(); foreach ($dynamicFiles as $fileId => $f) { $file = CcFilesQuery::create()->findPk($fileId); if (isset($file) && $file->getDbFileExists()) { $data["id"] = $file->getDbId(); $data["cliplength"] = $file->getDbLength(); $data["cuein"] = "00:00:00"; $data["cueout"] = $file->getDbLength(); $defaultFade = Application_Model_Preference::GetDefaultFade(); if (isset($defaultFade)) { //fade is in format SS.uuuuuu $data["fadein"] = $defaultFade; $data["fadeout"] = $defaultFade; } $data["type"] = 0; $files[] = $data; } } } } } } elseif ($type == "stream") { //need to return $stream = CcWebstreamQuery::create()->findPK($id, $this->con); if (is_null($stream)) { throw new Exception("A selected File does not exist!"); } else { $data = $this->fileInfo; $data["id"] = $id; $data["cliplength"] = $stream->getDbLength(); $data["cueout"] = $stream->getDbLength(); $data["type"] = 1; $defaultFade = Application_Model_Preference::GetDefaultFade(); if (isset($defaultFade)) { //fade is in format SS.uuuuuu $data["fadein"] = $defaultFade; $data["fadeout"] = $defaultFade; } $files[] = $data; } } elseif ($type == "block") { $bl = new Application_Model_Block($id); if ($bl->isStatic()) { foreach ($bl->getContents() as $track) { $data["id"] = $track['item_id']; $data["cliplength"] = $track['length']; $data["cuein"] = $track['cuein']; $data["cueout"] = $track['cueout']; $data["fadein"] = $track['fadein']; $data["fadeout"] = $track['fadeout']; $data["type"] = 0; $files[] = $data; } } else { $dynamicFiles = $bl->getListOfFilesUnderLimit(); foreach ($dynamicFiles as $fileId => $f) { $file = CcFilesQuery::create()->findPk($fileId); if (isset($file) && $file->getDbFileExists()) { $data["id"] = $file->getDbId(); $data["cliplength"] = $file->getDbLength(); $data["cuein"] = "00:00:00"; $data["cueout"] = $file->getDbLength(); $defaultFade = Application_Model_Preference::GetDefaultFade(); if (isset($defaultFade)) { //fade is in format SS.uuuuuu $data["fadein"] = $defaultFade; $data["fadeout"] = $defaultFade; } $data["type"] = 0; $files[] = $data; } } } } return $files; }
/** * Get the associated CcFiles object * * @param PropelPDO Optional Connection object. * @return CcFiles The associated CcFiles object. * @throws PropelException */ public function getCcFiles(PropelPDO $con = null) { if ($this->aCcFiles === null && $this->file_id !== null) { $this->aCcFiles = CcFilesQuery::create()->findPk($this->file_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aCcFiles->addCcShowInstancess($this); */ } return $this->aCcFiles; }
public function removeItems($scheduledItems, $adjustSched = true, $cancelShow = false) { $showInstances = array(); $this->con->beginTransaction(); try { $this->validateRequest($scheduledItems); $scheduledIds = array(); foreach ($scheduledItems as $item) { $scheduledIds[] = $item["id"]; } $removedItems = CcScheduleQuery::create()->findPks($scheduledIds); //check to make sure all items selected are up to date foreach ($removedItems as $removedItem) { $instance = $removedItem->getCcShowInstances($this->con); //check if instance is linked and if so get the schedule items //for all linked instances so we can delete them too if (!$cancelShow && $instance->getCcShow()->isLinked()) { //returns all linked instances if linked $ccShowInstances = $this->getInstances($instance->getDbId()); $instanceIds = array(); foreach ($ccShowInstances as $ccShowInstance) { $instanceIds[] = $ccShowInstance->getDbId(); } /* * Find all the schedule items that are in the same position * as the selected item by the user. * The position of each track is the same across each linked instance */ $itemsToDelete = CcScheduleQuery::create()->filterByDbPosition($removedItem->getDbPosition())->filterByDbInstanceId($instanceIds, Criteria::IN)->find(); foreach ($itemsToDelete as $item) { if (!$removedItems->contains($item)) { $removedItems->append($item); } } } //check to truncate the currently playing item instead of deleting it. if ($removedItem->isCurrentItem($this->epochNow)) { $nEpoch = $this->epochNow; $sEpoch = $removedItem->getDbStarts('U.u'); $length = bcsub($nEpoch, $sEpoch, 6); $cliplength = Application_Common_DateHelper::secondsToPlaylistTime($length); $cueinSec = Application_Common_DateHelper::playlistTimeToSeconds($removedItem->getDbCueIn()); $cueOutSec = bcadd($cueinSec, $length, 6); $cueout = Application_Common_DateHelper::secondsToPlaylistTime($cueOutSec); //Set DbEnds - 1 second because otherwise there can be a timing issue //when sending the new schedule to Pypo where Pypo thinks the track is still //playing. $removedItem->setDbCueOut($cueout)->setDbClipLength($cliplength)->setDbEnds($this->nowDT)->save($this->con); } else { $removedItem->delete($this->con); } // update is_scheduled in cc_files but only if // the file is not scheduled somewhere else $fileId = $removedItem->getDbFileId(); // check if the removed item is scheduled somewhere else $futureScheduledFiles = Application_Model_Schedule::getAllFutureScheduledFiles(); if (!is_null($fileId) && !in_array($fileId, $futureScheduledFiles)) { $db_file = CcFilesQuery::create()->findPk($fileId, $this->con); $db_file->setDbIsScheduled(false)->save($this->con); } } if ($adjustSched === true) { //get the show instances of the shows we must adjust times for. foreach ($removedItems as $item) { $instance = $item->getDBInstanceId(); if (!in_array($instance, $showInstances)) { $showInstances[] = $instance; } } foreach ($showInstances as $instance) { $this->removeGaps($instance); $this->calculateCrossfades($instance); } } //update the status flag in cc_schedule. $instances = CcShowInstancesQuery::create()->filterByPrimaryKeys($showInstances)->find($this->con); foreach ($instances as $instance) { $instance->updateScheduleStatus($this->con); $instance->correctSchedulePositions(); } //update the last scheduled timestamp. CcShowInstancesQuery::create()->filterByPrimaryKeys($showInstances)->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con); $this->con->commit(); Application_Model_RabbitMq::PushSchedule(); } catch (Exception $e) { $this->con->rollback(); throw $e; } }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $ret = $this->preDelete($con); if ($ret) { CcFilesQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (PropelException $e) { $con->rollBack(); throw $e; } }
/** * Fetch instance of StoreFile object.<br> * Should be supplied with only ONE parameter, all the rest should * be NULL. * * @param int $p_id * local id * @param string $p_gunid * global unique id of file * @param string $p_md5sum * MD5 sum of the file * @return StoredFile|NULL * Return NULL if the object doesnt exist in the DB. */ public static function Recall($p_id = null, $p_gunid = null, $p_md5sum = null, $p_filepath = null) { if (isset($p_id)) { $file = CcFilesQuery::create()->findPK(intval($p_id)); } else { if (isset($p_gunid)) { $file = CcFilesQuery::create()->filterByDbGunid($p_gunid)->findOne(); } else { if (isset($p_md5sum)) { $file = CcFilesQuery::create()->filterByDbMd5($p_md5sum)->findOne(); } else { if (isset($p_filepath)) { $path_info = MusicDir::splitFilePath($p_filepath); if (is_null($path_info)) { return null; } $music_dir = MusicDir::getDirByPath($path_info[0]); $file = CcFilesQuery::create()->filterByDbDirectory($music_dir->getId())->filterByDbFilepath($path_info[1])->findOne(); } else { return null; } } } } if (isset($file)) { $storedFile = new StoredFile(); $storedFile->_file = $file; return $storedFile; } else { return null; } }
public function addAudioClips($p_items, $p_afterItem = null, $addType = 'after') { $this->con->beginTransaction(); $contentsToUpdate = array(); try { if (is_numeric($p_afterItem)) { $afterItem = CcPlaylistcontentsQuery::create()->findPK($p_afterItem); $index = $afterItem->getDbPosition(); $pos = $addType == 'after' ? $index + 1 : $index; $contentsToUpdate = CcPlaylistcontentsQuery::create()->filterByDbPlaylistId($this->id)->filterByDbPosition($pos, Criteria::GREATER_EQUAL)->orderByDbPosition()->find($this->con); } else { //add to the end of the playlist if ($addType == 'after') { $pos = $this->getSize(); } else { $pos = 0; $contentsToUpdate = CcPlaylistcontentsQuery::create()->filterByDbPlaylistId($this->id)->orderByDbPosition()->find($this->con); } $contentsToUpdate = CcPlaylistcontentsQuery::create()->filterByDbPlaylistId($this->id)->filterByDbPosition($pos, Criteria::GREATER_EQUAL)->orderByDbPosition()->find($this->con); } foreach ($p_items as $ac) { $res = $this->insertPlaylistElement($this->buildEntry($ac, $pos)); // update is_playlist flag in cc_files to indicate the // file belongs to a playlist or block (in this case a playlist) if ($ac[1] == "audioclip") { $db_file = CcFilesQuery::create()->findPk($ac[0], $this->con); $db_file->setDbIsPlaylist(true)->save($this->con); } $pos = $pos + 1; } //reset the positions of the remaining items. for ($i = 0; $i < count($contentsToUpdate); $i++) { $contentsToUpdate[$i]->setDbPosition($pos); $contentsToUpdate[$i]->save($this->con); $pos = $pos + 1; } $this->pl->setDbMtime(new DateTime("now", new DateTimeZone("UTC"))); $this->pl->save($this->con); $this->con->commit(); } catch (Exception $e) { $this->con->rollback(); throw $e; } }
public function getListofFilesMeetCriteria() { $storedCrit = $this->getCriteria(); $qry = CcFilesQuery::create(); $qry->useFkOwnerQuery("subj", "left join"); if (isset($storedCrit["crit"])) { foreach ($storedCrit["crit"] as $crit) { $i = 0; foreach ($crit as $criteria) { //$spCriteriaPhpName = self::$criteria2PeerMap[$criteria['criteria']]; $spCriteria = $criteria['criteria']; $spCriteriaModifier = $criteria['modifier']; $column = CcFilesPeer::getTableMap()->getColumnByPhpName(self::$criteria2PeerMap[$spCriteria]); // if the column is timestamp, convert it into UTC if ($column->getType() == PropelColumnTypes::TIMESTAMP) { $spCriteriaValue = Application_Common_DateHelper::ConvertToUtcDateTimeString($criteria['value']); /* Check if only a date was supplied and trim * the time after it is converted to UTC time */ if (strlen($criteria['value']) <= 10) { //extract date only from timestamp in db $spCriteria = 'date(' . $spCriteria . ')'; $spCriteriaValue = substr($spCriteriaValue, 0, 10); } if (isset($criteria['extra'])) { $spCriteriaExtra = Application_Common_DateHelper::ConvertToUtcDateTimeString($criteria['extra']); if (strlen($criteria['extra']) <= 10) { $spCriteriaExtra = substr($spCriteriaExtra, 0, 10); } } } elseif ($spCriteria == "bit_rate" || $spCriteria == 'sample_rate') { // multiply 1000 because we store only number value // e.g 192kps is stored as 192000 $spCriteriaValue = $criteria['value'] * 1000; if (isset($criteria['extra'])) { $spCriteriaExtra = $criteria['extra'] * 1000; } /* * If user is searching for an exact match of length we need to * search as if it starts with the specified length because the * user only sees the rounded version (i.e. 4:02.7 is 4:02.761625 * in the database) */ } elseif ($spCriteria == 'length' && $spCriteriaModifier == "is") { $spCriteriaModifier = "starts with"; $spCriteria = $spCriteria . '::text'; $spCriteriaValue = $criteria['value']; } else { /* Propel does not escape special characters properly when using LIKE/ILIKE * We have to add extra slashes in these cases */ $tempModifier = trim(self::$modifier2CriteriaMap[$spCriteriaModifier]); if ($tempModifier == 'ILIKE') { $spCriteriaValue = addslashes($criteria['value']); // addslashes() does not esapce '%' so we have to do it manually $spCriteriaValue = str_replace('%', '\\%', $spCriteriaValue); } else { $spCriteriaValue = $criteria['value']; } $spCriteriaExtra = $criteria['extra']; } if ($spCriteriaModifier == "starts with") { $spCriteriaValue = "{$spCriteriaValue}%"; } elseif ($spCriteriaModifier == "ends with") { $spCriteriaValue = "%{$spCriteriaValue}"; } elseif ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") { $spCriteriaValue = "%{$spCriteriaValue}%"; } elseif ($spCriteriaModifier == "is in the range") { $spCriteriaValue = "{$spCriteria} >= '{$spCriteriaValue}' AND {$spCriteria} <= '{$spCriteriaExtra}'"; } $spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier]; try { if ($spCriteria == "owner_id") { $spCriteria = "subj.login"; } if ($i > 0) { $qry->addOr($spCriteria, $spCriteriaValue, $spCriteriaModifier); } else { $qry->add($spCriteria, $spCriteriaValue, $spCriteriaModifier); } if ($spCriteriaModifier == Criteria::NOT_ILIKE || $spCriteriaModifier == Criteria::NOT_EQUAL) { $qry->addOr($spCriteria, null, Criteria::ISNULL); } } catch (Exception $e) { Logging::info($e); } $i++; } } // check if file exists $qry->add("file_exists", "true", Criteria::EQUAL); $qry->addAscendingOrderByColumn('random()'); } // construct limit restriction $limits = array(); if (isset($storedCrit['limit'])) { if ($storedCrit['limit']['modifier'] == "items") { $limits['time'] = 1440 * 60; $limits['items'] = $storedCrit['limit']['value']; } else { $limits['time'] = $storedCrit['limit']['modifier'] == "hours" ? intval(floatval($storedCrit['limit']['value']) * 60 * 60) : intval($storedCrit['limit']['value'] * 60); $limits['items'] = null; } } try { $out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find(); return array("files" => $out, "limit" => $limits, "count" => $out->count()); } catch (Exception $e) { Logging::info($e); } }
/** There are 2 cases where this function can be called. * 1. When watched dir was added * 2. When some dir was watched, but it was unmounted somehow, but gets mounted again * * In case of 1, $userAddedWatchedDir should be true * In case of 2, $userAddedWatchedDir should be false * * When $userAddedWatchedDir is true, it will set "Watched" flag to true * otherwise, it will set "Exists" flag to true **/ public static function addWatchedDir($p_path, $userAddedWatchedDir = true, $nestedWatch = false) { $res = self::addDir($p_path, "watched", $userAddedWatchedDir, $nestedWatch); if ($res['code'] == 0) { //convert "linked" files (Airtime <= 1.8.2) to watched files. $propel_link_dir = CcMusicDirsQuery::create()->filterByType('link')->findOne(); //see if any linked files exist. if (isset($propel_link_dir)) { //newly added watched directory object $propel_new_watch = CcMusicDirsQuery::create()->filterByDirectory(Application_Common_OsPath::normpath($p_path) . "/")->findOne(); //any files of the deprecated "link" type. $link_files = CcFilesQuery::create()->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->filterByDbDirectory($propel_link_dir->getId())->find(); $newly_watched_dir = $propel_new_watch->getDirectory(); foreach ($link_files as $link_file) { $link_filepath = $link_file->getDbFilepath(); //convert "link" file into a watched file. if (strlen($newly_watched_dir) < strlen($link_filepath) && substr($link_filepath, 0, strlen($newly_watched_dir)) === $newly_watched_dir) { //get the filepath path not including the watched directory. $sub_link_filepath = substr($link_filepath, strlen($newly_watched_dir)); $link_file->setDbDirectory($propel_new_watch->getId()); $link_file->setDbFilepath($sub_link_filepath); $link_file->save(); } } } $data = array(); $data["directory"] = $p_path; Application_Model_RabbitMq::SendMessageToMediaMonitor("new_watch", $data); } return $res; }
private function buildEntry($p_item, $pos) { $objType = $p_item[1]; $objId = $p_item[0]; if ($objType == 'audioclip') { $obj = CcFilesQuery::create()->findPK($objId, $this->con); } elseif ($objType == "stream") { $obj = CcWebstreamQuery::create()->findPK($objId, $this->con); } elseif ($objType == "block") { $obj = CcBlockQuery::create()->findPK($objId, $this->con); } else { throw new Exception("Unknown file type"); } if (isset($obj)) { if ($obj instanceof CcFiles && $obj->getDbFileExists() || $obj instanceof CcWebstream || $obj instanceof CcBlock) { $entry = $this->plItem; $entry["id"] = $obj->getDbId(); $entry["pos"] = $pos; $entry["cliplength"] = $obj->getDbLength(); $entry["cueout"] = $obj->getDbLength(); $entry["ftype"] = $objType; } return $entry; } else { throw new Exception("trying to add a object that does not exist."); } }