forked from nakbo/Dynamics-typecho
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamics.php
79 lines (70 loc) · 2.51 KB
/
Dynamics.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
73
74
75
76
77
78
79
<?php
/** @noinspection DuplicatedCode */
include_once 'Dynamics_Abstract.php';
include_once 'Dynamics_Page.php';
class Dynamics extends Dynamics_Abstract
{
private $_dynamics_list = array();
private $_have;
private $_position;
private $pageNavigator;
/**
* Dynamics_ constructor.
* @param array $params
*/
public function parse($params = array())
{
$page = $this->request->get('dynamicsPage', 1);
$pageSize = $params["pageSize"] ?: 5;
$select = $this->db->select('table.dynamics.did',
'table.dynamics.authorId',
'table.dynamics.text',
'table.dynamics.status',
'table.dynamics.created',
'table.dynamics.modified',
'table.users.screenName',
'table.users.mail')->from('table.dynamics');
$select->join('table.users', 'table.dynamics.authorId = table.users.uid', Typecho_Db::LEFT_JOIN);
$select = $select->order('table.dynamics.created', Typecho_Db::SORT_DESC);
$select = $select->page($page, $pageSize);
$this->_dynamics_list = $this->db->fetchAll($select);
$count = $this->db->select('count(1) AS count')->from('table.dynamics');
$count = $this->db->fetchAll($count)[0]['count'];
$this->pageNavigator = new Dynamics_Page($pageSize, $count, $page, 4,
array(), false, $params["isPjax"] ?: false
);
$this->_have = count($this->_dynamics_list) > 0;
$this->_position = 0;
}
public function next()
{
if ($this->_have) {
$dic = $this->_dynamics_list[$this->_position];
$this->setDid($dic['did']);
$this->setStatus($dic['status']);
$this->setAuthorId($dic['authorId']);
$this->setMail($dic['mail']);
$this->setAuthorName($dic['screenName']);
$this->setText($dic['text']);
$this->setCreated($dic['created']);
$this->setModified($dic['modified']);
$this->_position++;
$this->_have = count($this->_dynamics_list) > $this->_position;
return true;
} else {
return false;
}
}
/**
* 当前页面位置
* @return int
*/
public function current()
{
return $this->_position + 1;
}
public function navigator()
{
echo "<ol class=\"dynamics-page-navigator\">" . $this->pageNavigator->show() . "</ol>";
}
}