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


PHP Books::getInstance方法代码示例

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


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

示例1: setStatus

    public static function setStatus($id_user, $id_book, $status, $state)
    {
        global $current_user;
        $book = Books::getInstance()->getByIdLoaded($id_book);
        /* @var $book Book */
        if ($book->getQuality() >= BOOK::BOOK_QUALITY_BEST) {
            throw new Exception('book quality is best, you cant fix states');
        }
        if (!isset(self::$statuses[$status])) {
            throw new Exception('no status #' . $status);
        }
        if (!isset(self::$states[$state])) {
            throw new Exception('no status #' . $state);
        }
        $can_comment = false;
        if ($state > 0) {
            $query = 'SELECT `time` FROM `ocr` WHERE  `id_book`=' . $id_book . ' AND `id_user`=' . $id_user . ' AND `status`=' . $status . ' AND `state`=' . $state;
            $last_time = Database::sql2single($query);
            if (time() - $last_time > 24 * 60 * 60) {
                $can_comment = true;
            }
        }
        if ($state == 0 && $status !== 0) {
            // delete
            $query = 'DELETE FROM `ocr` WHERE  `id_book`=' . $id_book . ' AND `id_user`=' . $id_user . ' AND `status`=' . $status . '';
        } else {
            // upsert
            $query = 'INSERT INTO `ocr` SET `id_book`=' . $id_book . ', `id_user`=' . $id_user . ', `status`=' . $status . ',`state`=' . $state . ',`time`=' . time() . '
			ON DUPLICATE KEY UPDATE
			`time`=' . time() . ', `state`=' . $state;
        }
        if (!Database::query($query, false)) {
            throw new Exception('Duplicating #book ' . $id_book . ' #status' . $status . ' #state' . $state);
        }
        if ($state == 0) {
            $comment = 'User ' . $current_user->id . ' drop status ' . $status . ' state ' . $state . ' user_id ' . $id_user;
        } else {
            $comment = 'User ' . $current_user->id . ' set status ' . $status . ' state ' . $state . ' user_id ' . $id_user;
        }
        $comUser = Users::getById($id_user);
        /* @var $comUser User */
        if ($can_comment && ($part = self::getMessagePart($status, $state))) {
            $comment = mb_strtolower($part, 'UTF-8') . ' книгу';
            MongoDatabase::addSimpleComment(BiberLog::TargetType_book, $id_book, $id_user, $comment);
        }
    }
开发者ID:rasstroen,项目名称:metro,代码行数:46,代码来源:Ocr.php

示例2: notifyGenreNewBook

 public static function notifyGenreNewBook($id_genre, $id_book)
 {
     global $current_user;
     $query = 'SELECT `id_user` FROM `genre_subscribers` WHERE `id_genre`=' . (int) $id_genre;
     $user_ids = array_keys(Database::sql2array($query, 'id_user'));
     if (isset($user_ids[$current_user->id])) {
         unset($user_ids[$current_user->id]);
     }
     if (count($user_ids)) {
         $genre = Database::sql2single('SELECT `title` FROM `genre` WHERE `id`=' . $id_genre);
         $book = Books::getInstance()->getByIdLoaded($id_book);
         /* @var $person Person */
         $subject = 'Добавлена книга в жанре ' . $genre;
         /* @var $book Book */
         $message = 'Книга <a href="/b/' . $book->id . '">' . $book->getTitle(1) . '</a> добавлена';
         self::send($user_ids, $subject, $message, UserNotify::UN_G_NEW_GENRES);
     }
 }
开发者ID:rasstroen,项目名称:metro,代码行数:18,代码来源:Notify.php

示例3: _after_idsToData

 public function _after_idsToData($data)
 {
     $aids = array();
     foreach ($data['books'] as $bookid => $d) {
         $book = Books::getInstance()->getByIdLoaded($bookid);
         $aid = $book->getAuthorId();
         if ($aid) {
             $aids[$aid] = $aid;
         }
     }
     if (count($aids)) {
         $persons = Persons::getInstance()->getByIdsLoaded($aids);
         foreach ($persons as $person) {
             $data['authors'][] = $person->getListData();
         }
     } else {
         $data['authors'] = array();
     }
     return $data;
 }
