本文整理汇总了PHP中Search::parse_rules方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::parse_rules方法的具体用法?PHP Search::parse_rules怎么用?PHP Search::parse_rules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Search
的用法示例。
在下文中一共展示了Search::parse_rules方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* run
*
* This function actually runs the search and returns an array of the
* results.
*/
public static function run($data)
{
$limit = intval($data['limit']);
$offset = intval($data['offset']);
$data = Search::clean_request($data);
$search = new Search(null, $data['type']);
$search->parse_rules($data);
// Generate BASE SQL
$limit_sql = "";
if ($limit > 0) {
$limit_sql = ' LIMIT ';
if ($offset) {
$limit_sql .= $offset . ",";
}
$limit_sql .= $limit;
}
$search_info = $search->to_sql();
$sql = $search_info['base'] . ' ' . $search_info['table_sql'];
if (!empty($search_info['where_sql'])) {
$sql .= ' WHERE ' . $search_info['where_sql'];
}
if (!empty($search_info['group_sql'])) {
$sql .= ' GROUP BY ' . $search_info['group_sql'];
if (!empty($search_info['having_sql'])) {
$sql .= ' HAVING ' . $search_info['having_sql'];
}
}
$sql .= ' ' . $limit_sql;
$sql = trim($sql);
$db_results = Dba::read($sql);
$results = array();
while ($row = Dba::fetch_assoc($db_results)) {
$results[] = $row['id'];
}
return $results;
}
示例2: Search
$playlist->save();
break;
case 'delete_playlist':
// If we made it here, we didn't have sufficient rights.
UI::access_denied();
break;
case 'show_playlist':
$playlist = new Search($_REQUEST['playlist_id'], 'song');
$playlist->format();
$object_ids = $playlist->get_items();
require_once AmpConfig::get('prefix') . UI::find_template('show_search.inc.php');
break;
case 'update_playlist':
$playlist = new Search($_REQUEST['playlist_id'], 'song');
if ($playlist->has_access()) {
$playlist->parse_rules(Search::clean_request($_REQUEST));
$playlist->update();
$playlist->format();
} else {
UI::access_denied();
break;
}
$object_ids = $playlist->get_items();
require_once AmpConfig::get('prefix') . UI::find_template('show_search.inc.php');
break;
default:
$object_ids = $playlist->get_items();
require_once AmpConfig::get('prefix') . UI::find_template('show_search.inc.php');
break;
}
// switch on the action
示例3: T_
<td>
<a id="addrowbutton" href="javascript:void(0)">
<?php
echo UI::get_icon('add');
?>
<?php
echo T_('Add Another Rule');
?>
</a>
<script type="text/javascript">$('#addrowbutton').on('click', SearchRow.add);</script>
</td>
</tr>
</tbody>
</table>
<?php
UI::show_box_bottom();
?>
<?php
if ($playlist) {
$out = $playlist->to_js();
} else {
$mysearch = new Search(null, $_REQUEST['type']);
$mysearch->parse_rules(Search::clean_request($_REQUEST));
$out = $mysearch->to_js();
}
if ($out) {
echo $out;
} else {
echo '<script type="text/javascript">SearchRow.add();</script>';
}
示例4: 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
//.........这里部分代码省略.........