示例#1
0
文件: Books.php 项目: rasstroen/metro
 public function LoadBookPersons($ids)
 {
     $this->getByIdsLoaded($ids);
     $out = array();
     $tofetch = array();
     $aids = array();
     if (is_array($ids)) {
         foreach ($ids as $id) {
             if (!isset($this->items[$id])) {
                 continue;
             }
             if (!$this->items[$id]->personsLoaded) {
                 $tofetch[] = (int) $id;
             }
         }
         $bookPersons = array();
         if (count($tofetch)) {
             $query = 'SELECT * FROM `book_persons` WHERE `id_book` IN (' . implode(',', $tofetch) . ')';
             $bookPersons = Database::sql2array($query);
         }
         $bookPersonsPrepared = array();
         foreach ($bookPersons as $book) {
             $bookPersonsPrepared[$book['id_book']][] = $book;
             $aids[$book['id_person']] = $book['id_person'];
         }
         Persons::getInstance()->getByIdsLoaded($aids);
         foreach ($ids as $id) {
             if (isset($this->items[$id])) {
                 if (isset($bookPersonsPrepared[$id])) {
                     $this->items[$id]->loadPersons(isset($bookPersonsPrepared[$id]) ? $bookPersonsPrepared[$id] : array());
                 } else {
                     // no any persons
                     $this->items[$id]->personsLoaded = true;
                     //$this->items[$id]->persons = array();
                 }
             }
         }
         foreach ($ids as $id) {
             if (isset($this->items[$id])) {
                 $out[$id] = $this->items[$id];
             }
         }
     }
     return $out;
 }
示例#2
0
 public static function notifyAuthorNewBook($id_author, $id_book)
 {
     global $current_user;
     $query = 'SELECT `id_user` FROM `author_subscribers` WHERE `id_author`=' . (int) $id_author;
     $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)) {
         $person = Persons::getInstance()->getByIdLoaded($id_author);
         $book = Books::getInstance()->getByIdLoaded($id_book);
         /* @var $person Person */
         $subject = 'Добавлена книга автора ' . $person->getName();
         /* @var $book Book */
         $message = 'Книга <a href="/b/' . $book->id . '">' . $book->getTitle(1) . '</a> добавлена';
         self::send($user_ids, $subject, $message, UserNotify::UN_G_NEW_AUTHORS);
     }
 }
示例#3
0
 function _show()
 {
     $out = array();
     $this->load();
     if ($redirect_to = $this->getDuplicateId()) {
         $person2 = Persons::getInstance()->getByIdLoaded($redirect_to);
         if ($person2->loaded) {
             @ob_end_clean();
             header('Location: ' . $this->getUrl($redirect = true) . '?redirect=a_' . $this->id);
             exit;
         }
     }
     $out['picture'] = $this->getPicture();
     $langId = $this->data['author_lang'] ? $this->data['author_lang'] : 136;
     foreach (Config::$langs as $code => $id_lang) {
         if ($id_lang == $langId) {
             $langCode = $code;
         }
     }
     $out['lang_code'] = $langCode;
     $out['id'] = $this->id;
     $out['lang_title'] = Config::$langRus[$langCode];
     $out['lang_id'] = $langId;
     $out['first_name'] = $this->data['first_name'];
     $out['last_name'] = $this->data['last_name'];
     $out['middle_name'] = $this->data['middle_name'];
     $out['avg_mark'] = $this->getAvgMark();
     $date_b = timestamp_to_ymd($this->data['date_birth']);
     $date_b = (int) $date_b[0] ? digit2($date_b[2]) . '.' . digit2($date_b[1]) . '.' . $date_b[0] : '';
     $date_d = timestamp_to_ymd($this->data['date_death']);
     $date_d = (int) $date_d[0] ? digit2($date_d[2]) . '.' . digit2($date_d[1]) . '.' . $date_d[0] : '';
     $out['date_birth'] = $date_b;
     $out['date_death'] = $date_d;
     $out['wiki_url'] = $this->data['wiki_url'];
     $out['homepage'] = $this->data['homepage'];
     $out['bio']['html'] = $this->data['bio'];
     $out['bio']['short'] = $this->data['short_bio'];
     $out['lastSave'] = $this->data['authorlastSave'];
     return $out;
 }