开发者ID:rasstroen,项目名称:metro,代码行数:20,代码来源:Books.php

示例4: addLoved

    function addLoved()
    {
        global $current_user;
        $event = new Event();
        /* @var $current_user CurrentUser */
        if (!$current_user->authorized) {
            $this->error('Auth');
            return;
        }
        $item_type = isset($_POST['item_type']) ? $_POST['item_type'] : false;
        $item_id = isset($_POST['item_id']) ? (int) $_POST['item_id'] : false;
        if (!$item_type || !$item_id) {
            $this->error('item_id or item_type missed');
            return;
        }
        if (!isset(Config::$loved_types[$item_type])) {
            $this->error('illegal item_type#' . $item_type);
            return;
        }
        $query = 'INSERT INTO `users_loved` SET `id_target`=' . $item_id . ',`target_type`=' . Config::$loved_types[$item_type] . ',`id_user`=' . $current_user->id;
        if (Database::query($query, false)) {
            $this->data['success'] = 1;
            $this->data['item_id'] = $item_id;
            $this->data['in_loved'] = 1;
            $event->event_LovedAdd($current_user->id, $item_id, $item_type);
            $event->push();
            if ($item_type == 'book') {
                $time = time();
                // inserting a new mark
                $query = 'INSERT INTO `book_rate` SET `id_book`=' . $item_id . ',`id_user`=' . $current_user->id . ',`rate`=5,`time`=' . $time . ' ON DUPLICATE KEY UPDATE
				`rate`=5 ,`time`=' . $time . ',`with_review`=0';
                Database::query($query);
                //recalculating rate
                $query = 'SELECT COUNT(1) as cnt, SUM(`rate`) as rate FROM `book_rate` WHERE `id_book`=' . $item_id;
                $res = Database::sql2row($query);
                $book_mark = round($res['rate'] / $res['cnt'] * 10);
                $book = Books::getInstance()->getById($item_id);
                /* @var $book Book */
                $book->updateLovedCount();
                $query = 'UPDATE `book` SET `mark`=' . $book_mark . ' WHERE `id`=' . $item_id;
                Database::query($query);
            }
            return;
        } else {
            $query = 'DELETE FROM `users_loved` WHERE `id_target`=' . $item_id . ' AND `target_type`=' . Config::$loved_types[$item_type] . ' AND `id_user`=' . $current_user->id;
            if (Database::query($query, false)) {
                $this->data['success'] = 1;
                $this->data['item_id'] = $item_id;
                $this->data['in_loved'] = 0;
                if ($item_type == 'book') {
                    $book = Books::getInstance()->getById($item_id);
                    /* @var $book Book */
                    $book->updateLovedCount();
                }
                return;
            } else {
                $this->data['success'] = 0;
            }
        }
    }
开发者ID:rasstroen,项目名称:sosedi,代码行数:60,代码来源:Jusers_module.php

