/**
  * Finds the related CcBlock objects and keep them for later
  *
  * @param PropelPDO $con A connection object
  */
 protected function findRelatedCcBlocks($con)
 {
     $criteria = clone $this;
     if ($this->useAliasInSQL) {
         $alias = $this->getModelAlias();
         $criteria->removeAlias($alias);
     } else {
         $alias = '';
     }
     $this->ccBlocks = CcBlockQuery::create()->joinCcBlockcontents($alias)->mergeWith($criteria)->find($con);
 }
 /**
  * Get the associated CcBlock object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     CcBlock The associated CcBlock object.
  * @throws     PropelException
  */
 public function getCcBlock(PropelPDO $con = null)
 {
     if ($this->aCcBlock === null && $this->block_id !== null) {
         $this->aCcBlock = CcBlockQuery::create()->findPk($this->block_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->aCcBlock->addCcPlaylistcontentss($this);
         		 */
     }
     return $this->aCcBlock;
 }
示例#3
0
文件: Block.php 项目: nidzix/Airtime
 public function saveType($p_blockType)
 {
     // saving dynamic/static flag
     CcBlockQuery::create()->findPk($this->id)->setDbType($p_blockType)->save();
 }
示例#4
0
 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->visible() || $obj instanceof CcWebstream || $obj instanceof CcBlock) {
             $entry = $this->plItem;
             $entry["id"] = $obj->getDbId();
             $entry["pos"] = $pos;
             $entry["cliplength"] = $obj->getDbLength();
             if ($obj instanceof CcFiles && $obj) {
                 $entry["cuein"] = isset($p_item['cuein']) ? $p_item['cuein'] : $obj->getDbCuein();
                 $entry["cueout"] = isset($p_item['cueout']) ? $p_item['cueout'] : $obj->getDbCueout();
                 $cue_in = isset($p_item['cueInSec']) ? $p_item['cueInSec'] : Application_Common_DateHelper::calculateLengthInSeconds($entry['cuein']);
                 $cue_out = isset($p_item['cueOutSec']) ? $p_item['cueOutSec'] : Application_Common_DateHelper::calculateLengthInSeconds($entry['cueout']);
                 $entry["cliplength"] = isset($p_item['length']) ? $p_item['length'] : Application_Common_DateHelper::secondsToPlaylistTime($cue_out - $cue_in);
             } elseif ($obj instanceof CcWebstream && $obj) {
                 $entry["cuein"] = "00:00:00";
                 $entry["cueout"] = $entry["cliplength"];
             }
             $entry["ftype"] = $objType;
             $entry["fadein"] = isset($p_item['fadein']) ? $p_item['fadein'] : $entry["fadein"];
             $entry["fadeout"] = isset($p_item['fadeout']) ? $p_item['fadeout'] : $entry["fadeout"];
         }
         return $entry;
     } else {
         throw new Exception("trying to add a object that does not exist.");
     }
 }
 public function startForm($p_blockId, $p_isValid = false)
 {
     // load type
     $out = CcBlockQuery::create()->findPk($p_blockId);
     if ($out->getDbType() == "static") {
         $blockType = 0;
     } else {
         $blockType = 1;
     }
     $spType = new Zend_Form_Element_Radio('sp_type');
     $spType->setLabel(_('Set smart block type:'))->setDecorators(array('viewHelper'))->setMultiOptions(array('static' => _('Static'), 'dynamic' => _('Dynamic')))->setValue($blockType);
     $this->addElement($spType);
     $bl = new Application_Model_Block($p_blockId);
     $storedCrit = $bl->getCriteria();
     //need to convert criteria to be displayed in the user's timezone if there's some timestamp type.
     self::convertTimestamps($storedCrit["crit"]);
     /* $modRoadMap stores the number of same criteria
      * Ex: 3 Album titles, and 2 Track titles
      * We need to know this so we display the form elements properly
      */
     $modRowMap = array();
     $openSmartBlockOption = false;
     if (!empty($storedCrit)) {
         $openSmartBlockOption = true;
     }
     $criteriaKeys = array();
     if (isset($storedCrit["crit"])) {
         $criteriaKeys = array_keys($storedCrit["crit"]);
     }
     $numElements = count($this->getCriteriaOptions());
     for ($i = 0; $i < $numElements; $i++) {
         $criteriaType = "";
         if (isset($criteriaKeys[$i])) {
             $critCount = count($storedCrit["crit"][$criteriaKeys[$i]]);
         } else {
             $critCount = 1;
         }
         $modRowMap[$i] = $critCount;
         /* Loop through all criteria with the same field
          * Ex: all criteria for 'Album'
          */
         for ($j = 0; $j < $critCount; $j++) {
             /****************** CRITERIA ***********/
             if ($j > 0) {
                 $invisible = ' sp-invisible';
             } else {
                 $invisible = '';
             }
             $criteria = new Zend_Form_Element_Select("sp_criteria_field_" . $i . "_" . $j);
             $criteria->setAttrib('class', 'input_select sp_input_select' . $invisible)->setValue('Select criteria')->setDecorators(array('viewHelper'))->setMultiOptions($this->getCriteriaOptions());
             if ($i != 0 && !isset($criteriaKeys[$i])) {
                 $criteria->setAttrib('disabled', 'disabled');
             }
             if (isset($criteriaKeys[$i])) {
                 $criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]];
                 $criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]);
             }
             $this->addElement($criteria);
             /****************** MODIFIER ***********/
             $criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_" . $i . "_" . $j);
             $criteriaModifers->setValue('Select modifier')->setAttrib('class', 'input_select sp_input_select')->setDecorators(array('viewHelper'));
             if ($i != 0 && !isset($criteriaKeys[$i])) {
                 $criteriaModifers->setAttrib('disabled', 'disabled');
             }
             if (isset($criteriaKeys[$i])) {
                 if ($criteriaType == "s") {
                     $criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
                 } else {
                     $criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
                 }
                 $criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]);
             } else {
                 $criteriaModifers->setMultiOptions(array('0' => _('Select modifier')));
             }
             $this->addElement($criteriaModifers);
             /****************** VALUE ***********/
             $criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_" . $i . "_" . $j);
             $criteriaValue->setAttrib('class', 'input_text sp_input_text')->setDecorators(array('viewHelper'));
             if ($i != 0 && !isset($criteriaKeys[$i])) {
                 $criteriaValue->setAttrib('disabled', 'disabled');
             }
             if (isset($criteriaKeys[$i])) {
                 $criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
             }
             $this->addElement($criteriaValue);
             /****************** EXTRA ***********/
             $criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_" . $i . "_" . $j);
             $criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')->setDecorators(array('viewHelper'));
             if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"])) {
                 $criteriaExtra->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]);
                 $criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
             } else {
                 $criteriaExtra->setAttrib('disabled', 'disabled');
             }
             $this->addElement($criteriaExtra);
         }
         //for
     }
     //for
     $repeatTracks = new Zend_Form_Element_Checkbox('sp_repeat_tracks');
     $repeatTracks->setDecorators(array('viewHelper'))->setLabel(_('Allow Repeat Tracks:'));
     if (isset($storedCrit["repeat_tracks"])) {
         $repeatTracks->setChecked($storedCrit["repeat_tracks"]["value"] == 1 ? true : false);
     }
     $this->addElement($repeatTracks);
     $limit = new Zend_Form_Element_Select('sp_limit_options');
     $limit->setAttrib('class', 'sp_input_select')->setDecorators(array('viewHelper'))->setMultiOptions($this->getLimitOptions());
     if (isset($storedCrit["limit"])) {
         $limit->setValue($storedCrit["limit"]["modifier"]);
     }
     $this->addElement($limit);
     $limitValue = new Zend_Form_Element_Text('sp_limit_value');
     $limitValue->setAttrib('class', 'sp_input_text_limit')->setLabel(_('Limit to'))->setDecorators(array('viewHelper'));
     $this->addElement($limitValue);
     if (isset($storedCrit["limit"])) {
         $limitValue->setValue($storedCrit["limit"]["value"]);
     } else {
         // setting default to 1 hour
         $limitValue->setValue(1);
     }
     //getting block content candidate count that meets criteria
     $bl = new Application_Model_Block($p_blockId);
     if ($p_isValid) {
         $files = $bl->getListofFilesMeetCriteria();
         $showPoolCount = true;
     } else {
         $files = null;
         $showPoolCount = false;
     }
     $generate = new Zend_Form_Element_Button('generate_button');
     $generate->setAttrib('class', 'btn btn-small');
     $generate->setAttrib('title', _('Generate playlist content and save criteria'));
     $generate->setIgnore(true);
     $generate->setLabel(_('Generate'));
     $generate->setDecorators(array('viewHelper'));
     $this->addElement($generate);
     $shuffle = new Zend_Form_Element_Button('shuffle_button');
     $shuffle->setAttrib('class', 'btn btn-small');
     $shuffle->setAttrib('title', _('Shuffle playlist content'));
     $shuffle->setIgnore(true);
     $shuffle->setLabel(_('Shuffle'));
     $shuffle->setDecorators(array('viewHelper'));
     $this->addElement($shuffle);
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'form/smart-block-criteria.phtml', "openOption" => $openSmartBlockOption, 'criteriasLength' => count($this->getCriteriaOptions()), 'poolCount' => $files['count'], 'modRowMap' => $modRowMap, 'showPoolCount' => $showPoolCount))));
 }