示例#4
0
 function getAuthorContributionComments()
 {
     global $current_user;
     /* @var $current_user CurrentUser */
     $id_author = isset($this->params['author_id']) ? (int) $this->params['author_id'] : false;
     if (!$id_author) {
         throw new Exception('author  not exists');
     }
     $author = Persons::getInstance()->getByIdLoaded($id_author);
     /* @var $author Person */
     if (!$author->exists) {
         throw new Exception('author #' . $author->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::getAuthorComments($id_author, $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'] = 'author';
         $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'] = 'Обсуждение автора ' . $author->getName() . '';
     $this->data['comments']['count'] = $count;
     $this->data['users'] = $this->getCommentsUsers($uids);
 }
示例#5
0
 function add_relation()
 {
     global $current_user;
     $this->ca();
     $id1 = isset($_POST['id']) ? (int) $_POST['id'] : false;
     $id2 = isset($_POST['author_id']) ? (int) $_POST['author_id'] : false;
     if ($id1 == $id2) {
         $this->data['error'] = 'Онанизмъ';
         return false;
     }
     $relation_type = isset($_POST['relation_type']) ? (int) $_POST['relation_type'] : false;
     $person1 = Persons::getInstance()->getByIdLoaded($id1);
     $person2 = Persons::getInstance()->getByIdLoaded($id2);
     /* @var $person2 Person */
     if (!$person2 || !$person1) {
         $this->data['error'] = 'Нет такого автора';
         return false;
     }
     if (!$id1 || !$id2 || !$relation_type) {
         throw new Exception('id or item_id or relation_type missed');
     }
     if (PersonRelations::addRelation($id1, $id2, $relation_type)) {
         $this->data['success'] = 1;
         $this->data['item_id'] = $id2;
         $this->data['relation_type'] = PersonRelations::$relation_types[$relation_type];
         /* @var $book2 Book */
         $this->data['title'] = $person2->getName();
         $search = Search::getInstance();
         /* @var $search Search */
         $search->setAuthorToFullUpdate($person2->id);
         $search->setAuthorToFullUpdate($person1->id);
     } else {
         $this->data['success'] = 0;
         $this->data['error'] = 'ошибочка: ' . PersonRelations::getLastError();
     }
 }
示例#6
0
文件: Book.php 项目: rasstroen/metro
 function loadPersons($persons = false)
 {
     if ($this->personsLoaded) {
         return false;
     }
     if ($persons !== false) {
         $pid = array();
         foreach ($persons as $person) {
             $pid[] = $person['id_person'];
         }
         Persons::getInstance()->getByIdsLoaded($pid);
     } else {
         // связи
         $query = 'SELECT `person_role`,`id_person` FROM `book_persons` WHERE `id_book`=' . $this->id;
         $persons = Database::sql2array($query, 'id_person');
         // профили
         $personProfiles = array();
         if (count($persons)) {
             $ids = array_keys($persons);
             Persons::getInstance()->getByIdsLoaded($ids);
         }
     }
     foreach ($persons as $person) {
         $personItem = Persons::getInstance()->getByIdLoaded($person['id_person']);
         if ($personItem->loaded) {
             $personProfiles[$person['id_person']] = $personItem->getListData();
             $personProfiles[$person['id_person']]['role'] = $person['person_role'];
             $personProfiles[$person['id_person']]['roleName'] = $this->getPersonRoleName($person['person_role']);
             $this->persons[] = $personProfiles[$person['id_person']];
         }
     }
     $this->personsLoaded = true;
 }
示例#7
0
 function add_author()
 {
     global $current_user;
     $this->ca();
     $id_person = (int) $_POST['id_author'];
     $id_book = (int) $_POST['id'];
     $id_role = (int) $_POST['id_role'];
     if ($id_role && $id_person && $id_book) {
         $persons = Persons::getInstance()->getByIdsLoaded(array($id_person));
         if (!isset($persons[$id_person]) || !$persons[$id_person]->id) {
             $this->data['item_id'] = $id_person;
             $this->data['success'] = 0;
             $this->data['error'] = 'Нет такого автора';
             return;
         }
         $query = 'INSERT INTO `book_persons` SET `id_book`=' . $id_book . ' , `id_person`=' . $id_person . ', `person_role`=' . $id_role;
         $r = Database::query($query, false);
         if ($r) {
             $this->data['success'] = 1;
             $this->data['item_id'] = $id_person;
             $this->data['name'] = $persons[$id_person]->getName();
             $this->data['role'] = Config::$person_roles[$id_role];
             BookLog::addLog(array('id_person' => $id_person, 'person_role' => $id_role), array('id_person' => 0, 'person_role' => 0), $id_book);
             $log_id = BookLog::saveLog($id_book, BookLog::TargetType_book, $current_user->id, BiberLog::BiberLogType_bookEditPerson);
             BookLog::saveLogLink($log_id, $id_person, BookLog::TargetType_person, $current_user->id, BiberLog::BiberLogType_bookEditPerson, $copy = 1);
             $search = Search::getInstance();
             /* @var $search Search */
             $search->updateBook(new Book($id_book));
             Notify::notifyAuthorNewBook($id_person, $id_book);
         } else {
             $this->data['error'] = 'Автор уже есть в списке авторов';
         }
         return;
     }
     $this->data['item_id'] = $id_person;
     $this->data['success'] = 0;
 }
示例#8
0
 function getLogPersons($ids)
 {
     $persons = Persons::getInstance()->getByIdsLoaded($ids);
     $out = array();
     if (is_array($persons)) {
         foreach ($persons as $person) {
             $out[] = $person->getListData();
         }
     }
     return $out;
 }
示例#9
0
 function getStatAuthors($aids)
 {
     if (!count($aids)) {
         return array();
     }
     $persons = Persons::getInstance()->getByIdsLoaded($aids);
     $out = array();
     foreach ($persons as $person) {
         $out[] = $person->getListData();
     }
     foreach ($out as &$r) {
         $r['path'] = Config::need('www_path') . '/admin/authors/' . $r['id'];
     }
     return $out;
 }
示例#10
0
 private static function undo_repeat_personNew($logdata)
 {
     $data = unserialize($logdata['data']);
     $query = 'UPDATE `persons` SET `is_deleted`=0 WHERE `id`=' . $data['id_person'];
     Database::query($query);
     self::undo_repeat_personEdit($logdata);
     Persons::getInstance()->dropCache($data['id_person']);
 }
示例#11
0
 function getAuthorRelations()
 {
     if (!$this->params['author_id']) {
         return;
     }
     $person = Persons::getInstance()->getByIdLoaded($this->params['author_id']);
     foreach (PersonRelations::$relation_types as $id => $title) {
         $this->data['author']['relation_types'][] = array('id' => $id, 'name' => $title);
     }
     /* @var $person Person */
     if (!$person->loaded) {
         return false;
     }
     $aids = array();
     if ($basket_id = $person->getBasketId()) {
         $query = 'SELECT * FROM `person_basket` WHERE `id_basket`=' . $basket_id;
         $relations = Database::sql2array($query);
         foreach ($relations as $relation) {
             $aids[$relation['id_person']] = $relation['id_person'];
         }
         Persons::getInstance()->getByIdsLoaded($aids);
         foreach ($relations as &$relation) {
             if ($relation['id_person'] == $person->id) {
                 continue;
             }
             $relperson = Persons::getInstance()->getByIdLoaded($relation['id_person']);
             $aids[$relation['id_person']] = $relation['id_person'];
             if ($person->getLangId() != $relperson->getLangId()) {
                 $relation['type'] = PersonRelations::RELATION_TYPE_TRANSLATE;
             } else {
                 $relation['type'] = PersonRelations::RELATION_TYPE_EDITION;
             }
             $relation['relation_type_name'] = PersonRelations::$relation_types[$relation['type']];
             $relation['id1'] = $person->id;
             $relation['id2'] = $relation['id_person'];
             $this->data['author']['relations'][] = $relation;
         }
     }
     $query = 'SELECT `id`,`is_p_duplicate` FROM `persons` WHERE `is_p_duplicate`=' . $person->id . ' OR `id`=' . $person->id;
     $rows = Database::sql2array($query);
     if (count($rows)) {
         foreach ($rows as $row) {
             if ($row['is_p_duplicate']) {
                 $relation = array('desc' => $row['id'] . ' is duplicate for ' . $row['is_p_duplicate'], 'id2' => (int) $row['id'], 'id1' => (int) $row['is_p_duplicate'], 'id_person' => (int) $row['id'], 'type' => PersonRelations::RELATION_TYPE_DUPLICATE, 'relation_type_name' => PersonRelations::$relation_types[PersonRelations::RELATION_TYPE_DUPLICATE]);
                 $this->data['author']['relations'][] = $relation;
                 $aids[$row['id']] = $row['id'];
                 $aids[$row['is_p_duplicate']] = $row['is_p_duplicate'];
             }
         }
     }
     $data = $this->_idsToData(array_keys($aids));
     $this->data['author']['relations']['authors'] = $data['authors'];
 }
示例#12
0
 function write()
 {
     global $current_user;
     $current_user->can_throw('books_edit');
     $id = isset(Request::$post['id']) ? (int) Request::$post['id'] : false;
     if (!$id) {
         $this->newAuthor();
         return;
     }
     $person = Persons::getInstance()->getByIdLoaded($id);
     if (!$person) {
         return;
     }
     $savedData = $person->data;
     /* @var $book Book */
     $fields = array('lang_code' => 'author_lang', 'bio' => 'bio', 'first_name' => 'first_name', 'middle_name' => 'middle_name', 'last_name' => 'last_name', 'homepage' => 'homepage', 'wiki_url' => 'wiki_url', 'date_birth' => 'date_birth', 'date_death' => 'date_death');
     if (!Request::$post['first_name'] || !Request::$post['last_name']) {
         throw new Exception('no author\'s name');
     }
     if (!Request::$post['lang_code']) {
         throw new Exception('no author\'s language');
     }
     Request::$post['lang_code'] = Config::$langs[Request::$post['lang_code']];
     $to_update = array();
     if (isset($_FILES['picture']) && $_FILES['picture']['tmp_name']) {
         $folder = Config::need('static_path') . '/upload/authors/' . ceil($person->id / 5000);
         @mkdir($folder);
         // inserting new cover
         $query = 'INSERT INTO `person_covers` SET `id_person`=' . $person->id;
         Database::query($query);
         $cover_id = Database::lastInsertId();
         // generating file names
         $filename_normal = $folder . '/default_' . $person->id . '_' . $cover_id . '.jpg';
         $filename_small = $folder . '/small_' . $person->id . '_' . $cover_id . '.jpg';
         $filename_big = $folder . '/big_' . $person->id . '_' . $cover_id . '.jpg';
         $filename_orig = $folder . '/orig_' . $person->id . '_' . $cover_id . '.jpg';
         $to_update['has_cover'] = $cover_id;
         $thumb = new Thumb();
         $thumb->createThumbnails($_FILES['picture']['tmp_name'], array($filename_small, $filename_normal, $filename_big, $filename_orig), self::$cover_sizes);
         if ($savedData['has_cover']) {
             $current_user->gainActionPoints('authors_add_cover', $person->id, BiberLog::TargetType_person);
         } else {
             $current_user->gainActionPoints('authors_edit_cover', $person->id, BiberLog::TargetType_person);
         }
     }
     foreach ($fields as $field => $personfield) {
         if (!isset(Request::$post[$field])) {
             throw new Exception('field missed #' . $field);
         }
         if ($person->data[$personfield] != Request::$post[$field]) {
             $to_update[$personfield] = Request::$post[$field];
         }
     }
     $q = array();
     if (count($to_update)) {
         $to_update['authorlastSave'] = time();
     }
     foreach ($to_update as $field => &$value) {
         if ($field == 'date_birth' || $field == 'date_death') {
             $value = getDateFromString($value);
         }
         if ($field == 'bio') {
             list($full, $short) = $person->processBio($value);
             $q[] = '`bio`=' . Database::escape($full) . '';
             $q[] = '`short_bio`=' . Database::escape($short) . '';
             $value = $person->data['bio'] = $full;
             $person->data['short_bio'] = $short;
         } else {
             $q[] = '`' . $field . '`=' . Database::escape($value) . '';
             $person->data[$field] = $value;
         }
     }
     if (count($q)) {
         $query = 'UPDATE `persons` SET ' . implode(',', $q) . ' WHERE `id`=' . $person->id;
         Database::query($query);
         unset($to_update['authorlastSave']);
         PersonLog::addLog($to_update, $savedData, $person->id);
         PersonLog::saveLog($person->id, BiberLog::TargetType_person, $current_user->id, BiberLog::BiberLogType_personEdit);
         Persons::getInstance()->dropCache($person->id);
         $current_user->gainActionPoints(BiberLog::$actionTypes[BiberLog::BiberLogType_personEdit], $person->id, BiberLog::TargetType_person);
         $search = Search::getInstance();
         /* @var $search Search */
         $search->setAuthorToFullUpdate($person->id);
     }
     ob_end_clean();
     header('Location:' . Config::need('www_path') . '/a/' . $person->id);
     exit;
 }
示例#13
0
 private static function setEdition($id1, $id2)
 {
     global $current_user;
     $type = self::RELATION_TYPE_EDITION;
     try {
         $person1 = Persons::getInstance()->getByIdLoaded($id1);
         $person2 = Persons::getInstance()->getByIdLoaded($id2);
         /* @var $person1 Person */
         /* @var $person2 Person */
         if ($person2->getLangId() != Config::$langs['ru']) {
             $type = self::RELATION_TYPE_TRANSLATE;
         }
         Database::query('START TRANSACTION');
         if ($id1 == $id2) {
             self::setError('Онанизмъ!');
             return false;
         }
         if ($person1->getBasketId() && $person1->getBasketId() == $person2->getBasketId()) {
             self::setError('Книги уже связаны!');
             return false;
         }
         // смотрим книги.
         $basket_id = max($person1->getBasketId(), $person2->getBasketId());
         $basket_old = 0;
         if (!$basket_id) {
             $query = 'INSERT INTO `pbasket` SET `time`=' . time();
             Database::query($query);
             $basket_id = Database::lastInsertId();
         }
         $to_change = array();
         $to_old = array();
         if ($basket_id == $person1->getBasketId()) {
             if ($person2->getBasketId()) {
                 $basket_old = $person2->getBasketId();
                 // из 2 корзины всё в первую
                 $query = 'SELECT * FROM `person_basket` WHERE `id_basket`=' . $person2->getBasketId();
                 $relations = Database::sql2array($query);
                 foreach ($relations as $relation) {
                     $to_change[$relation['id_person']] = $relation['id_person'];
                 }
                 $query = 'SELECT * FROM `person_basket` WHERE `id_basket`=' . $person1->getBasketId();
                 $relations = Database::sql2array($query);
                 foreach ($relations as $relation) {
                     $to_old[$relation['id_person']] = $relation['id_person'];
                 }
                 $query = 'UPDATE `person_basket` SET `id_basket`=' . $basket_id . ' WHERE `id_basket`=' . $person2->getBasketId();
                 Database::query($query);
                 $query = 'UPDATE `persons` SET `id_basket`=' . $basket_id . ' WHERE `id_basket`=' . $person2->getBasketId();
                 Database::query($query);
             } else {
                 $query = 'SELECT * FROM `person_basket` WHERE `id_basket`=' . $person1->getBasketId();
                 $relations = Database::sql2array($query);
                 foreach ($relations as $relation) {
                     $to_old[$relation['id_person']] = $relation['id_person'];
                 }
             }
         } else {
             if ($basket_id == $person2->getBasketId()) {
                 if ($person1->getBasketId()) {
                     $basket_old = $person1->getBasketId();
                     // из 1 корзины всё во вторую
                     $query = 'SELECT * FROM `person_basket` WHERE `id_basket`=' . $person1->getBasketId();
                     $relations = Database::sql2array($query);
                     foreach ($relations as $relation) {
                         $to_change[$relation['id_person']] = $relation['id_person'];
                     }
                     $query = 'SELECT * FROM `person_basket` WHERE `id_basket`=' . $person2->getBasketId();
                     $relations = Database::sql2array($query);
                     foreach ($relations as $relation) {
                         $to_old[$relation['id_person']] = $relation['id_person'];
                     }
                     $query = 'UPDATE `person_basket` SET `id_basket`=' . $basket_id . ' WHERE `id_basket`=' . $person1->getBasketId();
                     Database::query($query);
                     $query = 'UPDATE `persons` SET `id_basket`=' . $basket_id . ' WHERE `id_basket`=' . $person1->getBasketId();
                     Database::query($query);
                 } else {
                     $query = 'SELECT * FROM `person_basket` WHERE `id_basket`=' . $person2->getBasketId();
                     $relations = Database::sql2array($query);
                     foreach ($relations as $relation) {
                         $to_old[$relation['id_person']] = $relation['id_person'];
                     }
                 }
             }
         }
         // 2 книги в корзинку
         if ($person1->getBasketId() != $basket_id) {
             $to_change[$person1->id] = $person1->id;
         }
         if ($person2->getBasketId() != $basket_id) {
             $to_change[$person2->id] = $person2->id;
         }
         $query = 'UPDATE `persons` SET `id_basket`=' . $basket_id . ' WHERE `id` IN (' . $person1->id . ',' . $person2->id . ')';
         Database::query($query);
         // сохраняем в лог создание релейшна для книг, у которых поменялся id_basket
         if (count($to_change)) {
             $now = array('id_basket' => $basket_id, 'new_relations' => $to_change, 'old_relations' => $to_old);
             $was = array('id_basket' => $basket_old, 'new_relations' => array(), 'old_relations' => array());
             PersonLog::addLog($now, $was, $person1->id);
             $ids = array_merge($to_change, $to_old);
             PersonLog::saveLog($ids, PersonLog::TargetType_person, $current_user->id, BiberLog::BiberLogType_personAddRelation);
         }
         foreach ($ids as $id) {
             Persons::getInstance()->dropCache($id);
         }
         $query = 'REPLACE INTO `person_basket`(`id_person`,`id_basket`) VALUES (' . $person1->id . ',' . $basket_id . '),(' . $person2->id . ',' . $basket_id . ')';
         Database::query($query);
         Database::query('COMMIT');
     } catch (Exception $e) {
         self::setError($e->getMessage());
         return false;
     }
     return true;
 }
示例#14
0
 function getOneFull()
 {
     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)) . ') AND `is_deleted`=0');
     $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'];
     }
     $aids = array();
     if (count($bid)) {
         Books::getInstance()->getByIdsLoaded($bid);
         Books::getInstance()->LoadBookPersons($bid);
     }
     foreach ($series_books_p as &$sb) {
         foreach ($sb as &$bookrow) {
             $book = Books::getInstance()->getById($bookrow['id_book']);
             list($aid, $aname) = $book->getAuthor(1, 1, 1);
             // именно наш автор, если их там много
             $bookrow = $book->getListData();
             $aids[$aid] = $aid;
         }
     }
     if (count($aids)) {
         $persons = Persons::getInstance()->getByIdsLoaded($aids);
         foreach ($persons as $person) {
             $this->data['authors'][] = $person->getListData();
         }
     }
     $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 {
             $ser['path'] = Config::need('www_path') . '/series/' . $ser['id'];
             $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;
 }
