Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
CachedThreadData | |
0.00% |
0 / 21 |
|
0.00% |
0 / 6 |
72 | |
0.00% |
0 / 1 |
addData | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
getTopics | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTopicIdIterator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFromPage | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
retrieve | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
isTopic | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Import\LiquidThreadsApi; |
4 | |
5 | use ArrayIterator; |
6 | use Iterator; |
7 | |
8 | /** |
9 | * Cached LiquidThreads thread data. |
10 | * @property array[] $data |
11 | */ |
12 | class CachedThreadData extends CachedApiData { |
13 | /** @var true[] */ |
14 | protected $topics = []; |
15 | |
16 | /** |
17 | * @param array[] $data |
18 | */ |
19 | protected function addData( array $data ) { |
20 | parent::addData( $data ); |
21 | |
22 | foreach ( $data as $thread ) { |
23 | if ( self::isTopic( $thread ) ) { |
24 | $this->topics[$thread['id']] = true; |
25 | } |
26 | } |
27 | ksort( $this->topics ); |
28 | } |
29 | |
30 | /** |
31 | * Get the IDs of loaded threads that are top-level topics. |
32 | * |
33 | * @return array List of thread IDs in ascending order. |
34 | */ |
35 | public function getTopics() { |
36 | return array_keys( $this->topics ); |
37 | } |
38 | |
39 | /** |
40 | * Create an iterator for the contained topic ids in ascending order |
41 | * |
42 | * @return Iterator<int> |
43 | */ |
44 | public function getTopicIdIterator() { |
45 | return new ArrayIterator( $this->getTopics() ); |
46 | } |
47 | |
48 | /** |
49 | * Retrieve data for threads from the given page starting with the provided |
50 | * offset. |
51 | * |
52 | * @param string $pageName |
53 | * @param int $startId |
54 | * @return array Associative result array |
55 | */ |
56 | public function getFromPage( $pageName, $startId = 0 ) { |
57 | $data = $this->backend->retrieveThreadData( |
58 | [ |
59 | 'thpage' => $pageName, |
60 | 'thstartid' => $startId |
61 | ] |
62 | ); |
63 | $this->addData( $data ); |
64 | |
65 | return $data; |
66 | } |
67 | |
68 | protected function retrieve( array $ids ) { |
69 | return $this->backend->retrieveThreadData( |
70 | [ |
71 | 'thid' => implode( '|', $ids ), |
72 | ] |
73 | ); |
74 | } |
75 | |
76 | /** |
77 | * @param array $thread |
78 | * @return bool |
79 | */ |
80 | public static function isTopic( array $thread ) { |
81 | return $thread['parent'] === null; |
82 | } |
83 | } |