示例5: getBookContributionComments

 function getBookContributionComments()
 {
     global $current_user;
     /* @var $current_user CurrentUser */
     $id_book = isset($this->params['book_id']) ? (int) $this->params['book_id'] : false;
     if (!$id_book) {
         return;
     }
     $book = Books::getInstance()->getByIdLoaded($id_book);
     /* @var $book Book */
     if (!$book->exists) {
         throw new Exception('book #' . $book->id . ' not exists');
     }
     $cond = new Conditions();
     $per_page = 0;
     if (isset($this->params['per_page'])) {
         $per_page = (int) $this->params['per_page'];
     }
     $per_page = $per_page > 0 ? $per_page : 20;
     $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p';
     $cond->setPaging(1000, $per_page, $pagingName);
     $limit = $cond->getMongoLimit();
     list($comments, $count) = MongoDatabase::getBookComments($id_book, $per_page, $limit);
     $uids = array();
     $comments['comments'] = isset($comments['comments']) ? $comments['comments'] : array();
     foreach ($comments['comments'] as &$comment) {
         $comment['commenter_id'] = $comment['user_id'];
         $comment['type'] = 'book';
         $comment['time'] = date('Y/m/d H:i:s', $comment['time']);
         $uids[$comment['user_id']] = $comment['user_id'];
     }
     $cond = new Conditions();
     $cond->setPaging($count, $per_page, $pagingName);
     $this->data['conditions'] = $cond->getConditions();
     $this->data['comments'] = isset($comments['comments']) ? $comments['comments'] : array();
     $this->data['comments']['title'] = 'Обсуждение книги «' . $book->getTitle(true) . '»';
     $this->data['comments']['count'] = $count;
     $this->data['users'] = $this->getCommentsUsers($uids);
 }
开发者ID:rasstroen,项目名称:metro,代码行数:39,代码来源:comments_module.php

示例6: getStatBooks

 function getStatBooks($ids, $opts = array(), $limit = false)
 {
     $person_id = isset($opts['person_id']) ? $opts['person_id'] : false;
     $books = Books::getInstance()->getInstance()->getByIdsLoaded($ids);
     Books::getInstance()->getInstance()->LoadBookPersons($ids);
     $out = array();
     $aids = array();
     /* @var $book Book */
     $i = 0;
     if (is_array($books)) {
         foreach ($books as &$book) {
             if ($limit && ++$i > $limit) {
                 return $out;
             }
             $tmp = $book->getListData();
             list($author_id, $name) = $book->getAuthor();
             if ($author_id) {
                 $aids[$author_id] = $author_id;
             }
             $tmp['path'] = Config::need('www_path') . '/admin/books/' . $book->id;
             $out[] = $tmp;
         }
     }
     return array($out, $aids);
 }
开发者ID:rasstroen,项目名称:metro,代码行数:25,代码来源:statistics_module.php

示例7: getOne

 function getOne($for_editing = false)
 {
     if ($this->genre_id) {
         $query = 'SELECT * FROM `genre` WHERE `id`=' . Database::escape($this->genre_id);
     } else {
         $query = 'SELECT * FROM `genre` WHERE `name`=' . Database::escape($this->genre_name);
     }
     $data = Database::sql2row($query);
     if (!isset($data['name'])) {
         return;
     }
     $this->data['genre'] = array('name' => $data['name'], 'id' => $data['id'], 'id_parent' => $data['id_parent'], 'title' => $data['title'], 'description' => $data['description'], 'books_count' => $data['books_count'], 'path' => Config::need('www_path') . '/genres/' . $data['id'], 'path_edit' => Config::need('www_path') . '/genres/' . $data['id'] . '/edit');
     Request::pass('genre-title', $data['title']);
     if (!$data['id_parent']) {
         $this->data['genre']['subgenres'] = $this->getAll($data['id']);
         return;
     }
     if (!$for_editing) {
         $query = 'SELECT COUNT(1) FROM `book_genre` BG JOIN `book` B ON B.id = BG.id_book WHERE BG.id_genre = ' . $data['id'] . '';
         $count = Database::sql2single($query);
         $cond = new Conditions();
         $cond->setPaging($count, 20);
         $limit = $cond->getLimit();
         $this->data['conditions'] = $cond->getConditions();
         $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 ' . $limit;
         $bids = Database::sql2array($query, 'id_book');
         $books = Books::getInstance()->getByIdsLoaded(array_keys($bids));
         Books::getInstance()->LoadBookPersons(array_keys($bids));
         $aids = array();
         foreach ($books as $book) {
             $book = Books::getInstance()->getById($book->id);
             list($aid, $aname) = $book->getAuthor(1, 1, 1);
             // именно наш автор, если их там много
             $this->data['genre']['books'][$book->id] = $book->getListData();
             $aids[$aid] = $aid;
         }
         if (count($aids)) {
             $persons = Persons::getInstance()->getByIdsLoaded($aids);
             foreach ($persons as $person) {
                 $this->data['genre']['authors'][] = $person->getListData();
             }
         }
         $this->data['parent'] = array();
         if ($data['id_parent']) {
             $data = Database::sql2row('SELECT * FROM `genre` WHERE `id`=' . Database::escape($data['id_parent']));
             $this->data['genre']['parent'][] = array('name' => $data['name'], 'id' => $data['id'], 'id_parent' => $data['id_parent'], 'title' => $data['title'], 'description' => $data['description'], 'books_count' => $data['books_count'], 'path' => Config::need('www_path') . '/genres/' . $data['id'], 'path_edit' => Config::need('www_path') . '/genres/' . $data['id'] . '/edit');
         }
     }
 }
