-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwitterStore.php
218 lines (195 loc) · 5.44 KB
/
TwitterStore.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* TwitterStore.php
*
* This is released under the MIT, see license.txt for details
*
* @author Elizabeth Smith <[email protected]>
* @copyright Elizabeth Smith (c)2009
* @link http://elizabethmariesmith.com/slides
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @version 0.2.0
* @package Php-Twit
* @subpackage Lib
* @filesource
*/
/**
* TwitterSTore - uses the custom tree model components
*/
class TwitterStoreIter {
/**
* Only purpose is to keep track of our treeview iter madness
*
* @var int
*/
public $index = 0;
}
/**
* TwitterStore - uses the custom tree model components
*/
class TwitterStore extends PhpGtkCustomTreeModel {
/**
* total number of items to keep in the cached data before a rest
*
* @var int
*/
const CACHE_LIMIT = 100;
/**
* Internal reference to the db class we're pulling data from
*
* @var Sqlite object
*/
protected $database;
/**
* Internal reference to the db class we're pulling data from
*
* @var TwitterStoreIter object
*/
protected $iter;
/**
* a cache of fetched rows from the db
* we could do something fancy, but for now it just resets when
* the limit is hit
*
* @var array
*/
protected $cache;
/**
* keep of tally of number of items pushed into cache
*
* @var int
*/
protected $cache_count = 0;
/**
* default pixbuf to use for all users ;)
*
* @var GdkPixbuf
*/
protected $default_pixbuf;
/**
* current timeline we're hitting
*
* @var string
*/
protected $timeline;
/**
* Current columns supported by this store
*
* @var array
*/
protected $columns = array(GdkPixbuf::gtype,
GObject::TYPE_STRING,
GObject::TYPE_STRING,
GObject::TYPE_STRING);
/**
* method to retrieve gtk specific information about this store
* the flag returned means it's a list, not a tree
*
* @return int
*/
public function __construct(Sqlite $database, $timeline) {
// set up internal data
parent::__construct();
$this->database = $database;
$this->iter = new TwitterStoreIter;
$this->timeline = $timeline;
$this->default_pixbuf = GdkPixbuf::new_from_file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'temp.png');
}
/**
* method to retrieve gtk specific information about this store
* the flag returned means it's a list, not a tree
*
* @return int
*/
public function on_get_flags() {
return Gtk::TREE_MODEL_LIST_ONLY;
}
/**
* Tell the treeview that our store has a specific
* number of columns
*
* @return int
*/
public function on_get_n_columns() {
return count($this->columns);
}
/**
* Tell the treeview the types for each column
*
* @return int
*/
public function on_get_column_type($index) {
return $this->columns[$index];
}
/**
* Retrieves an iter for our store
* in this case the iter will be a row object
* from pdo
*
* @return null|TwitterStoreIter
*/
public function on_get_iter($path) {
if (isset($path[0])) {
$this->iter->index = $path[0];
return $this->iter;
}
return null;
}
/**
* Checks to see if we have more rows in the db
* than the one we're on
*
* @return null|TwitterStoreIter
*/
public function on_iter_next($iter) {
$total = $this->database->count();
if ($total > ($iter->index + 1)) {
$this->iter->index++;
return $this->iter;
}
return null;
}
/**
* Checks to see if a specific
*
* @return null|TwitterStoreIter
*/
public function on_iter_nth_child($iter, $n) {
$total = $this->database->count($this->timeline);
if ($total > ($n + 1)) {
$this->iter->index = $n;
return $this->iter;
}
return null;
}
/**
* Grabs the data from the db and returns a specific column
*
* @return mixed
*/
public function on_get_value($iter, $column) {
// reset the cache if it's too damn big
if ($this->cache_count > self::CACHE_LIMIT) {
$this->cache = array();
$this->cache_count = 0;
}
// our current row and row id
$row = $iter->index;
$id = $this->database->get_id_from_row($row, $this->timeline);
if ($id == false) {
return null;
}
// put data in the cache if needed
if (!isset($this->cache[$id])) {
$this->cache[$id] = $this->database->fetch($row, $this->timeline);
$this->cache_count++;
}
// if they want 0 - they want the gdkpixbuf
// so we need to check if the pic is downloaded, and if it is
// create the pixbuf, otherwise we use the default pixbuf
if ($column === 0) {
return $this->default_pixbuf;
}
return $this->cache[$id][$column];
}
}