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


PHP Books::getByIdsLoaded方法代码示例

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


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

	function write() {
		global $current_user;
		//$this->setWriteParameter('register_module', 'result', false);

		$id = isset(Request::$post['id']) ? (int) Request::$post['id'] : false;


		if (!$id) {
			$this->newBook();
			return;
		}


		$books = Books::getByIdsLoaded(array($id));
		$book = is_array($books) ? $books[$id] : false;
		if (!$book)
			return;
		/* @var $book Book */

		$fields = array(
		    'title' => 'title',
		    'subtitle' => 'subtitle',
		    'isbn' => 'ISBN',
		    'year' => 'year',
		    'lang_code' => 'id_lang', //lang_code
		    'annotation' => 'description'
		);

		Request::$post['lang_code'] = Config::$langs[Request::$post['lang_code']];
		$to_update = array();
		if (isset($_FILES['cover']) && $_FILES['cover']['tmp_name']) {
			$folder = Config::need('static_path') . '/upload/covers/' . (ceil($book->id / 5000));
			@mkdir($folder);
			chmod($folder, 755);
			$filename = $folder . '/' . $book->id . '.jpg';
			$upload = new UploadAvatar($_FILES['cover']['tmp_name'], 100, 100, "simple", $filename);
			if ($upload->out)
				$to_update['is_cover'] = 1;
			else {
				throw new Exception('cant copy file to ' . $filename, 100);
			}
		}

		if (isset($_FILES['file']) && isset($_FILES['file']['tmp_name']) && $_FILES['file']['tmp_name']) {
			$filetype = explode('.', $_FILES['file']['name']);
			$filetype = isset($filetype[count($filetype) - 1]) ? $filetype[count($filetype) - 1] : 'fb2';
			$filetype = $filetype == 'fb2' ? 1 : 0;
			if (!$filetype)
				throw new Exception('only fb2 allowed');
			$destinationDir = Config::need('files_path') . DIRECTORY_SEPARATOR . getBookFileDirectory($book->id, $filetype);
			@mkdir($destinationDir, 755);
			// добавляем запись в базу
			$filesize = $_FILES['file']['size'];
			$query = 'INSERT INTO `book_files` SET
				`id_book`=' . $book->id . ',
				`filetype`=' . $filetype . ',
				`id_file_author`=' . $current_user->id . ',
				`modify_time`=' . time() . ',
				`filesize`=' . $filesize;
			//Database::query($query);
			if ($id_file = 78037 || $id_file = Database::lastInsertId()) {
				$destinationFile = getBookFilePath($id_file, $book->id, $filetype, Config::need('files_path'));
				move_uploaded_file($_FILES['file']['tmp_name'], $destinationFile);
			}
			if ($filetype == 1) {
				$parser = new FB2Parser($destinationFile);
				$parser->parseDescription();
				$toc = $parser->getTOCHTML();
				Request::$post['annotation'] = $parser->getProperty('annotation');
				Request::$post['title'] = $parser->getProperty('book-title');
				$to_update['table_of_contents'] = $toc;
			}
		}


		foreach ($fields as $field => $bookfield) {
			if (!isset(Request::$post[$field])) {
				throw new Exception('field missed #' . $field);
			}
			if ($book->data[$bookfield] !== Request::$post[$field]) {
				$to_update[$bookfield] = Request::$post[$field];
			}
		}

		$q = array();
		foreach ($to_update as $field => &$value) {
			if (in_array($field, array('ISBN', 'year'))) {
				$value = is_numeric($value) ? $value : 0;
			}
			$q[] = '`' . $field . '`=' . Database::escape($value) . '';
		}

		if (count($q)) {
			$query = 'UPDATE `book` SET ' . implode(',', $q) . ' WHERE `id`=' . $book->id;
			Database::query($query);
			BookLog::addLog($to_update, $book->data);
			BookLog::saveLog($book->id, BookLog::TargetType_book, $current_user->id, BiberLog::BiberLogType_bookEdit);
		}
		ob_end_clean();
		header('Location:' . Config::need('www_path') . '/b/' . $book->id);
//.........这里部分代码省略.........
开发者ID:rasstroen,项目名称:diary,代码行数:101,代码来源:BookWriteModule.php

示例3: getEventsBooks

	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;
	}
开发者ID:rasstroen,项目名称:diary,代码行数:15,代码来源:events_module.php

示例4: 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

示例5: 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

示例6: 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

示例7: getLogBooks

 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;
 }
开发者ID:rasstroen,项目名称:diary,代码行数:23,代码来源:log_module.php


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