开发者ID:rasstroen,项目名称:metro,代码行数:49,代码来源:genres_module.php

示例8: getContributionBooks

 function getContributionBooks($ids)
 {
     $person_id = isset($opts['person_id']) ? $opts['person_id'] : false;
     $books = Books::getInstance()->getInstance()->getByIdsLoaded($ids);
     Books::getInstance()->getInstance()->LoadBookPersons($ids);
     $out = array();
     $aids = array();
     /* @var $book Book */
     if (is_array($books)) {
         foreach ($books as $book) {
             $out[] = $book->getListData();
             list($author_id, $name) = $book->getAuthor();
             if ($author_id) {
                 $aids[$author_id] = $author_id;
             }
         }
     }
     return array($out, $aids);
 }
开发者ID:rasstroen,项目名称:metro,代码行数:19,代码来源:contributions_module.php

示例9: generateData

 function generateData()
 {
     global $current_user;
     /* @var $current_user CurrentUser */
     if (!$current_user->authorized) {
         throw new Exception('Auth required');
     }
     $current_user->can_throw('books_download');
     $filetype = Request::get(0);
     list($id_file, $id_book) = explode('_', Request::get(1));
     $can_load = $current_user->canBookDownload($id_book, $id_file);
     if ($can_load !== true) {
         if ($can_load[1]) {
             throw new Exception('You cant download this book - limit of a ' . $can_load[1] . ' books in day exceed');
         } else {
             throw new Exception('Please prolong your subscription, сучечка!');
         }
     }
     $book = Books::getInstance()->getByIdLoaded($id_book);
     /* @var $book Book */
     if (!$book->loaded) {
         throw new Exception('Book doesn\'t exists');
     }
     if (!$filetype || !$id_file || !$id_book) {
         throw new Exception('Wrong download url');
     }
     $realPath = getBookFilePath($id_file, $id_book, $filetype, Config::need('files_path'));
     global $dev_mode;
     if (!is_readable($realPath)) {
         if ($dev_mode) {
             throw new Exception('Sorry, file ' . $realPath . ' doesn\'t exists');
         } else {
             throw new Exception('Sorry, file  doesn\'t exists');
         }
     }
     $current_user->onBookDownload($book->id);
     $current_user->save();
     if (Request::get('html') !== false) {
         // downloading generated html
         $book->getHTMLDownload();
         $realPath = getBookFilePathFB2HtmlDownload($id_file, $id_book, $filetype, Config::need('files_path'));
         $filetype = 4;
     }
     @ob_end_clean();
     $ft = Config::need('filetypes');
     $book->setReaded();
     if (Config::need('smart_download')) {
         header("Content-Type: application/force-download");
         header("Content-Type: application/octet-stream");
         header("Content-Type: application/download");
         header("Content-Description: File Transfer");
         header('Content-Disposition: attachment; filename="' . $book->getTitle(1) . '.' . $ft[$filetype]);
         header("X-Accel-Redirect: " . str_replace('/w/ru.jnpe.ls2/core', '', $realPath));
         exit;
     }
     //
     header('Content-Disposition: attachment; filename="' . $book->getTitle(1) . '.' . $ft[$filetype]);
     header("Content-Type: application/force-download");
     header("Content-Type: application/octet-stream");
     header("Content-Type: application/download");
     header("Content-Description: File Transfer");
     readfile($realPath);
     exit;
 }
