本文整理汇总了PHP中Attachments::findBySQL方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachments::findBySQL方法的具体用法?PHP Attachments::findBySQL怎么用?PHP Attachments::findBySQL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attachments
的用法示例。
在下文中一共展示了Attachments::findBySQL方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: paginateByProject
/**
* Paginate attachments by project
*
* @param Project $project
* @param User $user
* @param integer $page
* @param integer $per_page
* @param integer $min_state
* @return array
*/
function paginateByProject($project, $user, $page = 1, $per_page = 30, $min_state = STATE_VISIBLE)
{
$attachments_table = TABLE_PREFIX . 'attachments';
$project_objects_table = TABLE_PREFIX . 'project_objects';
$type_filter = ProjectUsers::getVisibleTypesFilterByProject($user, $project);
if ($type_filter) {
$total = array_var(db_execute_one("SELECT COUNT({$attachments_table}.id) AS 'row_count' FROM {$attachments_table}, {$project_objects_table} WHERE {$attachments_table}.attachment_type = ? AND {$attachments_table}.parent_id = {$project_objects_table}.id AND {$type_filter} AND {$project_objects_table}.state >= ? AND {$project_objects_table}.visibility >= ?", ATTACHMENT_TYPE_ATTACHMENT, $min_state, $user->getVisibility()), 'row_count');
if ($total) {
$offset = ($page - 1) * $per_page;
$attachments = Attachments::findBySQL("SELECT {$attachments_table}.* FROM {$attachments_table}, {$project_objects_table} WHERE {$attachments_table}.attachment_type = ? AND {$attachments_table}.parent_id = {$project_objects_table}.id AND {$type_filter} AND {$project_objects_table}.state >= ? AND {$project_objects_table}.visibility >= ? ORDER BY `created_on` DESC LIMIT {$offset}, {$per_page}", array(ATTACHMENT_TYPE_ATTACHMENT, $min_state, $user->getVisibility()));
if ($attachments) {
return array($attachments, new Pager($page, $total, $per_page));
}
// if
}
// if
}
// if
return array(null, new Pager(1, 0, $per_page));
}
示例2: search_attachments
function search_attachments($search_for, $user, $page, $per_page, $search_object_type, $search_under_project_id, $datesort)
{
$page = (int) $page;
$per_page = (int) $per_page;
$offset = ($page - 1) * $per_page;
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
mysql_select_db(DB_NAME);
$sql = "select ::PLACE_HOLDER:: from healingcrystals_attachments a inner join healingcrystals_project_objects b on (a.parent_id=b.id" . (!empty($search_under_project_id) ? " and b.project_id='" . $search_under_project_id . "'" : "") . ") where a.name like '%" . $search_for . "%' ";
$count_sql = str_replace('::PLACE_HOLDER::', "count(*) as row_count", $sql);
$result = mysql_query($count_sql, $link);
$info = mysql_fetch_assoc($result);
$total_items = $info['row_count'];
if ($total_items) {
if (empty($datesort)) {
$sql = str_replace('::PLACE_HOLDER::', 'a.id', $sql) . " order by a.name LIMIT " . $offset . " ," . $per_page;
} elseif ($datesort == 'a') {
$sql = str_replace('::PLACE_HOLDER::', 'a.id', $sql) . " order by a.created_on, a.name LIMIT " . $offset . " ," . $per_page;
} elseif ($datesort == 'd') {
$sql = str_replace('::PLACE_HOLDER::', 'a.id', $sql) . " order by a.created_on desc, a.name LIMIT " . $offset . " ," . $per_page;
}
$items = Attachments::findBySQL($sql);
} else {
$items = null;
}
mysql_close($link);
return array($items, new Pager($page, $total_items, $per_page), $total_items);
}