示例#15
0
 public function updateAuthorsFull($aids)
 {
     $documents = array();
     Books::$books_instance = false;
     // cached books?
     Persons::$persons_instance = false;
     // cached persons?
     $persons = Persons::getInstance()->getByIdsLoaded($aids);
     foreach ($persons as $person) {
         /* @var $person Person */
         $documents[] = $this->prepareAuthorFull($person);
     }
     $authors = self::$authors;
     /* @var $books Apache_Solr_Service */
     // удаляем из индекса
     $authors->deleteByMultipleIds($aids);
     // добавляем в индекс
     $authors->addDocuments($documents);
     // коммитим изменения
     $authors->commit();
     // оптимизируем поисковую базу
     $authors->optimize();
 }
示例#16
0
 function getContributionAuthors($aids)
 {
     if (!count($aids)) {
         return array();
     }
     $persons = Persons::getInstance()->getByIdsLoaded($aids);
     $out = array();
     foreach ($persons as $person) {
         $out[] = $person->getListData();
     }
     return $out;
 }
示例#17
0
 public static function buildPageTitlePart($var)
 {
     $x = explode(':', $var[1]);
     $name = false;
     if (count($x) == 3) {
         list($name, $paramtype, $paramvalue) = $x;
     }
     if (count($x) == 2) {
         list($name, $paramvalue) = $x;
         $paramtype = 'raw_get';
     }
     if ($name) {
         $val = self::parseParams($paramtype, $paramvalue);
         switch ($name) {
             case 'profile-nickname':
                 $user = Users::getByIdsLoaded(array((int) $val));
                 $user = isset($user[$val]) ? $user[$val] : false;
                 /* @var $user User */
                 if ($user) {
                     return $user->getNickName();
                 }
                 break;
             case 'book-title':
                 $book = Books::getInstance()->getByIdLoaded((int) $val);
                 /* @var $book Book */
                 return $book->getTitle(1);
                 break;
             case 'person-title':
                 $person = Persons::getInstance()->getById((int) $val);
                 /* @var $person Person */
                 return $person->getName();
                 break;
             case 'genre-title':
                 return Request::pass('genre-title');
                 break;
             case 'forum-title':
                 $t = Request::pass('forum-title');
                 if (!$t) {
                     $t = Database::sql2single('SELECT name FROM `term_data` WHERE `tid`=' . (int) $val);
                 }
                 return $t;
                 break;
             case 'post-subject':
                 return Request::pass('post-subject');
                 break;
             case 'theme-title':
                 return Request::pass('theme-title');
                 break;
             case 'serie-title':
                 $t = Request::pass('serie-title');
                 if (!$t) {
                     $t = Database::sql2single('SELECT `title` FROM `series` WHERE `id`=' . (int) $val);
                 }
                 return $t;
                 break;
             case 'shelf-name':
                 if ($val == 'loved') {
                     return 'Любимые книги';
                 }
                 if (isset(Config::$shelfIdByNames[$val])) {
                     return isset(Config::$shelves[Config::$shelfIdByNames[$val]]) ? Config::$shelves[Config::$shelfIdByNames[$val]] : $val;
                 }
                 break;
             case 'magazine-title':
                 $query = 'SELECT `title` FROM `magazines` WHERE `id`=' . (int) $val;
                 return Database::sql2single($query);
                 break;
             case 'thread-subject':
                 $query = 'SELECT `subject` FROM `users_messages` WHERE `id`=' . (int) $val;
                 return Database::sql2single($query);
                 break;
             case 'get':
                 return $val;
                 break;
             default:
                 throw new Exception('Cant process title part "' . $var[1] . '"');
                 break;
         }
     }
 }
示例#18
0
 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');
         }
     }
 }