/** * Searching articles by title. */ public function simpleAction() { $order = 'time_publish DESC'; $page = $this->params('p', 1); $module = $this->getModule(); $config = Pi::config('', $module); $limit = intval($config['page_limit_all']) ?: 40; $offset = $limit * ($page - 1); // Build where $where = array(); $keyword = $this->params('keyword', ''); if ($keyword) { $where['subject like ?'] = sprintf('%%%s%%', $keyword); } // Retrieve data $articleResultset = Entity::getAvailableArticlePage($where, $page, $limit, null, $order, $module); // Total count $where = array_merge($where, array('time_publish <= ?' => time(), 'status' => Article::FIELD_STATUS_PUBLISHED, 'active' => 1)); $modelArticle = $this->getModel('article'); $totalCount = $modelArticle->getSearchRowsCount($where); // Paginator $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array('module' => $module, 'controller' => 'search', 'action' => 'simple', 'keyword' => $keyword)))); // Prepare search form $form = new SimpleSearchForm(); $form->setData($this->params()->fromQuery()); $this->view()->assign(array('title' => __('Search result of '), 'articles' => $articleResultset, 'keyword' => $keyword, 'p' => $page, 'paginator' => $paginator, 'count' => $totalCount, 'form' => $form)); }
public function indexAction() { // Get page $page = $this->params('page', 1); $searchStatus = $this->params('searchStatus', 'open'); $searchUser = $this->params('searchUser'); $searchLabel = $this->params('searchLabel'); // Set info $ticket = array(); $where = array('mid' => 0); $order = array('time_update DESC', 'id DESC'); $offset = (int) ($page - 1) * $this->config('admin_perpage'); $limit = intval($this->config('admin_perpage')); // Check status switch ($searchStatus) { case 'open': $where['status'] = array(1, 2, 3, 4); break; case 'finish': $where['status'] = array(5); break; case 'all': // $where['status'] = array(1, 2, 3, 4, 5); break; } // Check user if ($searchUser > 0) { $where['uid'] = intval($searchUser); } // if ($searchLabel > 0) { $where['label'] = intval($searchLabel); } // Get info $select = $this->getModel('ticket')->select()->where($where)->order($order)->offset($offset)->limit($limit); $rowset = $this->getModel('ticket')->selectWith($select); // Make list foreach ($rowset as $row) { $ticket[$row->id] = Pi::api('ticket', 'support')->canonizeTicket($row); $ticket[$row->id]['user'] = Pi::user()->get($row->uid, array('id', 'identity', 'name', 'email')); $ticket[$row->id]['ticketUrl'] = Pi::url($this->url('', array('controller' => 'ticket', 'action' => 'detail', 'id' => $row->id))); } // Set paginator $count = array('count' => new Expression('count(*)')); $select = $this->getModel('ticket')->select()->columns($count)->where($where); $count = $this->getModel('ticket')->selectWith($select)->current()->count; $paginator = Paginator::factory(intval($count)); $paginator->setItemCountPerPage($this->config('admin_perpage')); $paginator->setCurrentPageNumber($page); $paginator->setUrlOptions(array('router' => $this->getEvent()->getRouter(), 'route' => $this->getEvent()->getRouteMatch()->getMatchedRouteName(), 'params' => array_filter(array('module' => $this->getModule(), 'controller' => 'index', 'action' => 'index', 'searchStatus' => $searchStatus, 'searchUser' => $searchUser, 'searchLabel' => $searchLabel)))); // Set form $values = array('searchStatus' => $searchStatus, 'searchUser' => $searchUser, 'searchLabel' => $searchLabel); $form = new SearchForm('search'); $form->setAttribute('action', $this->url('', array('action' => 'process'))); $form->setData($values); // Set view $this->view()->assign('tickets', $ticket); $this->view()->assign('paginator', $paginator); $this->view()->assign('form', $form); }
/** * Demo for article with comments */ public function indexAction() { $id = _get('id', 'int') ?: rand(1, 5); $page = _get('page', 'int') ?: 1; $paginator = Paginator::factory(100, array('limit' => 10, 'page' => $page, 'url_options' => array('params' => array('id' => $id, 'enable' => 'yes')))); $this->view()->assign(array('title' => sprintf(__('Demo article #%d'), $id), 'paginator' => $paginator)); $this->view()->setTemplate('demo'); }
/** * A test page with a couple of API demos */ public function indexAction() { $id = (int) $this->params('id', 1); $page = $this->params('p', 5); $paginator = Paginator::factory(100, array('limit' => 10, 'page' => $page, 'url_options' => array('page_param' => 'p', 'total_param' => 't', 'params' => array('id' => $id)))); $this->view()->assign('id', $id); $this->view()->assign('paginator', $paginator); }
/** * Show all tag of website. */ public function listAction() { $tag = _get('tag'); $limit = (int) $this->config('item_per_page'); $page = _get('page') ? (int) _get('page') : 1; $offset = (int) ($page - 1) * $limit; $module = _get('m'); $type = null; $moduleTitle = ''; $modules = Pi::registry('modulelist')->read(); if ($module && !isset($modules[$module])) { $module = ''; } if ($module) { $moduleTitle = $modules[$module]['title']; } $paginator = null; $list = array(); $count = Pi::service('tag')->getCount($tag, $module, $type); if ($count) { $items = Pi::service('tag')->getList($tag, $module, $type, $limit, $offset); $content = array(); $batches = array(); foreach ($items as $item) { //$key = $item['module'] . '-' . $item['type']; $batches[$item['module']][$item['type']][] = $item['item']; } $vars = array('id', 'title', 'link', 'time'); foreach ($batches as $m => $mData) { foreach ($mData as $t => $tData) { $content[$m . '-' . $t] = Pi::service('module')->content($vars, array('module' => $m, 'type' => $t, 'id' => $tData)); } } $list = array(); array_walk($items, function ($item) use($modules, $content, &$list) { $key = $item['module'] . '-' . $item['type']; if (isset($content[$key]) && isset($modules[$item['module']])) { $found = false; foreach ($content[$key] as $data) { if ($data['id'] == $item['item']) { $item['url'] = $data['link']; $item['title'] = $data['title']; $item['time'] = $data['time']; $found = true; break; } } if ($found) { $item['module'] = $modules[$item['module']]['title']; $list[] = $item; } } }); $paginator = Paginator::factory($count, array('limit' => $limit, 'page' => $page, 'url_options' => array('route' => 'tag', 'params' => array('tag' => $tag, 'm' => $module)))); } $this->view()->assign(array('paginator' => $paginator, 'list' => $list, 'tag' => $tag, 'count' => $count, 'm' => $module, 'moduleTitle' => $moduleTitle)); $this->view()->setTemplate('list'); }
/** * List notifications * * @return void */ public function indexAction() { $page = _get('p', 'int'); $page = $page ?: 1; $limit = Pi::config('list_number'); $offset = (int) ($page - 1) * $limit; //current user id $userId = Pi::user()->getUser()->id; // dismiss alert Pi::user()->message->dismissAlert($userId); $model = $this->getModel('notification'); //get notification list count /* $select = $model->select() ->columns(array( 'count' => new \Zend\Db\Sql\Predicate\Expression( 'count(*)' ) )) ->where(array('uid' => $userId, 'is_deleted' => 0)); $count = $model->selectWith($select)->current()->count; */ $count = $model->count(array('uid' => $userId, 'is_deleted' => 0)); if ($count) { //get notification list $select = $model->select()->where(array('uid' => $userId, 'is_deleted' => 0))->order('time_send DESC')->limit($limit)->offset($offset); $rowset = $model->selectWith($select); $notificationList = $rowset->toArray(); //jump to last page if (empty($notificationList) && $page > 1) { $this->redirect()->toRoute('', array('controller' => 'notify', 'action' => 'index', 'p' => ceil($count / $limit))); return; } array_walk($notificationList, function (&$v, $k) { //markup content $v['content'] = Pi::service('markup')->render($v['content'], 'text', false, array('newline' => false)); }); $paginator = Paginator::factory(intval($count), array('page' => $page, 'limit' => $limit, 'url_options' => array('page_param' => 'p', 'params' => array('module' => $this->getModule(), 'controller' => 'notify', 'action' => 'index')))); $this->view()->assign('paginator', $paginator); } else { $notificationList = array(); } $this->renderNav(); $this->view()->assign('notifications', $notificationList); return; }
/** * List pages */ public function indexAction() { $page = $this->params('p', 5); $flag = $this->params('f', 0); $limit = $this->config('item_per_page') ?: 10; $offset = (int) ($page - 1) * $limit; $model = $this->getModel('page'); $select = $model->select()->where(array('flag' => $flag))->limit($limit)->offset($offset)->order('time_created DESC'); $rowset = $model->selectWith($select); $pages = array(); foreach ($rowset as $row) { $pages[] = array('title' => $row['title'], 'time' => $row['time_created'], 'url' => $this->url('', array('action' => 'view', 'id' => $row['id']))); } $count = $model->count(array('flag' => $flag)); $paginator = Paginator::factory($count, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'total_param' => 't', 'params' => array('f' => $flag)))); $this->view()->assign(array('paginator' => $paginator, 'pages' => $pages)); $this->view()->setTemplate('page-list'); }
/** * Demo for lean usage of pagination with NullApapter */ public function simpleAction() { $page = $this->params('p', 5); $flag = $this->params('f', 0); $limit = (int) $this->config('item_per_page'); $model = $this->getModel('page'); $offset = (int) ($page - 1) * $this->config('item_per_page'); $select = $model->select()->where(array('flag' => $flag))->order('id')->offset($offset)->limit($limit); $rowset = $model->selectWith($select); $items = array(); foreach ($rowset as $row) { $items[] = $row; } //$data = $rowset->toArray(); /* $select = $model->select() ->columns(array('count' => new Expression('count(*)'))) ->where(array('flag' => $flag)); */ $count = $model->count(array('flag' => $flag)); /* $paginator = Paginator::factory(intval($count)); $paginator->setItemCountPerPage($limit); $paginator->setCurrentPageNumber($page); $paginator->setUrlOptions(array( // Use router to build URL for each page 'page_param' => 'p', 'total_param' => 't', 'params' => array( 'f' => $flag, ), // Or use a URL template to create URLs //'template' => '/url/p/__page__/t/__total__', 'template' => Pi::service('url')->assemble('', array( 'p' => '__page__', 't' => '__total__', 'f' => $flag, ), true), )); */ $paginator = Paginator::factory(intval($count), array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'total_param' => 't', 'params' => array('f' => $flag)))); $this->view()->assign('items', $items); $this->view()->assign('paginator', $paginator); }
/** * Application list page * * @return ViewModel */ public function listAction() { $page = $this->params('p', 1); $name = $this->params('name', ''); $limit = $this->config('page_limit') > 0 ? $this->config('page_limit') : 20; $offset = $limit * ($page - 1); $where = array(); if ($name) { $where['title like ?'] = "%{$name}%"; } $module = $this->getModule(); $model = $this->getModel('application'); $select = $model->select()->order('id ASC')->offset($offset)->limit($limit); $resultset = $model->selectWith($select)->toArray(); // Total count $totalCount = $model->count($where); // Paginator $paginator = Paginator::factory($totalCount, array('page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array_filter(array('module' => $module, 'controller' => 'application', 'action' => 'list', 'name' => $name))))); $this->view()->assign(array('title' => _a('Application List'), 'apps' => $resultset, 'paginator' => $paginator)); }
/** * List of audit logs * * @return void */ public function indexAction() { $limit = (int) $this->params('count', 20); $page = $this->params('p', 1); $model = Pi::model('audit'); $offset = (int) ($page - 1) * $limit; $select = $model->select()->where(array())->order('id DESC')->offset($offset)->limit($limit); $rowset = $model->selectWith($select); /* $select = $model->select() ->columns(array('count' => new Expression('count(*)'))); $count = (int) $model->selectWith($select)->current()->count; */ $count = $model->count(); $paginator = Paginator::factory($count, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array('count' => $limit)))); $this->view()->assign('count', $limit); $this->view()->assign('items', $rowset->toArray()); $this->view()->assign('paginator', $paginator); //$this->view()->setTemplate('audit-list'); }
public function indexAction() { // Check user is login or not Pi::service('authentication')->requireLogin(); // Get user info $uid = Pi::user()->getId(); $user = Pi::user()->get($uid, array('id', 'identity', 'name', 'email')); $user['avatar'] = Pi::service('user')->avatar($user['id'], 'medium', $user['name']); $user['profileUrl'] = Pi::url(Pi::service('user')->getUrl('profile', array('id' => $user['id']))); $user['accountUrl'] = Pi::url(Pi::service('user')->getUrl('user', array('controller' => 'account'))); // Get page $page = $this->params('page', 1); // Set info $ticket = array(); $where = array('mid' => 0, 'uid' => $uid); $order = array('time_update DESC', 'id DESC'); $offset = (int) ($page - 1) * $this->config('view_perpage'); $limit = intval($this->config('view_perpage')); // Get info $select = $this->getModel('ticket')->select()->where($where)->order($order)->offset($offset)->limit($limit); $rowset = $this->getModel('ticket')->selectWith($select); // Make list foreach ($rowset as $row) { $ticket[$row->id] = Pi::api('ticket', 'support')->canonizeTicket($row); } // Set paginator $count = array('count' => new Expression('count(*)')); $select = $this->getModel('ticket')->select()->columns($count)->where($where); $count = $this->getModel('ticket')->selectWith($select)->current()->count; $paginator = Paginator::factory(intval($count)); $paginator->setItemCountPerPage($this->config('view_perpage')); $paginator->setCurrentPageNumber($page); $paginator->setUrlOptions(array('router' => $this->getEvent()->getRouter(), 'route' => $this->getEvent()->getRouteMatch()->getMatchedRouteName(), 'params' => array_filter(array('module' => $this->getModule(), 'controller' => 'index', 'action' => 'index')))); // Set submit link $submit = Pi::url($this->url('', array('controller' => 'ticket', 'action' => 'index'))); // Set view $this->view()->assign('tickets', $ticket); $this->view()->assign('paginator', $paginator); $this->view()->assign('user', $user); $this->view()->assign('submit', $submit); }
/** * Processing media list */ public function listAction() { $params = $where = array(); $type = $this->params('type', 'image'); $keyword = $this->params('keyword', ''); $style = 'default'; if ('image' == $type) { $style = $this->params('style', 'normal'); $params['style'] = $style; } $where['type'] = $this->getExtension($type); $types = array(); foreach ($where['type'] as $item) { $types[$item] = $item; } $miniType = $this->params('mini_type', ''); if (!empty($miniType)) { $where['type'] = $miniType; $params['mini_type'] = $miniType; } if (!empty($keyword)) { $where['title like ?'] = '%' . $keyword . '%'; $params['keyword'] = $keyword; } $model = $this->getModel('media'); $page = $this->params('p', 1); $page = $page > 0 ? $page : 1; $module = $this->getModule(); $config = Pi::config('', $module); $limit = (int) $config['page_limit_all'] ?: 40; $resultSet = Media::getList($where, $page, $limit, null, null, $module); // Total count $count = $model->count($where); // Pagination $paginator = Paginator::factory($count, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array_merge(array('module' => $this->getModule(), 'controller' => 'media', 'action' => 'list', 'type' => $type, 'style' => $style), $params)))); // Getting search form $form = new SimpleSearchForm(); $this->view()->assign(array('title' => _a('All Media'), 'medias' => $resultSet, 'paginator' => $paginator, 'type' => $type, 'keyword' => $keyword, 'types' => $types, 'form' => $form, 'count' => $count, 'miniType' => $miniType, 'style' => $style)); }
/** * Process article list related with tag * * @return ViewModel */ public function listAction() { $tag = $this->params('tag', ''); $page = $this->params('p', 1); $page = $page > 0 ? $page : 1; $where = $articleIds = $articles = array(); if (empty($tag)) { return $this->jumpTo404(__('Cannot find this page')); } $module = $this->getModule(); $config = Pi::config('', $module); $limit = $config['page_limit_all'] ?: 40; $offset = ($page - 1) * $limit; // Total count $totalCount = (int) Pi::service('tag')->getCount($tag, $module); // Get article ids $articleTags = Pi::service('tag')->getList($tag, $module, '', $limit, $offset); foreach ($articleTags as $row) { $articleIds[] = $row['item']; } if ($articleIds) { $where['id'] = $articleIds; $articles = array_flip($articleIds); $columns = array('id', 'subject', 'time_publish', 'category'); $resultsetArticle = Entity::getAvailableArticlePage($where, 1, $limit, $columns, '', $module); foreach ($resultsetArticle as $key => $val) { $articles[$key] = $val; } $articles = array_filter($articles, function ($var) { return is_array($var); }); } // Pagination $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array('tag' => $tag)))); $this->view()->assign(array('title' => __('Articles on Tag '), 'articles' => $articles, 'paginator' => $paginator, 'p' => $page, 'tag' => $tag, 'config' => $config, 'count' => $totalCount)); $this->view()->viewModel()->getRoot()->setVariables(array('breadCrumbs' => true, 'Tag' => $tag)); }
/** * List all published article for management * * @return ViewModel */ public function publishedAction() { // Denied user viewing if no front-end management permission assigned if (!$this->config('enable_front_edit') && 'front' == $this->section) { return $this->jumpTo404(); } $page = $this->params('p', 1); $limit = $this->params('limit', 20); $from = $this->params('from', 'my'); $keyword = $this->params('keyword', ''); $category = $this->params('category', 0); $filter = $this->params('filter', ''); $order = 'time_publish DESC'; $where = array(); // Get permission $rules = Rule::getPermission(); if (empty($rules)) { return $this->jumpToDenied(); } $categories = array(); foreach (array_keys($rules) as $key) { $categories[$key] = true; } $where['category'] = array_keys($categories); // Select article of mine if ('my' == $from) { $where['uid'] = Pi::user()->getId() ?: 0; } $module = $this->getModule(); $modelArticle = $this->getModel('article'); $categoryModel = $this->getModel('category'); if (!empty($category) and !in_array($category, $where['category'])) { return $this->jumpToDenied(); } if ($category > 1) { $categoryIds = $categoryModel->getDescendantIds($category); if ($categoryIds) { $where['category'] = $categoryIds; } } // Build where $where['status'] = Article::FIELD_STATUS_PUBLISHED; if (!empty($keyword)) { $where['subject like ?'] = sprintf('%%%s%%', $keyword); } $where = array_filter($where); // The where must be added after array_filter function if ($filter == 'active') { $where['active'] = 1; } else { if ($filter == 'deactive') { $where['active'] = 0; } } // Retrieve data $data = Entity::getArticlePage($where, $page, $limit, null, $order); // Total count $totalCount = $modelArticle->count($where); // Paginator /* $paginator = Paginator::factory($totalCount); $paginator->setItemCountPerPage($limit) ->setCurrentPageNumber($page) ->setUrlOptions(array( 'page_param' => 'p', 'router' => $this->getEvent()->getRouter(), 'route' => $this->getEvent() ->getRouteMatch() ->getMatchedRouteName(), 'params' => array_filter(array( 'module' => $module, 'controller' => 'article', 'action' => 'published', 'category' => $category, 'filter' => $filter, 'keyword' => $keyword, )), )); */ $params = array(); foreach (array('category', 'filter', 'keyword', 'from') as $key) { if (${$key}) { $params[$key] = ${$key}; } } $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => $params))); // Prepare search form $form = new SimpleSearchForm(); $form->setData($this->params()->fromQuery()); $flags = array('draft' => DraftModel::FIELD_STATUS_DRAFT, 'pending' => DraftModel::FIELD_STATUS_PENDING, 'rejected' => DraftModel::FIELD_STATUS_REJECTED, 'published' => Article::FIELD_STATUS_PUBLISHED); $cacheCategories = Pi::api('api', $module)->getCategoryList(); $this->view()->assign(array('title' => __('Published'), 'data' => $data, 'form' => $form, 'paginator' => $paginator, 'summary' => Entity::getSummary($from, $rules), 'category' => $category, 'filter' => $filter, 'categories' => array_intersect_key($cacheCategories, $categories), 'action' => 'published', 'flags' => $flags, 'status' => Article::FIELD_STATUS_PUBLISHED, 'from' => $from, 'rules' => $rules)); if ('my' == $from) { $this->view()->setTemplate('draft-list', $module, 'front'); } else { $this->view()->setTemplate('article-published', $module, 'front'); } }
/** * List recent tagged contents */ public function linkAction() { $page = $this->params('page', 1); $module = $this->params('m'); $limit = (int) $this->config('item_per_page'); $offset = (int) ($page - 1) * $limit; $modules = $this->getModules(); $count = Pi::service('tag')->getCount('', $module, null); $list = Pi::service('tag')->getList('', $module, null, $limit, $offset); array_walk($list, function (&$tag) use($module) { $tag['url'] = Pi::service('tag')->url($tag['term'], $module ?: ''); }); $content = array(); $batches = array(); foreach ($list as $item) { $batches[$item['module']][$item['type']][$item['item']][] = $item['term']; } $vars = array('id', 'title', 'link', 'time'); foreach ($batches as $m => $mData) { foreach ($mData as $t => $tData) { $content[$m . '-' . $t] = Pi::service('module')->content($vars, array('module' => $m, 'type' => $t, 'id' => array_keys($tData))); } } $links = array(); array_walk($list, function ($item) use($modules, $content, &$links) { $key = $item['module'] . '-' . $item['type']; if (isset($content[$key]) && isset($modules[$item['module']])) { $found = false; foreach ($content[$key] as $data) { if ($data['id'] == $item['item']) { $item['item'] = $data; $found = true; break; } } if ($found) { $item['module'] = $modules[$item['module']]; $links[] = $item; } } }); $paginator = Paginator::factory($count, array('limit' => $limit, 'page' => $page, 'url_options' => array('params' => array('m' => $module)))); $this->view()->assign(array('paginator' => $paginator, 'modules' => $modules, 'm' => $module, 'links' => $links)); $this->view()->setTemplate('link'); }
/** * Get articles by condition * * @param int $status Draft status flag * @param string $from Show all articles or my articles * @param array $options Where condition */ public function showDraftPage($status, $from = 'my', $options = array()) { $where = $options; $page = $this->params('p', 1); $limit = $this->params('limit', 20); $where['status'] = $status; $where['article < ?'] = 1; if ('my' == $from) { $where['uid'] = Pi::user()->getId(); } if (isset($options['keyword'])) { $where['subject like ?'] = sprintf('%%%s%%', $options['keyword']); } $module = $this->getModule(); $modelDraft = $this->getModel('draft'); $resultsetDraft = Draft::getDraftPage($where, $page, $limit); // Total count $totalCount = (int) $modelDraft->getSearchRowsCount($where); $action = $this->getEvent()->getRouteMatch()->getParam('action'); // Paginator $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array('module' => $module, 'controller' => 'draft', 'action' => $action, 'status' => $status, 'from' => $from, 'where' => urlencode(json_encode($options)), 'limit' => $limit)))); $this->view()->assign(array('data' => $resultsetDraft, 'paginator' => $paginator, 'status' => $status, 'from' => $from, 'page' => $page, 'limit' => $limit)); }
/** * List media by user * * @return ViewModel */ public function userAction() { // Get user ID $user = $this->params('user', null); if (is_numeric($user)) { $userModel = Pi::service('user')->getUser($user); } elseif ($user) { $userModel = Pi::service('user')->getUser($user, 'identity'); } else { $userModel = ''; } $uid = $userModel ? $userModel->get('id') : 0; $active = $this->params('status', null); if ($active !== null) { $active = (int) $active; } $page = (int) $this->params('p', 1); $limit = (int) $this->config('page_limit') > 0 ? $this->config('page_limit') : 20; $offset = ($page - 1) * $limit; $where = array('uid' => $uid); $params = array('user' => $user); if (1 === $active) { $where['active'] = 1; $params['status'] = 1; } elseif (0 === $active) { $where['active'] = 0; $params['status'] = 1; } $delete = $this->params('delete', 0); if ($delete) { $where['time_deleted > ?'] = 0; } else { $where['time_deleted'] = 0; } $params['delete'] = $delete; // Get media list $module = $this->getModule(); $resultset = Pi::api('doc', $module)->getList($where, $limit, $offset, 'time_created'); $apps = $appkeys = array(); foreach ($resultset as $row) { $appkeys[] = $row['appkey']; } // Get application title if (!empty($appkeys)) { $apps = $this->getAppTitle($appkeys); } // Get users $users = Pi::user()->get($uid); $avatars = Pi::avatar()->get($uid); // Total count $totalCount = $this->getModel('doc')->count($where); // Paginator /* $paginator = Paginator::factory($totalCount); $paginator->setItemCountPerPage($limit) ->setCurrentPageNumber($page) ->setUrlOptions(array( 'page_param' => 'p', 'router' => $this->getEvent()->getRouter(), 'route' => $this->getEvent() ->getRouteMatch() ->getMatchedRouteName(), 'params' => array_filter(array_merge(array( 'controller' => 'list', 'action' => 'user', ), $params)), )); */ $paginator = Paginator::factory($totalCount, array('page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array_filter(array_merge(array('controller' => 'list', 'action' => 'user'), $params))))); $navTabs = array(array('active' => null === $active && !$delete, 'label' => _a('All resources'), 'href' => $this->url('', array('action' => 'user', 'user' => $user))), array('active' => 1 === $active && !$delete, 'label' => _a('Active resources'), 'href' => $this->url('', array('action' => 'user', 'user' => $user, 'status' => 1))), array('active' => 0 === $active && !$delete, 'label' => _a('Inactive resources'), 'href' => $this->url('', array('action' => 'user', 'user' => $user, 'status' => 0))), array('active' => $delete, 'label' => _a('Deleted resources'), 'href' => $this->url('', array('action' => 'user', 'user' => $user, 'delete' => 1)))); $url = $this->url('', array('action' => 'user')); $this->view()->assign(array('title' => _a('Resource List By User'), 'apps' => $apps, 'medias' => $resultset, 'paginator' => $paginator, 'tabs' => $navTabs, 'users' => $users, 'avatars' => $avatars, 'active' => $active, 'delete' => $delete, 'user' => $user, 'url' => $url)); }
/** * All posts commented on me */ public function receivedAction() { /* $active = _get('active'); if (null !== $active) { $active = 1; } */ $my = _get('my', 'int'); $uid = _get('uid', 'int'); $active = _get('active'); $page = _get('page', 'int') ?: 1; $limit = $this->config('list_limit') ?: 10; $offset = ($page - 1) * $limit; if (!$my && $uid) { $active = 1; } else { Pi::service('authentication')->requireLogin(); $my = 1; $uid = Pi::user()->getId(); if (null !== $active) { $active = (int) $active; } } $where = array('author' => $uid, 'active' => $active); $posts = Pi::api('api', 'comment')->getList($where, $limit, $offset); $options = array('user' => array('avatar' => 'medium')); $posts = Pi::api('api', 'comment')->renderList($posts, $options); $count = Pi::api('api', 'comment')->getCount($where); if ($my) { $params = array('my' => 1, 'active' => $active); } else { $params = array('uid' => $uid); } $paginator = Paginator::factory($count, array('page' => $page, 'limit' => $limit, 'url_options' => array('params' => $params))); if ($my) { $title = __('Received comments'); $user = null; $template = 'comment-my-received'; $navTabs = array(array('active' => null === $active, 'label' => __('All Posts'), 'href' => $this->url('', array('action' => 'received', 'my' => 1))), array('active' => 1 == $active, 'label' => __('Active Posts'), 'href' => $this->url('', array('action' => 'received', 'my' => 1, 'active' => 1))), array('active' => 0 === $active, 'label' => __('Inactive Posts'), 'href' => $this->url('', array('action' => 'received', 'my' => 1, 'active' => 0)))); $this->view()->assign(array('tabs' => $navTabs)); } else { $user = Pi::service('user')->get($uid, array('name')); $user['avatar'] = Pi::service('avatar')->get($uid, 'medium'); $user['url'] = Pi::service('user')->getUrl('profile', $uid); $title = __('Comment posts on user'); $template = 'comment-user-received'; } $this->view()->assign('comment', array('title' => $title, 'count' => $count, 'posts' => $posts, 'paginator' => $paginator, 'user' => $user)); $this->view()->setTemplate($template); }
/** * List private messages * * @return void */ public function indexAction() { $page = _get('p', 'int'); $page = $page ?: 1; $limit = Pi::config('list_number'); $offset = (int) ($page - 1) * $limit; //current user id Pi::service('authentication')->requireLogin(); $userId = Pi::user()->getId(); // dismiss alert Pi::user()->message->dismissAlert($userId); $model = $this->getModel('message'); //get private message list count $select = $model->select()->columns(array('count' => new \Zend\Db\Sql\Predicate\Expression('count(*)')))->where(function ($where) use($userId) { $fromWhere = clone $where; $toWhere = clone $where; $fromWhere->equalTo('uid_from', $userId); $fromWhere->equalTo('is_deleted_from', 0); $toWhere->equalTo('uid_to', $userId); $toWhere->equalTo('is_deleted_to', 0); $where->andPredicate($fromWhere)->orPredicate($toWhere); }); $count = $model->selectWith($select)->current()->count; if ($count) { //get private message list group by user $select = $model->select()->where(function ($where) use($userId) { $fromWhere = clone $where; $toWhere = clone $where; $fromWhere->equalTo('uid_from', $userId); $fromWhere->equalTo('is_deleted_from', 0); $toWhere->equalTo('uid_to', $userId); $toWhere->equalTo('is_deleted_to', 0); $where->andPredicate($fromWhere)->orPredicate($toWhere); })->order('time_send DESC')->limit($limit)->offset($offset); $rowset = $model->selectWith($select); $messageList = $rowset->toArray(); //jump to last page if (empty($messageList) && $page > 1) { $this->redirect()->toRoute('', array('controller' => 'index', 'action' => 'index', 'p' => ceil($count / $limit))); return; } array_walk($messageList, function (&$v, $k) use($userId) { //format messages // $v['content'] = Service::messageSummary($v['content']); // markup content $v['content'] = Pi::service('markup')->render($v['content'], 'text', false, array('newline' => false)); if ($userId == $v['uid_from']) { $v['is_read'] = 1; $user = Pi::user()->getUser($v['uid_to']) ?: Pi::user()->getUser(0); // get username url $v['name'] = $user->name; // username link, 4 locations $v['profileUrl'] = Pi::user()->getUrl('profile', $v['uid_to']); //get avatar $v['avatar'] = Pi::user()->avatar($v['uid_to'], 'small'); } else { $v['is_read'] = $v['is_read_to']; $user = Pi::user()->getUser($v['uid_from']) ?: Pi::user()->getUser(0); //get username url $v['name'] = $user->name; $v['profileUrl'] = Pi::user()->getUrl('profile', $v['uid_from']); //get avatar $v['avatar'] = Pi::user()->avatar($v['uid_from'], 'small'); } unset($v['is_read_from'], $v['is_read_to'], $v['delete_status_from'], $v['delete_status_to']); }); $paginator = Paginator::factory(intval($count), array('page' => $page, 'limit' => $limit, 'url_options' => array('page_param' => 'p', 'params' => array('module' => $this->getModule(), 'controller' => 'index', 'action' => 'index')))); $this->view()->assign('paginator', $paginator); $this->view()->assign('uid', $userId); } else { $messageList = array(); } $this->renderNav(); $this->view()->assign('messages', $messageList); return; }
/** * Listing all articles for users to review */ public function allAction() { $page = $this->params('p', 1); $sort = $this->params('sort', 'new'); $params = array('sort' => $sort); $where = array('status' => Article::FIELD_STATUS_PUBLISHED, 'active' => 1, 'time_publish < ?' => time()); $category = $this->params('category', 0); $params['category'] = $category; if (!empty($category) && 'all' != $category) { $modelCategory = $this->getModel('category'); if (!is_numeric($category)) { $category = $modelCategory->slugToId($category); } $children = $modelCategory->getDescendantIds($category); if (empty($children)) { return $this->jumpTo404(__('Invalid category id')); } $where['category'] = $children; } //@todo Get limit from module config $limit = (int) $this->config('page_limit_all'); $limit = $limit ?: 40; $offset = $limit * ($page - 1); $model = $this->getModel('article'); $select = $model->select()->where($where); if ('hot' == $sort) { $modelStats = $this->getModel('stats'); $select->join(array('st' => $modelStats->getTable()), sprintf('%s.id = st.article', $model->getTable()), array()); $order = 'st.visits DESC'; } else { $order = 'time_update DESC, time_publish DESC'; } $select->order($order)->offset($offset)->limit($limit); $module = $this->getModule(); $route = Pi::api('api', $module)->getRouteName(); $resultset = $model->selectWith($select); $items = array(); $categoryIds = $authorIds = array(); foreach ($resultset as $row) { $items[$row->id] = $row->toArray(); $publishTime = date('Ymd', $row->time_publish); $items[$row->id]['url'] = $this->url($route, array('id' => $row->id, 'time' => $publishTime)); $authorIds[] = $row->author; $categoryIds[] = $row->category; } // Get author $authors = array(); if (!empty($authorIds)) { $rowAuthor = $this->getModel('author')->select(array('id' => $authorIds)); foreach ($rowAuthor as $row) { $authors[$row->id] = $row->toArray(); } } // Total count $select = $model->select()->where($where)->columns(array('total' => new Expression('count(id)'))); $articleCountResultset = $model->selectWith($select); $totalCount = intval($articleCountResultset->current()->total); // Paginator $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array_merge(array('module' => $this->getModule(), 'controller' => 'list', 'action' => 'all'), $params)))); $config = Pi::config('', $module); // Get category nav $rowset = $this->getModel('category')->enumerate(null, null); $rowset = array_shift($rowset); $navs = $this->canonizeCategory($rowset['child'], $route); $categoryTitle = $this->getCategoryTitle($category, $rowset['child']); $allNav['all'] = array('label' => __('All'), 'route' => $route, 'controller' => 'list', 'params' => array('category' => 'all')); $navs = $allNav + $navs; // Get all categories $categories = array('all' => array('id' => 0, 'title' => __('All articles'), 'image' => '', 'url' => Pi::service('url')->assemble(Pi::api('api', $module)->getRouteName($module), array('list' => 'all')))); $rowset = $this->getModel('category')->enumerate(null, null, true); foreach ($rowset as $row) { if ('root' == $row['name']) { continue; } $url = Pi::service('url')->assemble('', array('controller' => 'category', 'action' => 'list', 'category' => $row['id'])); $categories[$row['id']] = array('id' => $row['id'], 'title' => $row['title'], 'image' => $row['image'], 'url' => $url); } $urlHot = $this->url($route, array('category' => $category, 'sort' => 'hot')); $urlNew = $this->url($route, array('category' => $category)); $title = $categoryTitle ?: __('All Articles'); $this->view()->assign(array('title' => $title, 'articles' => $items, 'paginator' => $paginator, 'elements' => $config['list_item'], 'authors' => $authors, 'categories' => $categories, 'length' => $config['list_summary_length'], 'navs' => $this->config('enable_list_nav') ? $navs : '', 'category' => $category, 'url' => array('hot' => $urlHot, 'new' => $urlNew))); }
/** * All commented articles */ public function articleAction() { $active = _get('active', 1); $active = $active ? 1 : null; $page = _get('page', 'int') ?: 1; $limit = $this->config('list_limit') ?: 10; $offset = ($page - 1) * $limit; $targets = Pi::api('api', 'comment')->getTargetList(array('active' => $active), $limit, $offset); $uids = array(); foreach ($targets as $root => $target) { $uids[] = $target['uid']; $uids[] = $target['comment_uid']; } if ($uids) { $uids = array_unique($uids); $users = Pi::service('user')->mget($uids, array('name')); $avatars = Pi::service('avatar')->getList($uids, 'small'); array_walk($users, function (&$data, $uid) use($avatars) { $data['url'] = Pi::service('user')->getUrl('profile', $uid); $data['avatar'] = $avatars[$uid]; }); } $users[0] = array('avatar' => Pi::service('avatar')->get(0, 'small'), 'url' => Pi::url('www'), 'name' => _a('Guest')); array_walk($targets, function (&$data, $root) use($users) { $data['user'] = isset($users[$data['uid']]) ? $users[$data['uid']] : $users[0]; $data['comment_user'] = isset($users[$data['comment_uid']]) ? $users[$data['comment_uid']] : $users[0]; $data['comment_url'] = Pi::api('api', 'comment')->getUrl('root', array('root' => $root)); }); //d($targets); $count = Pi::api('api', 'comment')->getTargetCount(array('active' => $active)); if ($targets) { $roots = array_keys($targets); $model = $this->getModel('post'); $select = $model->select()->where(array('root' => $roots ?: array()))->columns(array('root', 'count' => new Expression('count(*)')))->group(array('root')); $rowset = $model->selectWith($select); foreach ($rowset as $row) { $targets[$row->root]['count'] = $row->count; } } $params = null === $active ? array() : array('active' => $active); $paginator = Paginator::factory($count, array('page' => $page, 'limit' => $limit, 'url_options' => array('params' => $params))); if (null === $active) { $title = _a('All commented articles'); } else { $title = _a('All active commented articles'); } $this->view()->assign('comment', array('title' => $title, 'count' => $count, 'targets' => $targets, 'paginator' => $paginator)); /* $navTabs = array( array( 'active' => null === $active, 'label' => _a('Articles with comments'), 'href' => $this->url('', array( 'action' => 'article', )) ), array( 'active' => 1 == $active, 'label' => _a('Articles with active comments'), 'href' => $this->url('', array( 'action' => 'article', 'active' => 1, )) ), ); $this->view()->assign(array( 'tabs' => $navTabs, )); */ $this->view()->setTemplate('comment-article', '', 'front'); }
/** * Set paginator * * @param $option * @return \Pi\Paginator\Paginator */ protected function setPaginator($option) { $params = array('module' => $this->getModule(), 'controller' => $option['controller'], 'action' => $option['action']); if (isset($option['uid'])) { $params['uid'] = $option['uid']; } $paginator = Paginator::factory(intval($option['count']), array('limit' => $option['limit'], 'page' => $option['page'], 'url_options' => array('params' => $params))); return $paginator; }
/** * list articles of a topic for users to view */ public function listAction() { $topic = $this->params('topic', ''); if (empty($topic)) { return $this->jumpTo404(__('Invalid topic ID!')); } if (is_numeric($topic)) { $row = $this->getModel('topic')->find($topic); } else { $row = $this->getModel('topic')->find($topic, 'slug'); } $title = $row->title; // Return 503 code if topic is not active if (!$row->active) { return $this->jumpToException(__('The topic requested is not active'), 503); } $this->view()->assign('topic', $row->toArray()); $topicId = $row->id; $page = $this->params('p', 1); $page = $page > 0 ? $page : 1; $module = $this->getModule(); $config = Pi::config('', $module); $limit = (int) $config['page_limit_all']; // Getting relations $modelRelation = $this->getModel('article_topic'); $rowRelation = $modelRelation->select(array('topic' => $topicId)); $articleIds = array(0); $lastAdded = 0; foreach ($rowRelation as $row) { $articleIds[] = $row['article']; if ($row['time'] > $lastAdded) { $lastAdded = $row['time']; } } $where = array('id' => $articleIds); // Get articles $resultsetArticle = Entity::getAvailableArticlePage($where, $page, $limit); // Total count $where = array_merge($where, array('time_publish <= ?' => time(), 'status' => Article::FIELD_STATUS_PUBLISHED, 'active' => 1)); $modelArticle = $this->getModel('article'); $totalCount = $modelArticle->getSearchRowsCount($where); // Pagination $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array('topic' => $topic, 'list' => 'all')))); $this->view()->assign(array('title' => empty($topic) ? __('All') : $title, 'articles' => $resultsetArticle, 'paginator' => $paginator, 'lastAdded' => $lastAdded, 'count' => $totalCount)); }
/** * List articles of a category */ public function listAction() { $modelCategory = $this->getModel('category'); $category = $this->params('category', ''); $categoryId = is_numeric($category) ? (int) $category : $modelCategory->slugToId($category); $page = $this->params('p', 1); $page = $page > 0 ? $page : 1; $module = $this->getModule(); $config = Pi::config('', $module); $limit = (int) $config['page_limit_all'] ?: 40; $where = array(); $route = Pi::api('api', $module)->getRouteName(); // Get category nav $rowset = Pi::model('category', $module)->enumerate(null, null); $rowset = array_shift($rowset); $navs = $this->canonizeCategory($rowset['child'], $route); $allNav['all'] = array('label' => __('All'), 'route' => $route, 'controller' => 'list', 'params' => array('category' => 'all')); $navs = $allNav + $navs; // Get all categories $categories = array('all' => array('id' => 0, 'title' => __('All articles'), 'image' => '', 'url' => Pi::service('url')->assemble(Pi::api('api', $module)->getRouteName($module), array('controller' => 'list', 'action' => 'all', 'list' => 'all')))); $rowset = Pi::model('category', $module)->enumerate(null, null, true); foreach ($rowset as $row) { if ('root' == $row['name']) { continue; } $url = Pi::service('url')->assemble('', array('controller' => 'category', 'action' => 'list', 'category' => $row['id'])); $categories[$row['id']] = array('id' => $row['id'], 'title' => $row['title'], 'image' => $row['image'], 'url' => $url); } $categoryIds = $modelCategory->getDescendantIds($categoryId); if (empty($categoryIds)) { return $this->jumpTo404(__('Invalid category id')); } $where['category'] = $categoryIds; $categoryInfo = $categories[$categoryId]; // Get subcategories article count $modelArticle = $this->getModel('article'); $select = $modelArticle->select()->where(array('category' => $categoryIds, 'active' => 1, 'time_publish < ?' => time()))->columns(array('category', 'count' => new Expression('count(*)')))->group(array('category')); $resultCount = $modelArticle->selectWith($select); $counts = array(); foreach ($resultCount as $row) { $counts[$row['category']] = $row['count']; } // Get articles $columns = array('id', 'subject', 'time_publish', 'category', 'summary', 'author', 'image'); $resultsetArticle = Entity::getAvailableArticlePage($where, $page, $limit, $columns, null, $module); $articleCategoryIds = $authorIds = array(); foreach ($resultsetArticle as $row) { $authorIds[] = $row['author']; $articleCategoryIds[] = $row['category']; } // Get author $authors = array(); if (!empty($authorIds)) { $rowAuthor = $this->getModel('author')->select(array('id' => $authorIds)); foreach ($rowAuthor as $row) { $authors[$row->id] = $row->toArray(); } } // Total count $where = array_merge($where, array('time_publish <= ?' => time(), 'status' => Article::FIELD_STATUS_PUBLISHED, 'active' => 1)); $modelArticle = $this->getModel('article'); $totalCount = $modelArticle->getSearchRowsCount($where); // Pagination $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array('category' => $category)))); $module = $this->getModule(); $config = Pi::config('', $module); $this->view()->assign(array('title' => __('Article List in Category'), 'articles' => $resultsetArticle, 'paginator' => $paginator, 'categories' => $categories, 'categoryInfo' => $categoryInfo, 'category' => $category, 'p' => $page, 'config' => $config, 'counts' => $counts, 'categoryId' => array_shift($categoryIds), 'subCategoryId' => $categoryIds, 'route' => $route, 'elements' => $config['list_item'], 'authors' => $authors, 'length' => $config['list_summary_length'], 'navs' => $this->config('enable_list_nav') ? $navs : '')); $this->view()->viewModel()->getRoot()->setVariables(array('breadCrumbs' => true, 'Tag' => $categoryInfo['title'])); }
/** * List all added topic for management */ public function listTopicAction() { $module = $this->getModule(); $config = Pi::config('', $module); $limit = (int) $config['page_limit_management'] ?: 20; $page = $this->params('p', 1); $page = $page > 0 ? $page : 1; $offset = ($page - 1) * $limit; // Fetch topics $model = $this->getModel('topic'); $select = $model->select()->offset($offset)->limit($limit); $rowset = $model->selectWith($select)->toArray(); $topicIds = array(0); foreach ($rowset as $row) { $topicIds[] = $row['id']; } // Fetch topic article count $modelCount = $this->getModel('article_topic'); $select = $modelCount->select()->where(array('topic' => $topicIds))->columns(array('topic', 'count' => new Expression('count(*)')))->group(array('topic')); $rowCount = $modelCount->selectWith($select); $count = array(); foreach ($rowCount as $row) { $count[$row->topic] = $row->count; } // Get total topic count $select = $model->select()->columns(array('count' => new Expression('count(*)'))); $totalCount = (int) $model->selectWith($select)->current()->count; $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array('module' => $module, 'controller' => 'topic', 'action' => 'list-topic')))); $this->view()->assign(array('title' => _a('Topic List'), 'topics' => $rowset, 'action' => 'list-topic', 'route' => Pi::api('api', $module)->getRouteName(), 'count' => $count, 'paginator' => $paginator)); }
/** * Perform module search * * @param string $module * * @return void */ protected function searchModule($module = '') { $query = $this->params('q'); $page = $this->params('page') ?: 1; $module = $module ?: $this->params('m'); $modules = $this->getModules($query); if (!isset($modules[$module])) { $this->redirect()->toRoute('search', array('q' => $query)); return; } if ($query) { $result = array(); $terms = array(); $total = 0; $limit = 0; $flood = false; if (!$this->checkFlood()) { $flood = true; } else { $terms = $this->parseQuery($query); } if ($terms) { $limit = $this->config('list_limit'); $offset = $limit * ($page - 1); $result = $this->query($terms, $limit, $offset, $module); $total = $result ? $result->getTotal() : 0; } if ($total && $total > $limit) { $paginator = Paginator::factory($total, array('limit' => $limit, 'page' => $page, 'url_options' => array('params' => array('m' => $module), 'options' => array('query' => array('q' => $query))))); } else { $paginator = null; } $this->view()->assign(array('query' => $query, 'result' => $result, 'total' => $total, 'flood' => $flood, 'paginator' => $paginator)); $this->view()->setTemplate('search-module-result'); } else { $this->view()->setTemplate('search-home'); } $this->view()->assign(array('modules' => $modules, 'searchModule' => $module, 'service' => $this->getService())); }