开发者ID:rasstroen,项目名称:metro,代码行数:64,代码来源:download_module.php

示例10: updateBooksFull

 public function updateBooksFull($bids)
 {
     $documents = array();
     Books::$books_instance = false;
     // cached books?
     Persons::$persons_instance = false;
     // cached persons?
     $books = Books::getInstance()->getByIdsLoaded($bids);
     $time = time();
     foreach ($books as $book) {
         /* @var $book Book */
         $d = $this->prepareBookFull($book);
         if ($d) {
             $documents[] = $d;
         }
     }
     $books = self::$books;
     /* @var $books Apache_Solr_Service */
     // удаляем из индекса
     $books->deleteByMultipleIds($bids);
     // добавляем в индекс
     $books->addDocuments($documents);
     // коммитим изменения
     $books->commit();
     // оптимизируем поисковую базу
     $books->optimize();
 }
开发者ID:rasstroen,项目名称:metro,代码行数:27,代码来源:Search.php

示例11: getEventsBooks

 function getEventsBooks($ids, $opts = array(), $limit = false)
 {
     $person_id = isset($opts['person_id']) ? $opts['person_id'] : false;
     $books = Books::getInstance()->getByIdsLoaded($ids);
     Books::getInstance()->LoadBookPersons($ids);
     $out = array();
     $aids = array();
     /* @var $book Book */
     $i = 0;
     if (is_array($books)) {
         foreach ($books as $book) {
             if ($limit && ++$i > $limit) {
                 return $out;
             }
             $out[] = $book->getListData();
             list($author_id, $name) = $book->getAuthor();
             if ($author_id) {
                 $aids[$author_id] = $author_id;
             }
         }
     }
     return array($out, $aids);
 }
开发者ID:rasstroen,项目名称:metro,代码行数:23,代码来源:events_module.php

