当前位置: 首页>>代码示例>>PHP>>正文


PHP Search::to_sql方法代码示例

本文整理汇总了PHP中Search::to_sql方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::to_sql方法的具体用法?PHP Search::to_sql怎么用?PHP Search::to_sql使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Search的用法示例。


在下文中一共展示了Search::to_sql方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: song_to_sql

 /**
  * song_to_sql
  * Handles the generation of the SQL for song searches.
  */
 private function song_to_sql()
 {
     $sql_logic_operator = $this->logic_operator;
     $where = array();
     $table = array();
     $join = array();
     $group = array();
     $having = array();
     $join['tag'] = array();
     foreach ($this->rules as $rule) {
         $type = $this->name_to_basetype($rule[0]);
         $operator = array();
         foreach ($this->basetypes[$type] as $op) {
             if ($op['name'] == $rule[1]) {
                 $operator = $op;
                 break;
             }
         }
         $input = $this->_mangle_data($rule[2], $type, $operator);
         $sql_match_operator = $operator['sql'];
         switch ($rule[0]) {
             case 'anywhere':
                 $where[] = "(`artist`.`name` {$sql_match_operator} '{$input}' OR `album`.`name` {$sql_match_operator} '{$input}' OR `song_data`.`comment` {$sql_match_operator} '{$input}' OR `song_data`.`label` {$sql_match_operator} '{$input}' OR `song`.`file` {$sql_match_operator} '{$input}' OR `song`.`title` {$sql_match_operator} '{$input}')";
                 $join['album'] = true;
                 $join['artist'] = true;
                 $join['song_data'] = true;
                 break;
             case 'tag':
                 $key = md5($input . $sql_match_operator);
                 $where[] = "`realtag_{$key}`.`match` > 0";
                 $join['tag'][$key] = "{$sql_match_operator} '{$input}'";
                 break;
             case 'album_tag':
                 $key = md5($input . $sql_match_operator);
                 $where[] = "`realtag_{$key}`.`match` > 0";
                 $join['album_tag'][$key] = "{$sql_match_operator} '{$input}'";
                 $join['album'] = true;
                 break;
             case 'title':
                 $where[] = "`song`.`title` {$sql_match_operator} '{$input}'";
                 break;
             case 'album':
                 $where[] = "`album`.`name` {$sql_match_operator} '{$input}'";
                 $join['album'] = true;
                 break;
             case 'artist':
                 $where[] = "`artist`.`name` {$sql_match_operator} '{$input}'";
                 $join['artist'] = true;
                 break;
             case 'composer':
                 $where[] = "`song`.`composer` {$sql_match_operator} '{$input}'";
                 break;
             case 'time':
                 $input = $input * 60;
                 $where[] = "`song`.`time` {$sql_match_operator} '{$input}'";
                 break;
             case 'file':
                 $where[] = "`song`.`file` {$sql_match_operator} '{$input}'";
                 break;
             case 'year':
                 $where[] = "`song`.`year` {$sql_match_operator} '{$input}'";
                 break;
             case 'comment':
                 $where[] = "`song_data`.`comment` {$sql_match_operator} '{$input}'";
                 $join['song_data'] = true;
                 break;
             case 'label':
                 $where[] = "`song_data`.`label` {$sql_match_operator} '{$input}'";
                 $join['song_data'] = true;
                 break;
             case 'played':
                 $where[] = " `song`.`played` = '{$input}'";
                 break;
             case 'bitrate':
                 $input = $input * 1000;
                 $where[] = "`song`.`bitrate` {$sql_match_operator} '{$input}'";
                 break;
             case 'rating':
                 if ($this->type != "public") {
                     $where[] = "COALESCE(`rating`.`rating`,0) {$sql_match_operator} '{$input}'";
                 } else {
                     $group[] = "`song`.`id`";
                     $having[] = "ROUND(AVG(IFNULL(`rating`.`rating`,0))) {$sql_match_operator} '{$input}'";
                 }
                 $join['rating'] = true;
                 break;
             case 'played_times':
                 $where[] = "`song`.`id` IN (SELECT `object_count`.`object_id` FROM `object_count` " . "WHERE `object_count`.`object_type` = 'song' AND `object_count`.`count_type` = 'stream' " . "GROUP BY `object_count`.`object_id` HAVING COUNT(*) {$sql_match_operator} '{$input}')";
                 break;
             case 'catalog':
                 $where[] = "`song`.`catalog` {$sql_match_operator} '{$input}'";
                 break;
             case 'playlist_name':
                 $join['playlist'] = true;
                 $join['playlist_data'] = true;
                 $where[] = "`playlist`.`name` {$sql_match_operator} '{$input}'";
//.........这里部分代码省略.........
开发者ID:cheese1,项目名称:ampache,代码行数:101,代码来源:search.class.php

示例2: advanced

 /**
  * advanced
  * This processes the results of a post from a form and returns an
  * array of song items that were returned from said randomness
  */
 public static function advanced($type, $data)
 {
     /* Figure out our object limit */
     $limit = intval($data['random']);
     // Generate our matchlist
     /* If they've passed -1 as limit then get everything */
     $limit_sql = "";
     if ($data['random'] == "-1") {
         unset($data['random']);
     } else {
         $limit_sql = "LIMIT " . Dba::escape($limit);
     }
     $search_data = Search::clean_request($data);
     $search_info = false;
     if (count($search_data) > 1) {
         $search = new Search(null, $type);
         $search->parse_rules($search_data);
         $search_info = $search->to_sql();
     }
     $sql = "";
     switch ($type) {
         case 'song':
             $sql = "SELECT `song`.`id`, `size`, `time` " . "FROM `song` ";
             if ($search_info) {
                 $sql .= $search_info['table_sql'];
             }
             if (AmpConfig::get('catalog_disable')) {
                 $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
                 $sql .= " WHERE `catalog`.`enabled` = '1'";
             }
             if ($search_info) {
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= ' AND ' . $search_info['where_sql'];
                 } else {
                     $sql .= ' WHERE ' . $search_info['where_sql'];
                 }
             }
             break;
         case 'album':
             $sql = "SELECT `album`.`id`, SUM(`song`.`size`) AS `size`, SUM(`song`.`time`) AS `time` FROM `album` ";
             if (!$search_info || !$search_info['join']['song']) {
                 $sql .= "LEFT JOIN `song` ON `song`.`album`=`album`.`id` ";
             }
             if ($search_info) {
                 $sql .= $search_info['table_sql'];
             }
             if (AmpConfig::get('catalog_disable')) {
                 $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
                 $sql .= " WHERE `catalog`.`enabled` = '1'";
             }
             if ($search_info) {
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= ' AND ' . $search_info['where_sql'];
                 } else {
                     $sql .= ' WHERE ' . $search_info['where_sql'];
                 }
             }
             $sql .= ' GROUP BY `album`.`id`';
             break;
         case 'artist':
             $sql = "SELECT `artist`.`id`, SUM(`song`.`size`) AS `size`, SUM(`song`.`time`) AS `time` FROM `artist` ";
             if (!$search_info || !$search_info['join']['song']) {
                 $sql .= "LEFT JOIN `song` ON `song`.`artist`=`artist`.`id` ";
             }
             if ($search_info) {
                 $sql .= $search_info['table_sql'];
             }
             if (AmpConfig::get('catalog_disable')) {
                 $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
                 $sql .= " WHERE `catalog`.`enabled` = '1'";
             }
             if ($search_info) {
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= ' AND ' . $search_info['where_sql'];
                 } else {
                     $sql .= ' WHERE ' . $search_info['where_sql'];
                 }
             }
             $sql .= ' GROUP BY `artist`.`id`';
             break;
     }
     $sql .= " ORDER BY RAND() {$limit_sql}";
     // Run the query generated above so we can while it
     $db_results = Dba::read($sql);
     $results = array();
     $size_total = 0;
     $fuzzy_size = 0;
     $time_total = 0;
     $fuzzy_time = 0;
     while ($row = Dba::fetch_assoc($db_results)) {
         // If size limit is specified
         if ($data['size_limit']) {
             // Convert
             $new_size = $row['size'] / 1024 / 1024;
             // Only fuzzy 100 times
//.........这里部分代码省略.........
开发者ID:ivan801,项目名称:ampache,代码行数:101,代码来源:random.class.php

示例3: song_to_sql

 /**
  * song_to_sql
  * Handles the generation of the SQL for song searches.
  */
 private function song_to_sql()
 {
     $sql_logic_operator = $this->logic_operator;
     $where = array();
     $table = array();
     $join = array();
     $join['tag'] = array();
     foreach ($this->rules as $rule) {
         $type = $this->name_to_basetype($rule[0]);
         $operator = array();
         foreach ($this->basetypes[$type] as $op) {
             if ($op['name'] == $rule[1]) {
                 $operator = $op;
                 break;
             }
         }
         $input = $this->_mangle_data($rule[2], $type, $operator);
         $sql_match_operator = $operator['sql'];
         switch ($rule[0]) {
             case 'anywhere':
                 $where[] = "(`artist`.`name` {$sql_match_operator} '{$input}' OR `album`.`name` {$sql_match_operator} '{$input}' OR `song_data`.`comment` {$sql_match_operator} '{$input}' OR `song`.`file` {$sql_match_operator} '{$input}' OR `song`.`title` {$sql_match_operator} '{$input}')";
                 $join['album'] = true;
                 $join['artist'] = true;
                 $join['song_data'] = true;
                 break;
             case 'tag':
                 $key = md5($input . $sql_match_operator);
                 $where[] = "`realtag_{$key}`.`match` > 0";
                 $join['tag'][$key] = "{$sql_match_operator} '{$input}'";
                 break;
             case 'title':
                 $where[] = "`song`.`title` {$sql_match_operator} '{$input}'";
                 break;
             case 'album':
                 $where[] = "`album`.`name` {$sql_match_operator} '{$input}'";
                 $join['album'] = true;
                 break;
             case 'artist':
                 $where[] = "`artist`.`name` {$sql_match_operator} '{$input}'";
                 $join['artist'] = true;
                 break;
             case 'time':
                 $input = $input * 60;
                 $where[] = "`song`.`time` {$sql_match_operator} '{$input}'";
                 break;
             case 'file':
                 $where[] = "`song`.`file` {$sql_match_operator} '{$input}'";
                 break;
             case 'year':
                 $where[] = "`song`.`year` {$sql_match_operator} '{$input}'";
                 break;
             case 'comment':
                 $where[] = "`song_data`.`comment` {$sql_match_operator} '{$input}'";
                 $join['song_data'] = true;
                 break;
             case 'played':
                 $where[] = " `song`.`played` = '{$input}'";
                 break;
             case 'bitrate':
                 $input = $input * 1000;
                 $where[] = "`song`.`bitrate` {$sql_match_operator} '{$input}'";
                 break;
             case 'rating':
                 $where[] = "COALESCE(`rating`.`rating`,0) {$sql_match_operator} '{$input}'";
                 $join['rating'] = true;
                 break;
             case 'played_times':
                 $where[] = "`song`.`id` IN (SELECT `object_count`.`object_id` FROM `object_count` " . "WHERE `object_count`.`object_type` = 'song'" . "GROUP BY `object_count`.`object_id` HAVING COUNT(*) {$sql_match_operator} '{$input}')";
                 break;
             case 'catalog':
                 $where[] = "`song`.`catalog` {$sql_match_operator} '{$input}'";
                 break;
             case 'playlist_name':
                 $join['playlist'] = true;
                 $join['playlist_data'] = true;
                 $where[] = "`playlist`.`name` {$sql_match_operator} '{$input}'";
                 break;
             case 'playlist':
                 $join['playlist_data'] = true;
                 $where[] = "`playlist_data`.`playlist` {$sql_match_operator} '{$input}'";
                 break;
             case 'smartplaylist':
                 $subsearch = new Search('song', $input);
                 $subsql = $subsearch->to_sql();
                 $where[] = "{$sql_match_operator} (" . $subsql['where_sql'] . ")";
                 // HACK: array_merge would potentially lose tags, since it
                 // overwrites. Save our merged tag joins in a temp variable,
                 // even though that's ugly.
                 $tagjoin = array_merge($subsql['join']['tag'], $join['tag']);
                 $join = array_merge($subsql['join'], $join);
                 $join['tag'] = $tagjoin;
                 break;
             case 'added':
                 $input = strtotime($input);
                 $where[] = "`song`.`addition_time` {$sql_match_operator} {$input}";
                 break;
//.........这里部分代码省略.........
开发者ID:axelsimon,项目名称:ampache,代码行数:101,代码来源:search.class.php

示例4: array

set_time_limit(0);
$media_ids = array();
$name = "Unknown.zip";
switch ($_REQUEST['action']) {
    case 'tmp_playlist':
        $media_ids = $GLOBALS['user']->playlist->get_items();
        $name = $GLOBALS['user']->username . ' - Playlist';
        break;
    case 'playlist':
        $playlist = new Playlist($_REQUEST['id']);
        $media_ids = $playlist->get_songs();
        $name = $playlist->name;
        break;
    case 'smartplaylist':
        $search = new Search('song', $_REQUEST['id']);
        $sql = $search->to_sql();
        $sql = $sql['base'] . ' ' . $sql['table_sql'] . ' WHERE ' . $sql['where_sql'];
        $db_results = Dba::read($sql);
        while ($row = Dba::fetch_assoc($db_results)) {
            $media_ids[] = $row['id'];
        }
        $name = $search->name;
        break;
    case 'album':
        foreach ($_REQUEST['id'] as $a) {
            $album = new Album($a);
            if (empty($name)) {
                $name = $album->name;
            }
            $asongs = $album->get_songs();
            foreach ($asongs as $song_id) {
开发者ID:axelsimon,项目名称:ampache,代码行数:31,代码来源:batch.php


注:本文中的Search::to_sql方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。