本文整理汇总了PHP中Item::get_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::get_by_id方法的具体用法?PHP Item::get_by_id怎么用?PHP Item::get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Item
的用法示例。
在下文中一共展示了Item::get_by_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: do_search
function do_search($terms)
{
global $mysqli;
$terms = $this->search_split_terms($terms);
$terms_db = $this->search_db_escape_terms($terms);
$terms_rx = $this->search_rx_escape_terms($terms);
$parts = array();
foreach ($terms_db as $term_db) {
$parts[] = "content RLIKE '{$term_db}'";
}
$parts = implode(' AND ', $parts);
$sql = "SELECT id FROM items WHERE {$parts}";
$query = mysqli_query($mysqli, $sql);
$items = array();
while ($query && ($result = mysqli_fetch_assoc($query))) {
$item = Item::get_by_id($result['id']);
$item->content = process_content($item->content);
$item->score = 0;
foreach ($terms_rx as $term_rx) {
$item->score += preg_match_all("/{$term_rx}/i", $item->content, $null);
}
$items[] = $item;
}
if (count($items) > 1) {
uasort($items, array($this, 'search_sort_results'));
}
return $items;
}
示例2: list_all
public static function list_all($limit = 10, $offset = 0)
{
global $mysqli;
$config = new Config();
$sql = "SELECT `id` FROM `{$config->database->{$config->site_identifier}->prefix}items` ORDER BY `id` DESC";
// Limit string
$limit = sanitize_input($limit);
$sql .= " LIMIT {$limit}";
// Offset string
$offset = sanitize_input($offset);
$sql .= " OFFSET {$offset}";
$query = mysqli_query($mysqli, $sql);
// Loop through item ids, fetching objects
$items = array();
if ($query != false) {
while ($query && ($result = mysqli_fetch_assoc($query))) {
$items[] = Item::get_by_id($result['id']);
}
}
return $items;
}
示例3: json
function json($item_id)
{
$item = Item::get_by_id($item_id);
$this->json = $item->likes;
$this->loadView('pages/json', NULL, 'none');
}
示例4: test_change_state_to_waiting_for_done_undone_after_get
public function test_change_state_to_waiting_for_done_undone_after_get()
{
$this->item->create(time() + 1, time() + 1800, "این تست است", ITEM_STATE_DONE, 3)->save($this->user, $this->task);
sleep(2);
$tempItem = new Item();
$tempItem->get_by_id($this->item->getId());
$this->_assert_equals($tempItem->getFeedback(), null);
$this->_assert_equals($tempItem->getState(), ITEM_STATE_WAITING_FOR_DONE_UNDONE);
}
示例5: list_feed
public function list_feed($limit = 10, $offset = 0)
{
global $mysqli;
$config = new Config();
// Start by adding the viewer to the query string
$friends_string = "`user_id` = {$this->id}";
$friends = $this->friends();
// Loop through friends adding them to the query string
foreach ($friends as $friend) {
$friends_string .= " OR `user_id` = {$friend['friend_user_id']}";
}
$sql = "SELECT `id` FROM `{$config->database->{$config->site_identifier}->prefix}items` WHERE {$friends_string} ORDER BY `id` DESC";
// Limit string
$limit = sanitize_input($limit);
$sql .= " LIMIT {$limit}";
// Offset string
$offset = sanitize_input($offset);
$sql .= " OFFSET {$offset}";
$query = mysqli_query($mysqli, $sql);
// Loop through item ids, fetching objects
$items = array();
while ($query && ($result = mysqli_fetch_assoc($query))) {
$items[] = Item::get_by_id($result['id']);
}
return $items;
}
示例6: remove
function remove($item_id)
{
$item = Item::get_by_id($item_id);
if ($_SESSION['user_id'] == $item->user->id && $item != NULL) {
// Delete item
$item->remove();
// Log item deletion
if (isset($this->plugins->log)) {
$this->plugins->log->add($_SESSION['user_id'], 'item', $item->id, 'remove');
}
// Delete comments
if (is_array($item->comments)) {
foreach ($item->comments as $comment) {
// Remove comment
$id = $comment->remove();
// Log comment removal
if (isset($this->plugins->log)) {
$this->plugins->log->add($_SESSION['user_id'], 'comment', $id, 'remove');
}
}
}
// Delete likes
if (is_array($item->comments)) {
foreach ($item->likes as $like) {
// Remove like
$id = $like->remove();
// Log like removal
if (isset($this->plugins->log)) {
$this->plugins->log->add($_SESSION['user_id'], 'like', $like->id, 'remove');
}
}
}
// Set message
Application::flash('success', ucfirst($this->config->items->name) . ' removed!');
// Return from whence you came
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit;
} else {
// Naughtiness = expulsion!
// Go forth
header('Location: ' . $this->config->url);
exit;
}
}