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; }
public function getBlockInfoAction() { $request = $this->getRequest(); $params = $request->getPost(); $bl = new Application_Model_Block($params['id']); if ($bl->isStatic()) { $out = $bl->getContents(); $out['isStatic'] = true; } else { $out = $bl->getCriteria(); $out['isStatic'] = false; } $this->_helper->json->sendJson($out); }
public static function findEntries($con, $displayColumns, $fromTable, $data, $dataProp = "aaData") { $librarySetting = Application_Model_Preference::getCurrentLibraryTableColumnMap(); //$displayColumns[] = 'owner'; // map that maps original column position to db name $current2dbname = array(); // array of search terms $orig2searchTerm = array(); foreach ($data as $key => $d) { if (strstr($key, "mDataProp_")) { list($dump, $index) = explode("_", $key); $current2dbname[$index] = $d; } elseif (strstr($key, "sSearch_")) { list($dump, $index) = explode("_", $key); $orig2searchTerm[$index] = $d; } } // map that maps dbname to searchTerm $dbname2searchTerm = array(); foreach ($current2dbname as $currentPos => $dbname) { $new_index = $librarySetting($currentPos); // TODO : Fix this retarded hack later. Just a band aid for // now at least we print some warnings so that we don't // forget about this -- cc-4462 if (array_key_exists($new_index, $orig2searchTerm)) { $dbname2searchTerm[$dbname] = $orig2searchTerm[$new_index]; } else { Logging::warn("Trying to reorder to unknown index\n printing as much debugging as possible..."); $debug = array('$new_index' => $new_index, '$currentPos' => $currentPos, '$orig2searchTerm' => $orig2searchTerm); Logging::warn($debug); } } $where = array(); /* Holds the parameters for binding after the statement has been prepared */ $params = array(); if (isset($data['advSearch']) && $data['advSearch'] === 'true') { $advancedWhere = self::buildWhereClauseForAdvancedSearch($dbname2searchTerm); if (!empty($advancedWhere['clause'])) { $where[] = join(" AND ", $advancedWhere['clause']); $params = $advancedWhere['params']; } } if ($data["sSearch"] !== "") { $searchTerms = explode(" ", $data["sSearch"]); } $selectorCount = "SELECT COUNT(*) "; $selectorRows = "SELECT " . join(",", $displayColumns) . " "; $sql = $selectorCount . " FROM " . $fromTable; $sqlTotalRows = $sql; if (isset($searchTerms)) { $searchCols = array(); for ($i = 0; $i < $data["iColumns"]; $i++) { if ($data["bSearchable_" . $i] == "true") { $searchCols[] = $data["mDataProp_{$i}"]; } } $outerCond = array(); $simpleWhere = array(); foreach ($searchTerms as $term) { foreach ($searchCols as $col) { $simpleWhere['clause']["simple_" . $col] = "{$col}::text ILIKE :simple_" . $col; $simpleWhere['params']["simple_" . $col] = "%" . $term . "%"; } $outerCond[] = "(" . implode(" OR ", $simpleWhere['clause']) . ")"; } $where[] = "(" . implode(" AND ", $outerCond) . ")"; $params = array_merge($params, $simpleWhere['params']); } // End Where clause // Order By clause $orderby = array(); for ($i = 0; $i < $data["iSortingCols"]; $i++) { $num = $data["iSortCol_" . $i]; $orderby[] = $data["mDataProp_{$num}"] . " " . $data["sSortDir_" . $i]; } $orderby[] = "id"; $orderby = join(",", $orderby); // End Order By clause $displayLength = intval($data["iDisplayLength"]); $needToBind = false; if (count($where) > 0) { $needToBind = true; $where = join(" OR ", $where); $sql = $selectorCount . " FROM " . $fromTable . " WHERE " . $where; $sqlTotalDisplayRows = $sql; $sql = $selectorRows . " FROM " . $fromTable . " WHERE " . $where . " ORDER BY " . $orderby; //limit the results returned. if ($displayLength !== -1) { $sql .= " OFFSET " . $data["iDisplayStart"] . " LIMIT " . $displayLength; } } else { $sql = $selectorRows . " FROM " . $fromTable . " ORDER BY " . $orderby; //limit the results returned. if ($displayLength !== -1) { $sql .= " OFFSET " . $data["iDisplayStart"] . " LIMIT " . $displayLength; } } try { $r = $con->query($sqlTotalRows); $totalRows = $r->fetchColumn(0); if (isset($sqlTotalDisplayRows)) { $totalDisplayRows = Application_Common_Database::prepareAndExecute($sqlTotalDisplayRows, $params, 'column'); } else { $totalDisplayRows = $totalRows; } //TODO if ($needToBind) { $results = Application_Common_Database::prepareAndExecute($sql, $params); } else { $stmt = $con->query($sql); $stmt->setFetchMode(PDO::FETCH_ASSOC); $results = $stmt->fetchAll(); } // we need to go over all items and fix length for playlist // in case the playlist contains dynamic block foreach ($results as &$r) { //this function is also called for Manage Users so in //this case there will be no 'ftype' if (isset($r['ftype'])) { if ($r['ftype'] == 'playlist') { $pl = new Application_Model_Playlist($r['id']); $r['length'] = $pl->getLength(); } elseif ($r['ftype'] == "block") { $bl = new Application_Model_Block($r['id']); $r['bl_type'] = $bl->isStatic() ? 'static' : 'dynamic'; $r['length'] = $bl->getLength(); } } } } catch (Exception $e) { Logging::debug($e->getMessage()); } return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => intval($totalDisplayRows), "iTotalRecords" => intval($totalRows), $dataProp => $results); }
/** *Function will load and return the contents of the requested playlist. */ public function getPlaylistAction() { // disable the view and the layout $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $playlistID = $this->_getParam('playlistID'); if (!isset($playlistID)) { return; } $pl = new Application_Model_Playlist($playlistID); $result = array(); foreach ($pl->getContents(true) as $ele) { if ($ele['type'] == 2) { // if element is a block expand and add $bl = new Application_Model_Block($ele['item_id']); if ($bl->isStatic()) { foreach ($bl->getContents(true) as $track) { $result[] = $this->createElementMap($track); } } } else { $result[] = $this->createElementMap($ele); } } $this->_helper->json($result); }
public function getLength() { if ($this->hasDynamicBlock()) { $ids = $this->getIdsOfDynamicBlocks(); $length = $this->pl->getDbLength(); foreach ($ids as $id) { $bl = new Application_Model_Block($id['id']); if ($bl->hasItemLimit()) { return "N/A"; } } $formatter = new LengthFormatter($length); return "~" . $formatter->format(); } else { return $this->pl->getDbLength(); } }
public function preValidation($params) { $data = Application_Model_Block::organizeSmartPlyalistCriteria($params['data']); // add elelments that needs to be added // set multioption for modifier according to criteria_field $modRowMap = array(); foreach ($data['criteria'] as $critKey => $d) { $count = 1; foreach ($d as $modKey => $modInfo) { if ($modKey == 0) { $eleCrit = $this->getElement("sp_criteria_field_" . $critKey . "_" . $modKey); $eleCrit->setValue($this->getCriteriaOptions($modInfo['sp_criteria_field'])); $eleCrit->setAttrib("disabled", null); $eleMod = $this->getElement("sp_criteria_modifier_" . $critKey . "_" . $modKey); $criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']]; if ($criteriaType == "s") { $eleMod->setMultiOptions($this->getStringCriteriaOptions()); } elseif ($criteriaType == "n") { $eleMod->setMultiOptions($this->getNumericCriteriaOptions()); } else { $eleMod->setMultiOptions(array('0' => _('Select modifier'))); } $eleMod->setValue($modInfo['sp_criteria_modifier']); $eleMod->setAttrib("disabled", null); $eleValue = $this->getElement("sp_criteria_value_" . $critKey . "_" . $modKey); $eleValue->setValue($modInfo['sp_criteria_value']); $eleValue->setAttrib("disabled", null); if (isset($modInfo['sp_criteria_extra'])) { $eleExtra = $this->getElement("sp_criteria_extra_" . $critKey . "_" . $modKey); $eleExtra->setValue($modInfo['sp_criteria_extra']); $eleValue->setAttrib('class', 'input_text sp_extra_input_text'); $eleExtra->setAttrib("disabled", null); } } else { $criteria = new Zend_Form_Element_Select("sp_criteria_field_" . $critKey . "_" . $modKey); $criteria->setAttrib('class', 'input_select sp_input_select sp-invisible')->setValue('Select criteria')->setDecorators(array('viewHelper'))->setMultiOptions($this->getCriteriaOptions()); $criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']]; $criteria->setValue($this->getCriteriaOptions($modInfo['sp_criteria_field'])); $this->addElement($criteria); /****************** MODIFIER ***********/ $criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_" . $critKey . "_" . $modKey); $criteriaModifers->setValue('Select modifier')->setAttrib('class', 'input_select sp_input_select')->setDecorators(array('viewHelper')); if ($criteriaType == "s") { $criteriaModifers->setMultiOptions($this->getStringCriteriaOptions()); } elseif ($criteriaType == "n") { $criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions()); } else { $criteriaModifers->setMultiOptions(array('0' => _('Select modifier'))); } $criteriaModifers->setValue($modInfo['sp_criteria_modifier']); $this->addElement($criteriaModifers); /****************** VALUE ***********/ $criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_" . $critKey . "_" . $modKey); $criteriaValue->setAttrib('class', 'input_text sp_input_text')->setDecorators(array('viewHelper')); $criteriaValue->setValue($modInfo['sp_criteria_value']); $this->addElement($criteriaValue); /****************** EXTRA ***********/ $criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_" . $critKey . "_" . $modKey); $criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')->setDecorators(array('viewHelper')); if (isset($modInfo['sp_criteria_extra'])) { $criteriaExtra->setValue($modInfo['sp_criteria_extra']); $criteriaValue->setAttrib('class', 'input_text sp_extra_input_text'); } else { $criteriaExtra->setAttrib('disabled', 'disabled'); } $this->addElement($criteriaExtra); $count++; } } $modRowMap[$critKey] = $count; } $decorator = $this->getDecorator("ViewScript"); $existingModRow = $decorator->getOption("modRowMap"); foreach ($modRowMap as $key => $v) { $existingModRow[$key] = $v; } $decorator->setOption("modRowMap", $existingModRow); // reconstruct the params['criteria'] so we can populate the form $formData = array(); foreach ($params['data'] as $ele) { $formData[$ele['name']] = $ele['value']; } $this->populate($formData); return $data; }
public function getFileMetadataAction() { $id = $this->_getParam('id'); $type = $this->_getParam('type'); try { if ($type == "audioclip") { $file = Application_Model_StoredFile::Recall($id); $this->view->type = $type; $md = $file->getMetadata(); foreach ($md as $key => $value) { if ($key == 'MDATA_KEY_DIRECTORY') { $musicDir = Application_Model_MusicDir::getDirByPK($value); $md['MDATA_KEY_FILEPATH'] = Application_Common_OsPath::join($musicDir->getDirectory(), $md['MDATA_KEY_FILEPATH']); } } $formatter = new SamplerateFormatter($md["MDATA_KEY_SAMPLERATE"]); $md["MDATA_KEY_SAMPLERATE"] = $formatter->format(); $formatter = new BitrateFormatter($md["MDATA_KEY_BITRATE"]); $md["MDATA_KEY_BITRATE"] = $formatter->format(); $formatter = new LengthFormatter($md["MDATA_KEY_DURATION"]); $md["MDATA_KEY_DURATION"] = $formatter->format(); $this->view->md = $md; } elseif ($type == "playlist") { $file = new Application_Model_Playlist($id); $this->view->type = $type; $md = $file->getAllPLMetaData(); $formatter = new LengthFormatter($md["dcterms:extent"]); $md["dcterms:extent"] = $formatter->format(); $this->view->md = $md; $this->view->contents = $file->getContents(); } elseif ($type == "block") { $block = new Application_Model_Block($id); $this->view->type = $type; $md = $block->getAllPLMetaData(); $formatter = new LengthFormatter($md["dcterms:extent"]); $md["dcterms:extent"] = $formatter->format(); $this->view->md = $md; if ($block->isStatic()) { $this->view->blType = 'Static'; $this->view->contents = $block->getContents(); } else { $this->view->blType = 'Dynamic'; $this->view->contents = $block->getCriteria(); } $this->view->block = $block; } elseif ($type == "stream") { $webstream = CcWebstreamQuery::create()->findPK($id); $ws = new Application_Model_Webstream($webstream); $md = $ws->getMetadata(); $this->view->md = $md; $this->view->type = $type; } } catch (Exception $e) { Logging::info($e->getMessage()); } }
public static function setIsPlaylist($p_playlistItems, $p_type, $p_status) { foreach ($p_playlistItems as $item) { $file = self::RecallById($item->getDbFileId()); $fileId = $file->_file->getDbId(); if ($p_type == 'playlist') { // we have to check if the file is in another playlist before // we can update if (!is_null($fileId) && !in_array($fileId, Application_Model_Playlist::getAllPlaylistFiles())) { $file->_file->setDbIsPlaylist($p_status)->save(); } } elseif ($p_type == 'block') { if (!is_null($fileId) && !in_array($fileId, Application_Model_Block::getAllBlockFiles())) { $file->_file->setDbIsPlaylist($p_status)->save(); } } } }