Exemple #1
0
	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']);
		}
	}
Exemple #2
0
	function getEventsBooks($ids, $opts = array(), $limit = false) {
		$person_id = isset($opts['person_id']) ? $opts['person_id'] : false;
		$books = Books::getByIdsLoaded($ids);
		Books::LoadBookPersons($ids);
		$out = array();
		/* @var $book Book */
		$i = 0;
		if (is_array($books))
			foreach ($books as $book) {
				if ($limit && ++$i > $limit)
					return $out;
				$out[] = $book->getListData();
			}
		return $out;
	}
Exemple #3
0
	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];
		}
	}
Exemple #4
0
	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;
		}
	}
Exemple #5
0
	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;
	}
Exemple #6
0
 function getLogBooks($ids, $opts = array(), $limit = false) {
     $person_id = isset($opts['person_id']) ? $opts['person_id'] : false;
     $books = Books::getByIdsLoaded($ids);
     Books::LoadBookPersons($ids);
     $out = array();
     /* @var $book Book */
     $i = 0;
     if (is_array($books))
         foreach ($books as $book) {
             if ($limit && ++$i > $limit)
                 return $out;
             list($aid, $aname) = $book->getAuthor(1, 1, 1, $person_id); // именно наш автор, если их там много
             $out[] = array(
                 'id' => $book->id,
                 'cover' => $book->getCover(),
                 'title' => $book->getTitle(true),
                 'author' => $aname,
                 'author_id' => $aid,
                 'lastSave' => $book->data['modify_time'],
             );
         }
     return $out;
 }