Example #1
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');
         }
     }
 }
Example #2
0
 function getEvent()
 {
     if (!$this->post_id) {
         throw new Exception('illegal event id');
     }
     $query = 'SELECT `mongoid` FROM `events` WHERE `id`=' . (int) $this->post_id;
     $integer_id = Database::sql2single($query);
     if (!(int) $integer_id) {
         return;
     }
     if ($this->user_id) {
         $wall = MongoDatabase::getUserWallItem($integer_id, $this->user_id);
         $events = MongoDatabase::getWallEvents($wall);
     } else {
         $events = MongoDatabase::getWallEvents(array(array('id' => $integer_id)));
     }
     Request::pass('post-subject', isset($events[0]['subject']) ? $events[0]['subject'] : 'запись');
     $this->_list($events, $item = true);
 }
Example #3
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;
         }
     }
 }
Example #4
0
 function getOne()
 {
     if (!$this->series_id) {
         return;
     }
     $series = Database::sql2array('SELECT id,title,position,books_count,id_parent,description,is_s_duplicate FROM `series` WHERE (`id`=' . $this->series_id . ' OR `id_parent`=' . $this->series_id . ') AND `is_deleted`=0', 'id');
     if (!count($series)) {
         throw new Exception('К сожалению, такого у нас в базе совсем нет');
     }
     $parent_id = $series[$this->series_id]['id_parent'];
     if ($parent_id) {
         $parentInfo = Database::sql2row('SELECT id,title,position,books_count,id_parent FROM `series` WHERE `id`=' . $parent_id, 'id');
     } else {
         $parentInfo = array();
     }
     if ($series[$this->series_id]['is_s_duplicate']) {
         // is duplicate
         header('Location: /s/' . $series[$this->series_id]['is_s_duplicate'] . '?redirect=s_' . $this->series_id);
         exit;
     }
     $cond = new Conditions();
     $cnt = Database::sql2single('SELECT COUNT(1) FROM `book_series` WHERE id_series =' . $this->series_id);
     $cond->setPaging($cnt, self::PER_PAGE);
     $limit = $cond->getLimit();
     $this->data['conditions'] = $cond->getConditions();
     $series_books = Database::sql2array('SELECT * FROM `book_series` WHERE id_series =' . $this->series_id . ' LIMIT ' . $limit);
     $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();
     $series[$this->series_id]['path'] = Config::need('www_path') . '/s/' . $this->series_id;
     $this->data['serie'] = $series[$this->series_id];
     Request::pass('serie-title', $this->data['serie']['title']);
     $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') . '/s/' . $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']);
         }
     }
     if ($parentInfo) {
         $parentInfo['path'] = Config::need('www_path') . '/s/' . $parentInfo['id'];
         $this->data['serie']['parent'][] = $parentInfo;
     }
 }
Example #5
0
    function getThemesList()
    {
        $querycnt = 'SELECT COUNT(1) FROM `term_node` TN 
		LEFT JOIN `node` N ON TN.nid = N.nid 
		WHERE `tid`=' . $this->forum_id;
        $count = Database::sql2single($querycnt);
        $cond = new Conditions();
        $cond->setPaging($count, 15);
        $limit = $cond->getLimit();
        $this->data['conditions'] = $cond->getConditions();
        $query = 'SELECT N.uid as author_id, NCS.last_comment_timestamp,NCS.last_comment_uid,N.title,N.nid,N.created,N.changed,comment_count,N.promote,N.sticky,N.status FROM `term_node` TN 
		LEFT JOIN `node` N ON TN.nid = N.nid 
		LEFT OUTER JOIN `node_comment_statistics` NCS ON N.nid = NCS.nid 
		WHERE `tid`=' . $this->forum_id . '
		ORDER BY `changed` DESC LIMIT ' . $limit;
        Request::pass('forum-title', Database::sql2single('SELECT name FROM `term_data` WHERE `tid`=' . $this->forum_id));
        $themesList = Database::sql2array($query);
        foreach ($themesList as &$theme) {
            $theme['comment_count'] = max(0, (int) $theme['comment_count']);
            if ($theme['last_comment_uid']) {
                $uids[$theme['last_comment_uid']] = (int) $theme['last_comment_uid'];
            }
            $uids[$theme['author_id']] = (int) $theme['author_id'];
            $theme['last_comment_timestamp'] = date('Y/m/d H:i', $theme['last_comment_timestamp']);
            $theme['created'] = date('Y/m/d H:i', $theme['created']);
        }
        $this->data['users'] = $this->getUsers($uids);
        $this->data['themes'] = $themesList;
        $this->data['themes']['tid'] = $this->forum_id;
        $this->data['path_new_theme'] = Config::need('www_path') . '/forum/' . $this->forum_id . '/new';
    }