示例12: _glue

 function _glue()
 {
     global $current_user;
     $current_user->can_throw('books_edit');
     $id1 = isset(Request::$post['serie1_id']) ? (int) Request::$post['serie1_id'] : false;
     $id2 = isset(Request::$post['serie2_id']) ? (int) Request::$post['serie2_id'] : false;
     $is_1_main = isset(Request::$post['is_main']) ? true : false;
     if ($is_1_main) {
         $main_sid = $id1;
         $slave_sid = $id2;
     } else {
         $main_sid = $id2;
         $slave_sid = $id1;
     }
     if (!$main_sid || !$slave_sid) {
         throw new Exception('illegal ids');
     }
     $query = 'SELECT * FROM `series` WHERE `id` IN (' . $id1 . ',' . $id2 . ')';
     $series = Database::sql2array($query, 'id');
     if (count($series) != 2) {
         throw new Exception('illegal series');
     }
     if ($series[$main_sid]['is_s_duplicate']) {
         throw new Exception($main_sid . ' is duplicate of ' . $series[$main_sid]['is_s_duplicate']);
     }
     Database::query('START TRANSACTION');
     // set new parent_id for all subseries for slave
     $query = 'SELECT `id` FROM `series` WHERE `id_parent`=' . $slave_sid;
     $changed_parents = Database::sql2array($query, 'id');
     if (count($changed_parents)) {
         $query = 'UPDATE `series` SET `id_parent`=' . $main_sid . ' WHERE `id` IN (' . array_keys($changed_parents) . ')';
         Database::query($query);
     }
     // set new serie_id for all books for slave
     $query = 'SELECT `id_book` FROM `book_series` WHERE `id_series`=' . $slave_sid;
     $books = Database::sql2array($query, 'id_book');
     $query = 'UPDATE `book_series` SET `id_series`=' . $main_sid . ' WHERE `id_series`=' . $slave_sid;
     Database::query($query);
     // slave serie got is_s_duplicate flag
     $query = 'UPDATE `series` SET `is_s_duplicate`=' . $main_sid . ' WHERE `id`=' . $slave_sid;
     Database::query($query);
     // for main and slave serie - set new books count
     /* @todo */
     // writing logs
     // for each book - set new serie
     SerieLog::addGlueLog($main_sid, $slave_sid, array_keys($books), array_keys($changed_parents));
     $id_log = SerieLog::saveLog($slave_sid, BookLog::TargetType_serie, $current_user->id, BiberLog::BiberLogType_serieGlue, $copy = false);
     SerieLog::saveLogLink($id_log, $main_sid, BookLog::TargetType_serie, $current_user->id, BiberLog::BiberLogType_serieGlue, $copy = 1);
     // for subseries
     if ($books) {
         Books::getInstance()->getByIdsLoaded(array_keys($books));
         foreach ($books as $bid => $data) {
             SerieLog::saveLogLink($id_log, $bid, BookLog::TargetType_book, $current_user->id, BiberLog::BiberLogType_serieGlue, $copy = 1);
         }
     }
     // for slave serie subseries - set new parent_id
     if ($changed_parents) {
         foreach ($changed_parents as $sid => $data) {
             SerieLog::saveLogLink($id_log, $sid, BookLog::TargetType_serie, $current_user->id, BiberLog::BiberLogType_serieGlue, $copy = 1);
         }
     }
     $current_user->gainActionPoints(BiberLog::$actionTypes[BiberLog::BiberLogType_serieGlue], $main_sid, BiberLog::TargetType_serie);
     Database::query('COMMIT');
     ob_end_clean();
     $search = Search::getInstance();
     /* @var $search Search */
     $search->setSerieToFullUpdate($slave_sid);
     $search->setSerieToFullUpdate($main_sid);
     header('Location:' . Config::need('www_path') . '/s/' . $main_sid);
     exit;
 }
开发者ID:rasstroen,项目名称:metro,代码行数:71,代码来源:SeriesWriteModule.php

示例13: undo_repeat_bookNew

 private static function undo_repeat_bookNew($logdata)
 {
     $data = unserialize($logdata['data']);
     $query = 'UPDATE `book` SET `is_deleted`=0 WHERE `id`=' . $data['id_book'];
     Database::query($query);
     self::undo_repeat_bookEdit($logdata);
     Books::getInstance()->dropCache($data['id_book']);
 }
开发者ID:rasstroen,项目名称:metro,代码行数:8,代码来源:BiberLog.php

