forked from dragonling/phalcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PostController.php
72 lines (65 loc) · 2.67 KB
/
PostController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Eva\EvaBlog\Controllers;
use Eva\EvaBlog\Models;
use Eva\EvaBlog\Models\Post;
class PostController extends \Phalcon\Mvc\Controller
{
public function listAction()
{
$limit = $this->dispatcher->getParam('limit');
$limit = $limit ? $limit : 25;
/** @noinspection PhpDuplicateArrayKeysInspection */
$query = array(
'q' => $this->dispatcher->getParam('q'),
'status' => $this->dispatcher->getParam('status'),
'uid' => $this->dispatcher->getParam('uid'),
'cid' => $this->dispatcher->getParam('cid'),
'tid' => $this->dispatcher->getParam('tid'),
'has_image' => $this->dispatcher->getParam('has_image', 'int'),
'min_created_at' => $this->dispatcher->getParam('min_created_at', 'int'),
'username' => $this->dispatcher->getParam('username'),
'order' => $this->dispatcher->getParam('order'),
'limit' => $limit,
'page' => $this->dispatcher->getParam('page'),
);
$post = new Models\Post();
$posts = $post->findPosts($query);
$paginator = new \Eva\EvaEngine\Paginator(array(
"builder" => $posts,
"limit" => $query['limit'],
"page" => $query['page']
));
$paginator->setQuery($query);
$pager = $paginator->getPaginate();
return $pager;
}
public function searchAction()
{
$limit = $this->dispatcher->getParam('limit', 'int', 25);
$limit = $limit > 100 ? 100 : $limit;
$limit = $limit < 3 ? 3 : $limit;
$order = $this->dispatcher->getParam('order', 'string', '-created_at');
$query = array(
'q' => $this->dispatcher->getParam('q', 'string'),
'status' => 'published',
'uid' => $this->dispatcher->getParam('uid', 'int'),
'cid' => $this->dispatcher->getParam('cid', 'int'),
'tid' => $this->dispatcher->getParam('tid', 'int'),
'username' => $this->dispatcher->getParam('username', 'string'),
'order' => $order,
'limit' => $limit,
'page' => $this->dispatcher->getParam('page', 'int', 1),
);
$postSearcher = new Models\PostSearcher();
$pager = $postSearcher->searchPosts($query);
return $pager;
}
public function relatedPostsByTextAction()
{
$text = $this->dispatcher->getParam('text');
$limit = $this->dispatcher->getParam('limit', 'int', 5);
$days = $this->dispatcher->getParam('days', 'int', 30);
$postSearcher = new Models\PostSearcher();
return $postSearcher->getRelatedPostsByText($text, $limit, $days);
}
}