示例#6
0
 /**
  * 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(CcBlockPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $ret = $this->preDelete($con);
         if ($ret) {
             CcBlockQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
示例#7
0
 /**
  * Returns the number of related CcBlock objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related CcBlock objects.
  * @throws     PropelException
  */
 public function countCcBlocks(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collCcBlocks || null !== $criteria) {
         if ($this->isNew() && null === $this->collCcBlocks) {
             return 0;
         } else {
             $query = CcBlockQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByCcSubjs($this)->count($con);
         }
     } else {
         return count($this->collCcBlocks);
     }
 }
示例#8
0
 /**
  * Delete stored virtual file
  *
  * @param boolean $p_deleteFile
  *
  */
 public function delete()
 {
     $filepath = $this->getFilePath();
     // Check if the file is scheduled to be played in the future
     if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) {
         throw new DeleteScheduledFileException();
     }
     $userInfo = Zend_Auth::getInstance()->getStorage()->read();
     $user = new Application_Model_User($userInfo->id);
     $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
     if (!$isAdminOrPM && $this->getFileOwnerId() != $user->getId()) {
         throw new FileNoPermissionException();
     }
     $music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory());
     $type = $music_dir->getType();
     if (file_exists($filepath) && $type == "stor") {
         $data = array("filepath" => $filepath, "delete" => 1);
         try {
             Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
         } catch (Exception $e) {
             Logging::error($e->getMessage());
             return;
         }
     }
     // set hidden flag to true
     $this->_file->setDbHidden(true);
     $this->_file->save();
     // need to explicitly update any playlist's and block's length
     // that contains the file getting deleted
     $fileId = $this->_file->getDbId();
     $plRows = CcPlaylistcontentsQuery::create()->filterByDbFileId()->find();
     foreach ($plRows as $row) {
         $pl = CcPlaylistQuery::create()->filterByDbId($row->getDbPlaylistId($fileId))->findOne();
         $pl->setDbLength($pl->computeDbLength(Propel::getConnection(CcPlaylistPeer::DATABASE_NAME)));
         $pl->save();
     }
     $blRows = CcBlockcontentsQuery::create()->filterByDbFileId($fileId)->find();
     foreach ($blRows as $row) {
         $bl = CcBlockQuery::create()->filterByDbId($row->getDbBlockId())->findOne();
         $bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME)));
         $bl->save();
     }
 }
示例#9
0
 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.");
     }
 }