function getRightholders() { $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 : 1; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; $where = ''; $order = 'ORDER BY `id` DESC '; $group_by = ''; $query = 'SELECT COUNT(1) FROM `rightholders` ' . $where . ' ' . $group_by . ''; $count = Database::sql2single($query); $cond->setPaging($count, $per_page, $pagingName); $limit = $cond->getLimit(); $limit = ' LIMIT ' . $limit; $query = 'SELECT * FROM `rightholders`' . $where . ' ' . $group_by . ' ' . $order . ' ' . $limit; $data = Database::sql2array($query); foreach ($data as &$row) { $row['path'] = Config::need('www_path') . '/admin/rightholders/' . $row['id']; } $this->data['rightholders'] = $data; $this->data['rightholders']['title'] = 'Правообладатели'; $this->data['rightholders']['count'] = $count; $this->data['conditions'] = $cond->getConditions(); }
function _list($opts) { $data = array(); $has_paging = !isset($opts['no_paging']); $show_sortings = isset($opts['show_sortings']); $per_page = isset($opts['per_page']) ? $opts['per_page'] : 10; $per_page = min(100, max(1, (int) $per_page)); $cond = new Conditions(); $cond->setSorting(array('time' => array('order' => 'desc', 'title' => 'по дате')), array('time' => array('order' => 'desc', 'title' => 'по дате'))); $cond->setPaging(100000, $per_page); $where = array('parent_id=0'); if (isset($opts['where'])) { foreach ($opts['where'] as $w) { $where[] = $w; } } $order = $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL(); $limit = $cond->getLimit(); $query = 'SELECT * FROM `comments` WHERE (' . implode(' AND ', $where) . ') ORDER BY ' . $order . ' LIMIT ' . $limit . ''; $comments = Database::sql2array($query, 'id'); $pids = array(); $uids = array(); foreach ($comments as $comment) { $pids[$comment['id']] = $comment['id']; $uids[$comment['user_id']] = $comment['user_id']; } if (count($pids)) { $query = 'SELECT * FROM `comments` WHERE `thread` IN (' . implode(',', $pids) . ') ORDER BY `thread`,`id`'; $nextlevel = Database::sql2array($query, 'id'); $comments += $nextlevel; foreach ($comments as $comment) { $uids[$comment['user_id']] = $comment['user_id']; } if (count($uids)) { $users = Users::getByIdsLoaded($uids); } else { $users = array(); } foreach ($comments as &$comment) { if (!isset($users[$comment['user_id']])) { continue; } $comment['user'] = $users[$comment['user_id']]; $parents[$comment['parent_id']][$comment['id']] = $comment; uasort($parents[$comment['parent_id']], 'x_sort_comment'); } $comments = $this->build_tree($parents, 0); } return $comments; }
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'); } } }
function _list($opts = array()) { $has_paging = !isset($opts['no_paging']); $show_sortings = isset($opts['show_sortings']); $per_page = isset($opts['per_page']) ? $opts['per_page'] : 10; $per_page = min(100, max(1, (int) $per_page)); $cond = new Conditions(); $cond->setSorting(array('created' => array('order' => 'desc', 'title' => 'по дате'))); $cond->setPaging(100000, $per_page); $where = array('1'); if (isset($opts['where'])) { foreach ($opts['where'] as $w) { $where[] = $w; } } $order = $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL(); $limit = $cond->getLimit(); $query = 'SELECT SQL_CALC_FOUND_ROWS P. * , GROUP_CONCAT( T.title ) AS tags, GROUP_CONCAT( PT.tag_id ) AS tags_indexes FROM `publications` P LEFT JOIN `publications_tags` PT ON PT.publication_id = P.id LEFT JOIN `tags` T ON T.id = PT.tag_id WHERE (' . implode(' AND ', $where) . ') GROUP BY P.id ORDER BY ' . $order . ' LIMIT ' . $limit . ''; $publications = Database::sql2array($query, 'id'); foreach ($publications as $publication) { $uids[$publication['user_id']] = $publication['user_id']; } $users = Users::getByIdsLoaded($uids); foreach ($publications as &$publication) { $publication['user'] = isset($users[$publication['user_id']]) ? $users[$publication['user_id']]->data : array(); } $cond->setPaging(Database::sql2single('SELECT FOUND_ROWS()'), $per_page); $data['publications'] = $publications; $data['conditions'] = $cond->getConditions(); if (!$show_sortings) { foreach ($data['conditions'] as $key => $group) { if ($group['mode'] == 'sorting') { unset($data['conditions'][$key]); } } } return $data; }
function getSynthesis($mode = 'synthesis') { $min_update_time = time() - 48 * 60 * 60; $query = 'SELECT COUNT(1) FROM `posts` WHERE `update_time`>' . $min_update_time; $count = min(200, Database::sql2single($query)); $cond = new Conditions(); $per_page = 20; $cond->setPaging($count, $per_page, 'p'); $this->data['conditions'] = $cond->getConditions(); $limit = $cond->getLimit(); switch ($mode) { case 'synthesis': $order = 'rating'; break; case 'links': $order = 'rating_links'; break; case 'visits': $order = 'rating_visits'; break; case 'comments': $order = 'rating_comments'; break; } $posts = Database::sql2array('SELECT * FROM `posts` ORDER BY ' . $order . ' DESC LIMIT ' . $limit); $i = 0; foreach ($posts as $data) { $post = new Post($data); $this->data['posts'][$i] = $post->getShort(); $this->data['posts'][$i]['num'] = ($cond->currentPage - 1) * $per_page + $i + 1; $aids[$post->data['id_author']] = $post->data['id_author']; $i++; } if (count($aids)) { $authors = Database::sql2array('SELECT * FROM `authors` WHERE `id` IN(' . implode(',', $aids) . ')'); foreach ($authors as $data) { $author = new Author($data); $this->data['authors'][] = $author->getShort(); } } }
function getSettings() { $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 : 1; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; $where = ''; $order = 'ORDER BY `id` DESC '; $group_by = ''; $query = 'SELECT COUNT(1) FROM `settings` ' . $where . ' ' . $group_by . ''; $count = Database::sql2single($query); $cond->setPaging($count, $per_page, $pagingName); $limit = $cond->getLimit(); $limit = ' LIMIT ' . $limit; $query = 'SELECT * FROM `settings`' . $where . ' ' . $group_by . ' ' . $order . ' ' . $limit; $data = Database::sql2array($query); $this->data['settings'] = $data; $this->data['settings']['title'] = 'Настройки'; $this->data['settings']['count'] = $count; $this->data['conditions'] = $cond->getConditions(); }
function getLog() { if ($this->target_type == 'user') { $query = 'SELECT COUNT(DISTINCT(id_log)) FROM `biber_log_index` WHERE `id_user`=' . $this->id_target . ' '; } else { if ($this->target_type == 'all') { $query = 'SELECT COUNT(DISTINCT(id_log)) FROM `biber_log_index` WHERE `is_copy`=0'; } else { $query = 'SELECT COUNT(1) FROM `biber_log_index` WHERE `target_type`=' . $this->target_type . ' AND `id_target`=' . $this->id_target . ' '; } } $count = min(1000, Database::sql2single($query)); $cond = new Conditions(); $cond->setPaging($count, 10); $this->data['conditions'] = $cond->getConditions(); $limit = $cond->getLimit(); if ($this->target_type == 'user') { $query = 'SELECT * FROM `biber_log_index` WHERE `id_user`=' . $this->id_target . ' GROUP BY id_log ORDER BY `time` DESC LIMIT ' . $limit; } else { if ($this->target_type == 'all') { $query = 'SELECT * FROM `biber_log_index` WHERE `is_copy`=0 GROUP BY id_log ORDER BY `time` DESC LIMIT ' . $limit; } else { $query = 'SELECT * FROM `biber_log_index` WHERE `target_type`=' . $this->target_type . ' AND `id_target`=' . $this->id_target . ' ORDER BY `time` DESC LIMIT ' . $limit; } } $book_ids = array(); $person_ids = array(); $serie_ids = array(); $magazine_ids = array(); $uids = array(); if ($this->target_type == BiberLog::TargetType_book) { $book_ids[$this->id_target] = $this->id_target; } if ($this->target_type == BiberLog::TargetType_person) { $person_ids[$this->id_target] = $this->id_target; } if ($this->target_type == 'user') { $uids[$this->id_target] = $this->id_target; } $arr = array(); $arri = Database::sql2array($query, 'id_log'); $to_fetch_log = array(); foreach ($arri as $row) { $to_fetch_log[(int) $row['id_log']] = (int) $row['id_log']; } if (count($to_fetch_log)) { $query = 'SELECT * FROM `biber_log` WHERE `id` IN (' . implode(',', $to_fetch_log) . ') ORDER BY `time` DESC'; $arr = Database::sql2array($query); foreach ($arr as &$rowx) { foreach ($arri[$rowx['id']] as $f => $v) { $rowx[$f] = $v; } } } foreach ($arr as &$row) { $book_id_s = 0; $uids[$row['id_user']] = $row['id_user']; $vals = unserialize($row['data']); if (isset($vals['id1'])) { $book_ids[$vals['id1'][0]] = $vals['id1'][0]; $book_ids[$vals['id1'][1]] = $vals['id1'][1]; } if (isset($vals['id2'])) { $book_ids[$vals['id2'][0]] = $vals['id2'][0]; $book_ids[$vals['id2'][1]] = $vals['id2'][1]; } if (isset($vals['id_person'])) { if (isset($vals['id_person'][0])) { $person_ids[$vals['id_person'][0]] = (int) $vals['id_person'][0]; } if (isset($vals['id_person'][1])) { $person_ids[$vals['id_person'][1]] = (int) $vals['id_person'][1]; } } if (isset($vals['is_duplicate'])) { $book_ids[$vals['is_duplicate'][0]] = $vals['is_duplicate'][0]; $book_ids[$vals['is_duplicate'][1]] = $vals['is_duplicate'][1]; } $book_id = 0; $person_id = 0; $serie_id = 0; $values = array(); foreach ($vals as $field => $v) { if (!is_array($v)) { if ($field == 'id_book') { $book_id = $v; $book_ids[$v] = $v; } if ($field == 'id_person') { $person_id = $v; $person_ids[$v] = $v; } if ($field == 'id_serie') { $serie_id = $v; $serie_ids[$v] = $v; } if ($field == 'id_magazine') { $serie_id = $v; $magazine_ids[$v] = $v; } continue; } $tmp = array(); if ($row['target_type'] == BiberLog::TargetType_book) { if ($field == 'new_relations') { foreach ($v[1] as $new_relation_id) { $book_ids[$new_relation_id] = $new_relation_id; $tmp[] = array('book_id' => $new_relation_id); } $values['new_relations'] = $tmp; } else { if ($field == 'old_relations') { foreach ($v[1] as $new_relation_id) { $book_ids[$new_relation_id] = $new_relation_id; $tmp[] = array('book_id' => $new_relation_id); } $values['old_relations'] = $tmp; } else { if ($field == 'deleted_relations') { foreach ($v[1] as $new_relation_id) { $book_ids[$new_relation_id] = $new_relation_id; $tmp[] = array('book_id' => $new_relation_id); } $values['deleted_relations'] = $tmp; } else { $values[] = array('name' => $field, 'old' => $v[0], 'new' => $v[1]); } } } } else { if ($row['target_type'] == BiberLog::TargetType_person) { if ($field == 'new_relations') { foreach ($v[1] as $new_relation_id) { $person_ids[$new_relation_id] = (int) $new_relation_id; $tmp[] = array('author_id' => $new_relation_id); } $values['new_relations'] = $tmp; } else { if ($field == 'old_relations') { foreach ($v[1] as $new_relation_id) { $person_ids[$new_relation_id] = (int) $new_relation_id; $tmp[] = array('author_id' => $new_relation_id); } $values['old_relations'] = $tmp; } else { if ($field == 'deleted_relations') { foreach ($v[1] as $new_relation_id) { $person_ids[$new_relation_id] = (int) $new_relation_id; $tmp[] = array('author_id' => $new_relation_id); } $values['deleted_relations'] = $tmp; } else { $values[] = array('name' => $field, 'old' => $v[0], 'new' => $v[1]); } } } } else { if ($row['target_type'] == BiberLog::TargetType_magazine) { $values[] = array('name' => $field, 'old' => $v[0], 'new' => $v[1]); } else { if ($row['target_type'] == BiberLog::TargetType_serie) { if ($field == 'id_book') { $book_id_s = $v[0] ? $v[0] : $v[1]; if ($book_id_s) { $book_ids[$book_id_s] = $book_id_s; } continue; } $values[] = array('name' => $field, 'old' => $v[0], 'new' => $v[1]); } } } } } if (in_array($row['target_type'], array(BiberLog::TargetType_book))) { $book_ids[$row['id_target']] = $row['id_target']; $book_id = $row['id_target']; } if (in_array($row['target_type'], array(BiberLog::TargetType_person))) { $person_ids[(int) $row['id_target']] = (int) $row['id_target']; $person_id = $row['id_target']; } if (in_array($row['target_type'], array(BiberLog::TargetType_serie))) { $serie_id = $row['id_target']; $serie_ids[$row['id_target']] = $row['id_target']; } if (in_array($row['target_type'], array(BiberLog::TargetType_magazine))) { $magazine_id = $row['id_target']; $magazine_ids[$row['id_target']] = $row['id_target']; } $this->data['logs'][] = array('id' => $row['id'], 'book_id' => max($book_id, $book_id_s), 'author_id' => $person_id, 'serie_id' => $serie_id, 'time' => date('Y/m/d H:i:s', $row['time']), 'action' => BiberLog::$actionTypes[$row['action_type']], 'id_user' => $row['id_user'], 'values' => $values, 'applied' => $row['undo'] ? 0 : 1); } $users = Users::getByIdsLoaded($uids); foreach ($users as $user) { $this->data['users'][$user->id] = $user->getListData(); } if (count($serie_ids)) { $query = 'SELECT id,name,title FROM `series` WHERE `id` IN(' . implode(',', $serie_ids) . ')'; $out = Database::sql2array($query); foreach ($out as &$r) { $r['path'] = Config::need('www_path') . '/s/' . $r['id']; } $this->data['series'] = $out; } if (count($book_ids)) { $this->data['books'] = $this->getLogBooks($book_ids); } if (count($person_ids)) { $this->data['authors'] = $this->getLogPersons($person_ids); } foreach (Config::$langRus as $code => $title) { $this->data['lang_codes'][] = array('id' => Config::$langs[$code], 'code' => $code, 'title' => $title); } }
function getSearch() { $query_string = isset(Request::$get_normal['s']) ? Request::$get_normal['s'] : false; $query_string_prepared = '%' . mysql_escape_string($query_string) . '%'; $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 : 60; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; $where = 'WHERE `nickname` LIKE \'' . $query_string_prepared . '\' OR `email` LIKE \'' . $query_string_prepared . '\' OR `id`=\'' . $query_string_prepared . '\''; $order = 'ORDER BY `regTime` DESC '; $group_by = ''; $query = 'SELECT COUNT(1) FROM `users` ' . $where . ' ' . $group_by . ''; $count = Database::sql2single($query); $cond->setPaging($count, $per_page, $pagingName); $limit = $cond->getLimit(); $limit = ' LIMIT ' . $limit; $query = 'SELECT * FROM `users`' . $where . ' ' . $group_by . ' ' . $order . ' ' . $limit; $data = Database::sql2array($query); foreach ($data as $row) { $user = new User($row['id'], $row); Users::add($user); $this->data['users'][] = $user->getListData(true); } $this->data['users']['title'] = 'Пользователи'; $this->data['users']['count'] = $count; $this->data['conditions'] = $cond->getConditions(); }
function getStatistics($type, $id_target = false) { $id_target = $id_target ? max(0, (int) $id_target) : false; $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 : 1; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; $time_start = Request::get('from'); $time_end = Request::get('to'); $curtime = time(); if (!$time_start) { $time_start = strtotime(date('Y-m-1 00:00:00')); } else { $time_start = strtotime(date('Y-m-d 00:00:00', strtotime($time_start))); } if (!$time_end) { $time_end = strtotime(date('Y-m-d 23:59:59')); } else { $time_end = strtotime(date('Y-m-d 23:59:59', strtotime($time_end))); } if ($time_end < $time_start) { $t = $time_end; $time_end = $time_start; $time_start = $t; } $where = 'WHERE (`time` >= ' . $time_start . ' AND `time` <= ' . $time_end . ')'; if ($id_target) { $where .= ' AND `id_' . $type . '`=' . $id_target; } if ($type == 'user') { $order = 'ORDER BY COUNT(1) DESC '; } else { $order = 'ORDER BY `count` DESC '; } $group_by = 'GROUP BY `id_' . $type . '`'; if ($id_target) { $group_by = 'GROUP BY `time`'; } $query = 'SELECT COUNT(1) FROM (SELECT 1 FROM `stat_' . $type . '_download`' . $where . ' ' . $group_by . ') s '; $count = Database::sql2single($query); $cond->setPaging($count, $per_page, $pagingName); $limit = $cond->getLimit(); $limit = ' LIMIT ' . $limit; if ($type == 'user') { $query = 'SELECT `id_' . $type . '`,COUNT(1) as `count` , `time` FROM `stat_' . $type . '_download`' . $where . ' ' . $group_by . ' ' . $order . ' ' . $limit; } else { $query = 'SELECT `id_' . $type . '`,sum(`count`) as `count` , `time` FROM `stat_' . $type . '_download`' . $where . ' ' . $group_by . ' ' . $order . ' ' . $limit; } $statistics = Database::sql2array($query); $gids = array(); $aids = array(); $bids = array(); $uids = array(); foreach ($statistics as &$stat) { if ($type == 'genre') { $gids[$stat['id_genre']] = $stat['id_genre']; } if ($type == 'author') { $aids[$stat['id_author']] = $stat['id_author']; } if ($type == 'book') { $bids[$stat['id_book']] = $stat['id_book']; } if ($type == 'user') { $uids[$stat['id_user']] = $stat['id_user']; } $stat['time'] = date('Y/m/d', $stat['time']); $stat['path'] = Config::need('www_path') . '/admin/' . $type . 's/' . $stat['id_' . $type]; } $this->data['genres'] = $this->getStatGenres($gids); if (!count($aids)) { list($this->data['books'], $aids) = $this->getStatBooks($bids); } $this->data['authors'] = $this->getStatAuthors($aids); $this->data['users'] = $this->getStatUsers($uids); $this->data['statistics'] = $statistics; $this->data['statistics']['from'] = date('Y.m.d', $time_start); $this->data['statistics']['to'] = date('Y.m.d', $time_end); $title_part = ''; if ($type == 'book') { $title_part = 'книг'; $title_part_m = 'книги'; } if ($type == 'author') { $title_part = 'книг авторов'; $title_part_m = 'книг автора'; } if ($type == 'genre') { $title_part = 'книг жанров'; $title_part_m = 'книг жанра'; } if ($type == 'user') { $title_part = ' книг пользователями'; $title_part_m = ' книг пользователем '; } if (!$id_target) { $this->data['statistics']['title'] = 'Статистика по скачиванию ' . $title_part . ' за период с ' . $this->data['statistics']['from'] . ' по ' . $this->data['statistics']['to']; } else { $this->data['statistics']['title'] = 'Статистика по скачиванию ' . $title_part_m . ' за период с ' . $this->data['statistics']['from'] . ' по ' . $this->data['statistics']['to']; } $this->data['statistics']['count'] = $count; $this->data['conditions'] = $cond->getConditions(); $this->data['statistics']['current_month_path'] = Request::$url . '?from=' . date('Y-m-01', strtotime(date('Y-m-1 00:00:00'))) . '&to=' . date('Y-m-d', strtotime(date('Y-m-d 23:59:59')) + 1); $this->data['statistics']['last_month_path'] = Request::$url . '?from=' . date('Y-m-01', strtotime(date('Y-m-1 00:00:00')) - 1) . '&to=' . date('Y-m-d', strtotime(date('Y-m-1 00:00:00')) - 1); }
/** * устанавливает $this->data[items_name] * @param type $where * @param type $sortings * @param type $return */ function _list($where, $sortings = false, $return = false) { $limit = false; $order = false; $sorting_order = false; $cond = new Conditions(); if ($this->ConditionsEnabled) { // пейджинг, сортировка if ($sortings) { $cond->setSorting($sortings); $order = $cond->getSortingField(); $sorting_order = $cond->getSortingOrderSQL(); } $per_page = isset($this->params['per_page']) ? $this->params['per_page'] : 0; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; if ($per_page) { $cond->setPaging($this->getCountBySQL($where), $per_page, $pagingName); $limit = $cond->getLimit(); } } $query = $this->prepareSelect('id', $where, $order ? ($order . ' ' . $sorting_order) : '', $limit); $ids = Database::sql2array($query, 'id'); // нашли объекты, которые хотим вывести if ($return) return $this->_idsToData(array_keys($ids)); // отдаем массив else $this->data = $this->_idsToData(array_keys($ids)); // отдаем массив $this->data['conditions'] = $cond->getConditions(); return true; }
function _list($opts = array()) { $has_paging = !isset($opts['no_paging']); $show_sortings = isset($opts['show_sortings']); $per_page = isset($opts['per_page']) ? $opts['per_page'] : 10; $per_page = min(100, max(1, (int) $per_page)); $cond = new Conditions(); if (isset($opts['historical']) && $opts['historical']) { $cond->setSorting(array('eventTime' => array('order' => 'desc', 'title' => 'по исторической дате')), array('eventTime' => array('order' => 'desc', 'title' => 'по исторической дате'))); } else { $cond->setSorting(array('createTime' => array('order' => 'desc', 'title' => 'по дате')), array('createTime' => array('order' => 'desc', 'title' => 'по дате'))); } $cond->setPaging(100000, $per_page); $where = array('1'); if (isset($opts['where'])) { foreach ($opts['where'] as $w) { $where[] = $w; } } $order = $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL(); $limit = $cond->getLimit(); $query = 'SELECT SQL_CALC_FOUND_ROWS A.child_name as child_name,A.birthDate as birthDate,AE.*, LE.*,AE.description as description, LE.description as event_description, LE.title as event_title,AE.title as title, AE.creator_id as user_id,AE.id as id, LE.id as lib_event_id, LET.id as lib_template_id, AE.id as id FROM `album_events` AE LEFT JOIN `album` A ON A.id=AE.album_id LEFT JOIN `lib_events` LE ON LE.id=AE.event_id LEFT JOIN `lib_event_templates` LET ON LET.id=LE.template_id WHERE (' . implode(' AND ', $where) . ') ORDER BY ' . $order . ' LIMIT ' . $limit . ''; $events = Database::sql2array($query, 'id'); $uids = array(); if (count($events)) { $field_values = Database::sql2array('SELECT AEF.*,LETF.title as event_field_title,T.* FROM `album_events_fields` AEF JOIN `lib_event_templates_fields` LETF ON LETF.field_id=AEF.field_id JOIN `lib_event_templates_fields_types` T ON T.id=LETF.type WHERE `event_id` IN(' . implode(',', array_keys($events)) . ')'); } else { $field_values = array(); } foreach ($field_values as $values) { $events[$values['event_id']]['fields'][$values['field_id']] = $values; } foreach ($events as $event) { if ($event['user_id']) { $uids[$event['user_id']] = $event['user_id']; } } if (count($uids)) { $users = Users::getByIdsLoaded($uids); } else { $users = array(); } foreach ($events as &$event) { $event['user'] = isset($users[$event['user_id']]) ? $users[$event['user_id']]->data : array(); $event['template_id'] = $event['template_id'] ? $event['template_id'] : 1; $image_id = $event['picture']; $event['pic_small'] = $image_id ? ImgStore::getUrl($image_id, Config::SIZES_PICTURE_SMALL) : false; $event['pic_normal'] = $image_id ? ImgStore::getUrl($image_id, Config::SIZES_PICTURE_NORMAL) : false; $event['pic_big'] = $image_id ? ImgStore::getUrl($image_id, Config::SIZES_PICTURE_BIG) : false; $event['pic_orig'] = $image_id ? ImgStore::getUrl($image_id, 0) : false; } $cond->setPaging(Database::sql2single('SELECT FOUND_ROWS()'), $per_page); $data['events'] = $events; $data['conditions'] = $cond->getConditions(); if (!$show_sortings) { foreach ($data['conditions'] as $key => $group) { if ($group['mode'] == 'sorting') { unset($data['conditions'][$key]); } } } return $data; }
function listEvents($opts = array()) { $cond = new Conditions(); $per_page = 10; $cond->setPaging(10000, $per_page); $where = array(1); if (isset($opts['where'])) { foreach ($opts['where'] as $f => $v) { $where[] = $f . '=' . Database::escape($v); } } $events = Database::sql2array('SELECT SQL_CALC_FOUND_ROWS * FROM `lib_events` WHERE ' . implode(' AND ', $where) . ' ORDER BY age_start_days,age_end_days LIMIT ' . $cond->getLimit()); $cond->setPaging(Database::sql2single('SELECT FOUND_ROWS()'), $per_page); $template_ids = array(); foreach ($events as $event) { $template_ids[$event['template_id']] = 1; } if (count($template_ids)) { $templates = Database::sql2array('SELECT * FROM lib_event_templates T WHERE id IN(' . implode(',', array_keys($template_ids)) . ')', 'id'); foreach ($events as &$event) { $event['template'] = isset($templates[$event['template_id']]) ? $templates[$event['template_id']]['title'] : false; } } $data['events'] = $events; if (!isset($opts['cond']) || $opts['cond'] == true) { $data['conditions'] = $cond->getConditions(); } return $data; }
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; } }
function getPartners() { $cond = new Conditions(); $per_page = 0; $id_target = 0; if (isset($this->params['per_page'])) { $per_page = (int) $this->params['per_page']; } $per_page = $per_page > 0 ? $per_page : 1; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; $time_start = Request::get('from'); $time_end = Request::get('to'); $curtime = time(); if (!$time_start) { $time_start = strtotime(date('Y-m-1 00:00:00')); } else { $time_start = strtotime(date('Y-m-d 00:00:00', strtotime($time_start))); } if (!$time_end) { $time_end = strtotime(date('Y-m-d 23:59:59')); } else { $time_end = strtotime(date('Y-m-d 23:59:59', strtotime($time_end))); } if ($time_end < $time_start) { $t = $time_end; $time_end = $time_start; $time_start = $t; } $where = 'WHERE ((`time` >= ' . $time_start . ' AND `time` <= ' . $time_end . ') OR `time` IS NULL ) AND `partners`.`id`>0'; if ($id_target) { $where .= ' AND `id_' . $type . '`=' . $id_target; } $order = 'ORDER BY `count` DESC '; $join = 'RIGHT JOIN `partners` ON SUPR.`id_partner`=`partners`.`id`'; $join2 = 'RIGHT JOIN `partners` ON SUPR.`id_partner`=`partners`.`id`'; $group_by = 'GROUP BY partners.`id`'; $query = 'SELECT COUNT(1) FROM `partners`'; $count = Database::sql2single($query); $cond->setPaging($count, $per_page, $pagingName); $limit = $cond->getLimit(); $limit = 'LIMIT ' . $limit; $query = 'SELECT *, COUNT(1) as `count` FROM `stat_user_partner_referer` SUPR ' . $join . ' ' . $where . ' ' . $group_by . ' HAVING `count`>0 ' . $order . ' ' . $limit; $data = Database::sql2array($query, 'id'); $ids = array(); foreach ($data as &$row) { $row['path'] = Config::need('www_path') . '/admin/partners/' . $row['id']; $row['partner_link'] = Config::need('www_path') . '/?pid=' . $row['pid']; $row['path_edit'] = Config::need('www_path') . '/admin/partners/' . $row['id'] . '/edit'; if (!$row['time']) { $row['count'] = 0; } $ids[$row['id']] = $row['id']; } if (count($ids)) { $query = 'SELECT * , 0 as `count` FROM `partners` WHERE `id` NOT IN(' . implode(',', $ids) . ') ' . $order; $nostat = Database::sql2array($query); $i = 0; foreach ($nostat as &$row) { $row['path'] = Config::need('www_path') . '/admin/partners/' . $row['id']; $row['partner_link'] = Config::need('www_path') . '/?pid=' . $row['pid']; $row['path_edit'] = Config::need('www_path') . '/admin/partners/' . $row['id'] . '/edit'; $data[$row['id']] = $row; } } uasort($data, 'sort_by_count'); $this->data['partners'] = $data; $this->data['partners']['title'] = 'Партнёры'; $this->data['partners']['count'] = $count; $this->data['conditions'] = $cond->getConditions(); $this->data['statistics']['current_month_path'] = Request::$url . '?from=' . date('Y-m-01', strtotime(date('Y-m-1 00:00:00'))) . '&to=' . date('Y-m-d', strtotime(date('Y-m-d 23:59:59')) + 1); $this->data['statistics']['last_month_path'] = Request::$url . '?from=' . date('Y-m-01', strtotime(date('Y-m-1 00:00:00')) - 1) . '&to=' . date('Y-m-d', strtotime(date('Y-m-1 00:00:00')) - 1); }
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'; }
function getUserContribution() { global $current_user; $uid = $this->params['user_id']; $user = new User($uid); $user->load(); $count = Database::sql2single('SELECT COUNT(1) FROM `users_points_history` WHERE `id_user`=' . $user->id); //по книгам, по дате, по типам действий $sortings = array('time' => array('title' => 'по дате'), 'id_target' => array('title' => 'по книге'), 'id_action' => array('title' => 'по типу действий')); $dsortings = array('time' => array('title' => 'по дате', 'order' => 'desc')); $cond = new Conditions(); $cond->setPaging($count, isset($this->params['per_page']) ? (int) $this->params['per_page'] : 40); $cond->setSorting($sortings, $dsortings); $order = 'ORDER BY ' . $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL(); $limit = $cond->getLimit(); $this->data['conditions'] = $cond->getConditions(); $query = 'SELECT * FROM `users_points_history` WHERE `id_user`=' . $user->id . ' ' . $order . ' LIMIT ' . $limit; $contributions = Database::sql2array($query); $bids = array(); $aids = array(); $sids = array(); $mids = array(); $gids = array(); $uids = array($user->id); $tmp = array(); foreach (Config::$points as $name => $p) { $tmp[$p['id']] = $name; } foreach ($contributions as &$contribution) { switch ($contribution['target_type']) { case BiberLog::TargetType_book: $contribution['id_book'] = $contribution['id_target']; $bids[$contribution['id_target']] = $contribution['id_target']; break; case BiberLog::TargetType_person: $contribution['id_author'] = $contribution['id_target']; $aids[$contribution['id_target']] = $contribution['id_target']; break; case BiberLog::TargetType_magazine: $contribution['id_magazine'] = $contribution['id_target']; $mids[$contribution['id_target']] = $contribution['id_target']; break; case BiberLog::TargetType_serie: $contribution['id_serie'] = $contribution['id_target']; $sids[$contribution['id_target']] = $contribution['id_target']; break; case BiberLog::TargetType_genre: $contribution['id_genre'] = $contribution['id_target']; $gids[$contribution['id_target']] = $contribution['id_target']; break; default: throw new Exception('cant process type #' . $contribution['target_type'] . ' for contribution'); break; } $contribution['action'] = $tmp[$contribution['id_action']]; unset($contribution['id_action']); unset($contribution['id_target']); unset($contribution['target_type']); if (!$current_user->can('logs_view')) { unset($contribution['points']); } $contribution['date'] = date('Y/m/d H:i:s', $contribution['time']); unset($contribution['time']); } $this->data['contributions'] = $contributions; $aaids = array(); if (count($bids)) { list($this->data['books'], $aaids) = $this->getContributionBooks($bids); } if (count($aaids)) { foreach ($aaids as $aid) { $aids[$aid] = $aid; } } if (count($aids)) { $this->data['authors'] = $this->getContributionAuthors($aids); } if (count($mids)) { $this->data['magazines'] = $this->getContributionMagazines($mids); } if (count($sids)) { $this->data['series'] = $this->getContributionSeries($sids); } if (count($gids)) { $this->data['genres'] = $this->getContributionGenres($gids); } if (count($uids)) { $this->data['users'] = $this->getContributionUsers($uids); } }
/** * вынимаем все книги в ocr */ function getOcrListOld() { /** * paging & sorting */ $where = '`flag`=0'; $sortings = array('ocr.time' => array('title' => 'по дате добавления'), 'rating' => array('title' => 'по популярности')); $default_sortings = array('ocr.time' => array('title' => 'по дате добавления', 'order' => 'desc')); $count = (int) Database::sql2single('SELECT COUNT(1) FROM (SELECT 1 FROM `ocr` WHERE ' . $where . ' GROUP BY `id_book`) c '); $limit = false; $order = false; $sorting_order = false; $cond = new Conditions(); if ($this->ConditionsEnabled) { // пейджинг, сортировка if ($sortings || $default_sortings) { $cond->setSorting($sortings, $default_sortings); $order = $cond->getSortingField(); $sorting_order = $cond->getSortingOrderSQL(); } $per_page = isset($this->params['per_page']) ? $this->params['per_page'] : 0; $limit_parameter = isset($this->params['limit']) ? $this->params['limit'] : 0; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; if ($per_page) { $cond->setPaging($count, $per_page, $pagingName); $limit = $cond->getLimit(); } if ($limit_parameter) { $cond->setLimit($limit_parameter); $limit = $cond->getLimit(); } } $query = 'SELECT `id_book` FROM `ocr` LEFT JOIN `book` B ON B.id = `ocr`.`id_book` WHERE ' . $where . ' GROUP BY `id_book` ' . ($order ? 'ORDER BY ' . $order . ' ' . $sorting_order : '') . ' LIMIT ' . $limit . ''; // получили список книг $bids = Database::sql2array($query, 'id_book'); // получаем статусы полученных книг $query = 'SELECT * FROM `ocr` WHERE `id_book` IN(' . implode(',', array_keys($bids)) . ') ORDER BY `time` DESC'; $tasks = Database::sql2array($query); $task_book = array(); foreach ($tasks as &$task) { $task['date'] = date('Y/m/d H:i:s', $task['time']); $user_ids[$task['id_user']] = $task['id_user']; $task_book[$task['id_book']][] = $task; } $this->data = $this->_idsToData(array_keys($bids)); foreach ($this->data['books'] as &$book) { if (isset($task_book[$book['id']])) { $book['statuses'] = $task_book[$book['id']]; } } $this->data['books']['title'] = 'Книги в работе'; $this->data['books']['count'] = $count; $this->data['users'] = $this->getOcrUsers($user_ids); $this->setStatusesNode(); $this->data['conditions'] = $cond->getConditions(); }