예제 #1
0
    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;
    }
예제 #2
0
    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;
    }
예제 #3
0
 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);
     }
 }
예제 #4
0
	/**
	 * устанавливает $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;
	}
예제 #5
0
    /**
     * вынимаем все книги в 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();
    }
예제 #6
0
    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;
    }