Exemplo n.º 1
0
 private static function buildWhereClauseForAdvancedSearch($dbname2searchTerm)
 {
     $where['clause'] = array();
     $where['params'] = array();
     foreach ($dbname2searchTerm as $dbname => $term) {
         $isRange = false;
         if (strstr($term, '~')) {
             $info = explode('~', $term);
             if ($dbname == 'utime' || $dbname == 'mtime') {
                 $input1 = isset($info[0]) ? Application_Common_DateHelper::ConvertToUtcDateTimeString($info[0]) : null;
                 $input2 = isset($info[1]) ? Application_Common_DateHelper::ConvertToUtcDateTimeString($info[1]) : null;
             } else {
                 if ($dbname == 'bit_rate') {
                     $input1 = isset($info[0]) ? intval($info[0]) * 1000 : null;
                     $input2 = isset($info[1]) ? intval($info[1]) * 1000 : null;
                 } else {
                     $input1 = isset($info[0]) ? $info[0] : null;
                     $input2 = isset($info[1]) ? $info[1] : null;
                 }
             }
             $isRange = true;
         } else {
             $input1 = $term;
         }
         if ($isRange) {
             $sub = array();
             if ($input1 != null) {
                 $sub[] = $dbname . " >= :" . $dbname . "1";
             }
             if ($input2 != null) {
                 $sub[] = $dbname . " <= :" . $dbname . "2";
             }
             if (!empty($sub)) {
                 $where['clause'][$dbname] = "(" . implode(' AND ', $sub) . ")";
                 if ($input1 != null) {
                     $where['params'][$dbname . "1"] = $input1;
                 }
                 if ($input2 != null) {
                     $where['params'][$dbname . "2"] = $input2;
                 }
             }
         } else {
             if (trim($input1) !== "") {
                 $where['clause'][$dbname] = $dbname . " ILIKE :" . $dbname . "1";
                 $where['params'][$dbname . "1"] = "%" . $input1 . "%";
             }
         }
     }
     return $where;
 }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 public function weekInfoAction()
 {
     if (Application_Model_Preference::GetAllow3rdPartyApi()) {
         // disable the view and the layout
         $this->view->layout()->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
         $date = new Application_Common_DateHelper();
         $dayStart = $date->getWeekStartDate();
         $utcDayStart = Application_Common_DateHelper::ConvertToUtcDateTimeString($dayStart);
         $dow = array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday");
         $result = array();
         for ($i = 0; $i < 7; $i++) {
             $utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart);
             $shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
             $utcDayStart = $utcDayEnd;
             Application_Model_Show::convertToLocalTimeZone($shows, array("starts", "ends", "start_timestamp", "end_timestamp"));
             $result[$dow[$i]] = $shows;
         }
         //used by caller to determine if the airtime they are running or widgets in use is out of date.
         $result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION;
         header("Content-type: text/javascript");
         // If a callback is not given, then just provide the raw JSON.
         echo isset($_GET['callback']) ? $_GET['callback'] . '(' . json_encode($result) . ')' : json_encode($result);
     } else {
         header('HTTP/1.0 401 Unauthorized');
         print 'You are not allowed to access this resource. ';
         exit;
     }
 }
Exemplo n.º 4
0
 public static function GetDayEndTimestampInUtc($time = "")
 {
     $dayEndTimestamp = Application_Common_DateHelper::GetDayEndTimestamp($time);
     return Application_Common_DateHelper::ConvertToUtcDateTimeString($dayEndTimestamp);
 }