示例14: write

    function write()
    {
        global $current_user;
        $points_gained = false;
        /* @var $current_user CurrentUser */
        Database::query('START TRANSACTION');
        $current_user->can_throw('books_edit');
        if (!isset(Request::$post['lang_code']) || !Request::$post['lang_code']) {
            throw new Exception('field missed #lang_code');
        }
        $id = isset(Request::$post['id']) ? (int) Request::$post['id'] : false;
        if (Request::post('isbn')) {
            Request::$post['isbn'] = extractISBN(Request::$post['isbn']);
        }
        if (!$id) {
            $this->newBook();
            return;
        }
        $books = Books::getInstance()->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', 'annotation' => 'description', 'rightholder' => 'id_rightholder');
        Request::$post['lang_code'] = Config::$langs[Request::$post['lang_code']];
        Request::$post['annotation'] = trim(prepare_review(Request::$post['annotation'], false, '<img>'));
        Request::$post['title'] = trim(prepare_review(Request::$post['title'], ''));
        Request::$post['year'] = (int) Request::$post['year'];
        $magazineData = array();
        if ($book->data['book_type'] == Book::BOOK_TYPE_MAGAZINE) {
            $magazineData = Database::sql2row('SELECT * FROM `magazines` M LEFT JOIN book_magazines BM ON BM.id_magazine=M.id WHERE BM.id_book=' . $book->id);
            $book->data['n'] = max(0, $magazineData['n']);
            $book->data['year'] = $magazineData['year'];
            Request::$post['n'] = isset(Request::$post['n']) && Request::$post['n'] ? Request::$post['n'] : $magazineData['n'];
        }
        $to_update_m = array();
        $to_update = array();
        if (isset(Request::$post['quality'])) {
            if ($book->data['quality'] != (int) Request::$post['quality']) {
                $to_update['quality'] = (int) Request::$post['quality'];
            }
        }
        if (isset(Request::$post['n'])) {
            if (isset($book->data['n']) && $book->data['n'] != (int) Request::$post['n']) {
                $to_update_m['n'] = (int) Request::$post['n'];
                Request::$post['title'] = $magazineData['title'];
                Request::$post['subtitle'] = '№ ' . $to_update_m['n'] . ' за ' . Request::$post['year'] . ' год';
            }
            if (isset($book->data['year']) && $book->data['year'] != (int) Request::$post['year']) {
                $to_update_m['n'] = (int) Request::$post['n'];
                Request::$post['title'] = $magazineData['title'];
                Request::$post['subtitle'] = '№ ' . $to_update_m['n'] . ' за ' . Request::$post['year'] . ' год';
            }
        }
        if (isset($_FILES['cover']) && $_FILES['cover']['tmp_name']) {
            $folder = Config::need('static_path') . '/upload/covers/' . ceil($book->id / 5000);
            @mkdir($folder);
            // inserting new cover
            $query = 'INSERT INTO `book_covers` SET `id_book`=' . $book->id;
            Database::query($query);
            $cover_id = Database::lastInsertId();
            // generating file names
            $filename_normal = $folder . '/default_' . $book->id . '_' . $cover_id . '.jpg';
            $filename_small = $folder . '/small_' . $book->id . '_' . $cover_id . '.jpg';
            $filename_big = $folder . '/big_' . $book->id . '_' . $cover_id . '.jpg';
            $filename_orig = $folder . '/orig_' . $book->id . '_' . $cover_id . '.jpg';
            $to_update['is_cover'] = $cover_id;
            $thumb = new Thumb();
            $thumb->createThumbnails($_FILES['cover']['tmp_name'], array($filename_small, $filename_normal, $filename_big, $filename_orig), self::$cover_sizes);
            if ($book->data['is_cover']) {
                $current_user->gainActionPoints('books_edit_cover', $book->id, BiberLog::TargetType_book);
            } else {
                $current_user->gainActionPoints('books_add_cover', $book->id, BiberLog::TargetType_book);
            }
            $points_gained = true;
        }
        // file loading
        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] : '';
            $fts = Config::need('filetypes');
            $filetype = false;
            foreach ($fts as $ftid => $ftname) {
                if ($ftname == $filetype_) {
                    $filetype = $ftid;
                }
            }
            if (!$filetype) {
                throw new Exception('wrong filetype:' . $filetype_);
            }
            $destinationDir = Config::need('files_path') . DIRECTORY_SEPARATOR . getBookFileDirectory($book->id, $filetype);
            @mkdir($destinationDir, 0755);
            // добавляем запись в базу
            $filesize = $_FILES['file']['size'];
            $query = 'SELECT * FROM `book_files` WHERE `id_book`=' . $book->id;
            $files = Database::sql2array($query, 'filetype');
            // replacing file
            if (isset($files[$filetype])) {
                $old_id_file = $files[$filetype]['id'];
//.........这里部分代码省略.........
开发者ID:rasstroen,项目名称:metro,代码行数:101,代码来源:BookWriteModule.php

示例15: getLogBooks

 function getLogBooks($ids, $opts = array(), $limit = false)
 {
     $person_id = isset($opts['person_id']) ? $opts['person_id'] : false;
     $books = Books::getInstance()->getByIdsLoaded($ids);
     Books::getInstance()->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,项目名称:metro,代码行数:18,代码来源:log_module.php


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