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


PHP Books::getById方法代码示例

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


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

示例1: getOne

	function getOne() {
		$query = 'SELECT * FROM `genre` WHERE `name`=' . Database::escape($this->genre_name);
		$data = Database::sql2row($query);
		if (!isset($data['name']))
			return;
		$this->data['genres'][$data['id']] = array(
		    'name' => $data['name'],
		    'id' => $data['id'],
		    'id_parent' => $data['id_parent'],
		    'title' => $data['title'],
		    'books_count' => $data['books_count']
		);

		if (!$data['id_parent']) {
			$this->data['genres'][$data['id']]['subgenres'] = $this->getAll($data['id']);
			return;
		}

		$query = 'SELECT `id_book` FROM `book_genre` BG JOIN `book` B ON B.id = BG.id_book WHERE BG.id_genre = ' . $data['id'] . ' ORDER BY B.mark DESC LIMIT 20';
		$bids = Database::sql2array($query, 'id_book');
		$books = Books::getByIdsLoaded(array_keys($bids));
		Books::LoadBookPersons(array_keys($bids));

		foreach ($books as $book) {
			$book = Books::getById($book->id);
			list($aid, $aname) = $book->getAuthor(1, 1, 1); // именно наш автор, если их там много
			$this->data['genres'][$data['id']]['books'][] = array('id' => $book->id,
			    'cover' => $book->getCover(),
			    'title' => $book->getTitle(true),
			    'author' => $aname,
			    'author_id' => $aid,
			    'lastSave' => $book->data['modify_time']);
		}
	}
开发者ID:rasstroen,项目名称:diary,代码行数:34,代码来源:genres_module.php

示例2: getShelves

	function getShelves() {
		global $current_user;
		/* @var $current_user CurrentUser */
		/* @var $user User */
		$user = ($current_user->id === $this->id) ? $current_user : Users::getById($this->id);
		$bookShelf = $user->getBookShelf();
		foreach ($bookShelf as $shelf => &$books)
			uasort($books, 'sort_by_add_time');
		$bookIds = array();
		foreach ($bookShelf as $shelf => $ids) {
			foreach ($ids as $bookId => $data)
				$bookIds[$bookId] = $bookId;
		}
		// все эти книжки нужно подгрузить
		Books::getByIdsLoaded($bookIds);
		Books::LoadBookPersons($bookIds);
		$shelfcounter = array(1 => 0, 2 => 0, 3 => 0);
		foreach ($bookShelf as $shelf => $ids) {
			foreach ($ids as $bookId => $data) {
				$book = Books::getById($bookId);
				if (isset($shelfcounter[$shelf]))
					$shelfcounter[$shelf]++;
				else
					$shelfcounter[$shelf] = 1;
				if ($shelfcounter[$shelf] > 10)
					continue;
				/* @var $book Book */

				list($author_id, $author_name) = $book->getAuthor();
				$this->data['shelves'][$shelf]['books'][$bookId] = array(
				    'id' => $book->id,
				    'title' => $book->getTitle(true),
				    'cover' => $book->getCover(),
				    'author' => $author_name,
				    'author_id' => $author_id,
				    'add_time' => $data['add_time']
				);
			}
		}
		foreach (Config::$shelves as $id => $title) {
			$this->data['shelves'][$id]['books']['count'] = (int) $shelfcounter[$id];
			$this->data['shelves'][$id]['books']['title'] = $title;
			$this->data['shelves'][$id]['books']['link_title'] = 'Перейти на полку «' . $title . '»';
			$this->data['shelves'][$id]['books']['link_url'] = 'user/' . $this->id . '/books/' . Config::$shelfNameById[$id];
		}
	}
开发者ID:rasstroen,项目名称:diary,代码行数:46,代码来源:books_module.php

示例3: getReviews

	function getReviews() {
		if ($this->target_user) {
			$query = 'SELECT * FROM `reviews` WHERE `id_user`=' . $this->target_user . ' ORDER BY `time` DESC';
			$res = Database::sql2array($query);
			$this->data = $this->_list($res);
			$bids = array();
			foreach ($this->data['reviews'] as $row) {
				$bids[$row['book_id']] = $row['book_id'];
			}
			$books = Books::getByIdsLoaded(array_keys($bids));
			Books::LoadBookPersons(array_keys($bids));

			foreach ($books as $book) {
				$book = Books::getById($book->id);
				list($aid, $aname) = $book->getAuthor(1, 1, 1); // именно наш автор, если их там много
				$this->data['books'][] = array('id' => $book->id,
				    'cover' => $book->getCover(),
				    'title' => $book->getTitle(true),
				    'author' => $aname,
				    'author_id' => $aid,
				    'lastSave' => $book->data['modify_time']);
			}
			$this->data['reviews']['target_id'] = $this->target_id;
			$this->data['reviews']['target_type'] = $this->target_type;
		} else {
			$query = 'SELECT * FROM `reviews` WHERE `id_target`=' . $this->target_id . ' AND `target_type`=' . $this->target_type;
			$res = Database::sql2array($query);
			$this->data = $this->_list($res);
			$this->data['reviews']['target_id'] = $this->target_id;
			$this->data['reviews']['target_type'] = $this->target_type;
		}
	}
开发者ID:rasstroen,项目名称:diary,代码行数:32,代码来源:reviews_module.php

示例4: getOne

	function getOne() {
		if (!$this->series_id)
			return;
		$series = Database::sql2array('SELECT id,title,position,books_count,id_parent,description FROM `series` WHERE `id`=' . $this->series_id . ' OR `id_parent`=' . $this->series_id, 'id');
		$parent_id = $series[$this->series_id]['id_parent'];
		if ($parent_id) {
			$parentInfo = Database::sql2array('SELECT id,title,position,books_count,id_parent FROM `series` WHERE `id`=' . $parent_id, 'id');
		}else
			$parentInfo = array();
		$series_books = Database::sql2array('SELECT * FROM `book_series` WHERE id_series IN (' . implode(',', array_keys($series)) . ')');
		$bid = array();

		$cnt = array();
		$series_books_p = array();
		foreach ($series_books as $sb) {
			$cnt[$sb['id_series']] = isset($cnt[$sb['id_series']]) ? $cnt[$sb['id_series']] + 1 : 1;
	
			$series_books_p[$sb['id_series']][] = $sb;
			$bid[$sb['id_book']] = $sb['id_book'];
		}

		if (count($bid)) {
			Books::getByIdsLoaded($bid);
			Books::LoadBookPersons($bid);
		}

		foreach ($series_books_p as &$sb) {
			foreach ($sb as &$bookrow) {
				$book = Books::getById($bookrow['id_book']);
				list($aid, $aname) = $book->getAuthor(1, 1, 1); // именно наш автор, если их там много
				$bookrow = array('id' => $book->id,
				    'cover' => $book->getCover(),
				    'title' => $book->getTitle(true),
				    'author' => $aname,
				    'author_id' => $aid,
				    'lastSave' => $book->data['modify_time']);
			}
		}

		$this->data['serie']['series'] = array();

		$this->data['serie'] = $series[$this->series_id];
		$this->data['serie']['books'] = isset($series_books_p[$this->series_id]) ? $series_books_p[$this->series_id] : array();
		$this->data['serie']['books']['count'] = isset($cnt[$this->series_id]) ? $cnt[$this->series_id] : 0;

		foreach ($series as $id => $ser) {
			if ($ser['id'] == $this->series_id) {
				unset($this->data['serie']['books_count']);
				continue;
			} else {
				$this->data['serie']['series'][$id] = $ser;
				$this->data['serie']['series'][$id]['books'] = isset($series_books_p[$id]) ? $series_books_p[$id] : array();
				$this->data['serie']['series'][$id]['books']['count'] = $ser['books_count'];
				unset($this->data['serie']['series'][$id]['books_count']);
			}
		}
		$this->data['serie']['parent'] = $parentInfo;
	}
开发者ID:rasstroen,项目名称:diary,代码行数:58,代码来源:series_module.php


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