Skip to content
This repository was archived by the owner on Jul 15, 2020. It is now read-only.

Commit f1983b2

Browse files
committed
Count reactions instead of likes
1 parent c4e3598 commit f1983b2

File tree

10 files changed

+121
-155
lines changed

10 files changed

+121
-155
lines changed

CHANGELOG.md

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ All notable changes to this project will be documented in this file. This projec
44
[keeps a CHANGELOG](http://keepachangelog.com/) and adheres to
55
[Semantic Versioning](http://semver.org/).
66

7+
## [UNREALEASED] 2017-01-01
78

8-
## [UNREALEASED] 2016-
9+
* ...
910

10-
### Added
11+
## [0.7.0] - 2017-05-22
1112

1213
* Parameters configuration generated when installing dependencies with Composer
1314
* Documentation
@@ -16,56 +17,40 @@ All notable changes to this project will be documented in this file. This projec
1617
* Report date range set via command options
1718
* Translations for multiple languages
1819
* Symfony Dependency Injection
19-
* ...
20-
21-
### Fixed
22-
2320
* Timezones now works correctly for current user and the Graph API's UTC format.
21+
* Most shared topic
22+
* Comments have reactions instead of likes
2423

2524
## [0.6.0] - 2016-09-05
2625

27-
### Added
28-
2926
* Project update
3027
* Template updates
3128
* Topic points based on reactions
3229
* Access token removed from configuration
3330
* ROT13 for offensive words
3431

35-
3632
## [0.5.0] - 2016-06-06
3733

38-
### Added
39-
4034
* Better points calculation for more explanatory comments and replies.
4135

42-
4336
## [0.4.0] - 2016-05-23
4437

45-
### Added
46-
4738
* Points calculation for images and animated images shares.
4839
* More detailed configuration descriptions and FAQ.
4940
* Configuration refactoring.
5041
* Symfony Expression Language component
5142
* Points calculation improvements.
5243
* Bonus points for topics from group staff.
5344

54-
5545
## [0.3.0] - 2016-05-16
5646

57-
### Added
58-
5947
* Dependency injection container
6048
* Configuration overriding
6149
* Offensive speech detection
6250
* Comments merging
6351

64-
6552
## [0.2.0] - 2016-05-09
6653

67-
### Added
68-
6954
* Coding style fixed
7055
* Twig template engine
7156
* Code quality improvements
@@ -74,6 +59,4 @@ All notable changes to this project will be documented in this file. This projec
7459

7560
## [0.1.0] - 2016-05-02
7661

77-
### Added
78-
7962
* Initial repository structure

app/config/points.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ points:
1616
# Points for reactions on topic
1717
topic_reactions: '(topic.getReactionsCount() >= 100) ? 15 : ceil(topic.getReactionsCount() / 10)'
1818

19-
# Points for number of likes on comment or reply
20-
likes: '(likes > 100) ? 11 : ceil(likes / 10)'
19+
# Points for number of reactions on comment or reply
20+
comment_reactions: '(comment.getReactionsCount() > 100) ? 15 : ceil(comment.getReactionsCount() / 10)'
2121

2222
# Points for topics with only image or animated image (such as bumped images from
2323
# album topics and images without much description).
@@ -33,6 +33,7 @@ points:
3333
- ['github.io', 10]
3434
- ['php.net', 20]
3535
- ['php.earth', 20]
36+
- ['wwphp-fb.github.io', 20]
3637
- ['packagist.org', 10]
3738
- ['getcomposer.org', 10]
3839
- ['phptherightway.com', 10]

src/Fetcher.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getFeed()
7171
$pagesCount = 0;
7272
$startDate = $this->config->getParameter('start_datetime');
7373
$endDate = $this->config->getParameter('end_datetime');
74-
$response = $this->fb->get('/'.$this->config->getParameter('group_id').'/feed?fields=comments.limit(200).summary(1){like_count,comment_count,from,created_time,message,can_comment,comments.limit(200).summary(1){like_count,comment_count,from,created_time,message}},reactions.limit(0).summary(1),from,created_time,updated_time,message,type,attachments{type},shares&include_hidden=true&limit=50&since='.$startDate->getTimestamp().'&until='.$endDate->getTimestamp());
74+
$response = $this->fb->get('/'.$this->config->getParameter('group_id').'/feed?fields=comments.limit(200).summary(1){comment_count,from,created_time,message,can_comment,reactions.limit(0).summary(1),comments.limit(200).summary(1){comment_count,from,created_time,message,reactions.limit(0).summary(1)}},reactions.limit(0).summary(1),from,created_time,updated_time,message,type,attachments{type},shares&include_hidden=true&limit=50&since='.$startDate->getTimestamp().'&until='.$endDate->getTimestamp());
7575

7676
$feedEdge = $response->getGraphEdge();
7777

@@ -80,13 +80,8 @@ public function getFeed()
8080
++$pagesCount;
8181
$this->progress->setMessage('Fetching feed from API page '.$pagesCount.' and with the topic updated '.$feedEdge[0]->getField('updated_time')->format('Y-m-d H:i:s'));
8282
$this->progress->advance();
83-
8483
foreach ($feedEdge as $topic) {
85-
$topicArray = $topic->asArray();
86-
$topicArray['commentsCount'] = $topic->getField('comments')->getMetaData()['summary']['total_count'];
87-
$topicArray['reactionsCount'] = $topic->getField('reactions')->getMetaData()['summary']['total_count'];
88-
$topicArray['canComment'] = $topic->getField('comments')->getMetaData()['summary']['can_comment'];
89-
$this->feed[] = $topicArray;
84+
$this->feed[] = $topic;
9085
}
9186
} while ($feedEdge = $this->fb->next($feedEdge));
9287
}

src/Mapper.php

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,19 @@ private function mapFeed($feed)
9595
{
9696
$startDate = $this->config->getParameter('start_datetime');
9797
$endDate = $this->config->getParameter('end_datetime');
98-
9998
foreach ($feed as $topic) {
100-
if ($topic['created_time'] >= $startDate && $topic['created_time'] <= $endDate) {
99+
if ($topic->getField('created_time') >= $startDate && $topic->getField('created_time') <= $endDate) {
101100
$this->mapTopic($topic);
102101
}
103102

104-
if (isset($topic['comments'])) {
105-
foreach ($topic['comments'] as $comment) {
106-
if ($comment['created_time'] >= $startDate && $comment['created_time'] <= $endDate) {
107-
$this->mapComment($comment);
108-
}
103+
foreach($topic->getField('comments', []) as $i => $comment) {
104+
if ($comment->getField('created_time') >= $startDate && $comment->getField('created_time') <= $endDate) {
105+
$this->mapComment($comment);
106+
}
109107

110-
if (isset($comment['comments'])) {
111-
foreach ($comment['comments'] as $reply) {
112-
if ($reply['created_time'] >= $startDate && $reply['created_time'] <= $endDate) {
113-
$this->mapReply($reply);
114-
}
115-
}
108+
foreach($comment->getField('comments', []) as $j=>$reply) {
109+
if ($reply->getField('created_time') >= $startDate && $reply->getField('created_time') <= $endDate) {
110+
$this->mapReply($reply);
116111
}
117112
}
118113
}
@@ -122,112 +117,115 @@ private function mapFeed($feed)
122117
/**
123118
* Maps topic data from API feed to Topic object.
124119
*
125-
* @param array $topic
120+
* @param array $data
126121
*
127122
* @return Topic
128123
*
129124
* @throws \Exception
130125
*/
131-
private function mapTopic($topic)
126+
private function mapTopic($data)
132127
{
133-
$newTopic = new Topic();
134-
$commentsCount = $topic['commentsCount'];
135-
if (array_key_exists('comments', $topic)) {
136-
foreach ($topic['comments'] as $comment) {
137-
if (isset($comment['comment_count'])) {
138-
$commentsCount += $comment['comment_count'];
139-
}
140-
}
141-
}
142-
$newTopic->setCommentsCount($commentsCount);
143-
$newTopic->setId($topic['id']);
144-
$newTopic->setCreatedTime($topic['created_time']);
145-
if (array_key_exists('message', $topic)) {
146-
$newTopic->setMessage($topic['message']);
128+
$topic = new Topic();
129+
130+
// Count comments and replies
131+
$commentsCount = $data->getField('comments')->getMetaData()['summary']['total_count'];
132+
foreach ($data->getField('comments', []) as $comment) {
133+
$commentsCount += $comment->getField('comment_count', 0);
147134
}
148-
$newTopic->setReactionsCount($topic['reactionsCount']);
149-
$newTopic->setCanComment($topic['canComment']);
150-
$newTopic->setType($topic['type']);
151-
if ($newTopic->getType() == 'link' && isset($topic['attachments'][0]['type']) && $topic['attachments'][0]['type'] == 'animated_image_share') {
152-
$newTopic->setType('animated_image_share');
135+
$topic->setCommentsCount($commentsCount);
136+
137+
$topic->setId($data->getField('id'));
138+
$topic->setCreatedTime($data->getField('created_time'));
139+
$topic->setMessage($data->getField('message'));
140+
141+
$topic->setReactionsCount($data->getField('reactions')->getMetaData()['summary']['total_count']);
142+
$topic->setCanComment($data->getField('comments')->getMetaData()['summary']['can_comment']);
143+
$topic->setType($data->getField('type'));
144+
145+
$dataArray = $data->asArray();
146+
147+
if ($topic->getType() == 'link' && isset($dataArray['attachments'][0]['type']) && $dataArray['attachments'][0]['type'] == 'animated_image_share') {
148+
$topic->setType('animated_image_share');
153149
}
154150

155-
if (array_key_exists('from', $topic)) {
156-
$user = $this->mapUser($topic['from']);
157-
$user->addTopic($newTopic);
158-
$newTopic->setUser($user);
151+
if (array_key_exists('from', $dataArray)) {
152+
$user = $this->mapUser($dataArray['from']);
153+
$user->addTopic($topic);
154+
$topic->setUser($user);
159155
}
160156

161-
if (array_key_exists('shares', $topic)) {
162-
$newTopic->setSharesCount($topic['shares']['count']);
157+
if (array_key_exists('shares', $dataArray)) {
158+
$topic->setSharesCount($dataArray['shares']['count']);
163159
}
164160

165161
// Add topic to collection
166-
$this->topics->add($newTopic, $newTopic->getId());
162+
$this->topics->add($topic, $topic->getId());
167163

168164
// Log topic
169-
$log = $newTopic->getId()."\t";
170-
$log .= ' Reactions: '.$newTopic->getReactionsCount()."\t";
171-
$log .= ' Comments: '.$newTopic->getCommentsCount()."\n";
165+
$log = $topic->getId()."\t";
166+
$log .= ' Reactions: '.$topic->getReactionsCount()."\t";
167+
$log .= ' Comments: '.$topic->getCommentsCount()."\n";
172168
$this->log->logTopic($log);
173169

174-
return $newTopic;
170+
return $topic;
175171
}
176172

177173
/**
178174
* Maps comment data from API feed to Comment object.
179175
*
180-
* @param array $comment
176+
* @param array $data
181177
*
182178
* @return Comment
183179
*
184180
* @throws \Exception
185181
*/
186-
private function mapComment($comment)
182+
private function mapComment($data)
187183
{
188-
$newComment = new Comment();
189-
$newComment->setId($comment['id']);
190-
$newComment->setMessage($comment['message']);
191-
$newComment->setLikesCount($comment['like_count']);
184+
$comment = new Comment();
185+
$comment->setId($data->getField('id'));
186+
$comment->setMessage($data->getField('message'));
187+
$comment->setReactionsCount($data->getField('reactions')->getMetaData()['summary']['total_count']);
192188

193-
if (array_key_exists('from', $comment)) {
194-
$user = $this->mapUser($comment['from']);
195-
$user->addComment($newComment);
189+
$dataArray = $data->asArray();
190+
if (array_key_exists('from', $dataArray)) {
191+
$user = $this->mapUser($dataArray['from']);
192+
$user->addComment($comment);
196193

197-
$newComment->setUser($user);
194+
$comment->setUser($user);
198195
}
199196

200-
$this->comments->add($newComment, $newComment->getId());
197+
$this->comments->add($comment, $comment->getId());
201198

202-
return $newComment;
199+
return $comment;
203200
}
204201

205202
/**
206203
* Map reply data from API feed to Reply object.
207204
*
208-
* @param array $reply
205+
* @param array $data
209206
*
210207
* @return Reply
211208
*
212209
* @throws \Exception
213210
*/
214-
private function mapReply($reply)
211+
private function mapReply($data)
215212
{
216-
$newReply = new Reply();
217-
$newReply->setId($reply['id']);
218-
$newReply->setMessage($reply['message']);
219-
$newReply->setLikesCount($reply['like_count']);
213+
$reply = new Reply();
214+
$reply->setId($data->getField('id'));
215+
$reply->setMessage($data->getField('message'));
216+
$reply->setReactionsCount($data->getField('reactions')->getMetaData()['summary']['total_count']);
220217

221-
if (array_key_exists('from', $reply)) {
222-
$user = $this->mapUser($reply['from']);
223-
$user->addReply($newReply);
218+
$dataArray = $data->asArray();
219+
if (array_key_exists('from', $dataArray)) {
220+
$user = $this->mapUser($dataArray['from']);
221+
$user->addReply($reply);
224222

225-
$newReply->setUser($user);
223+
$reply->setUser($user);
226224
}
227225

228-
$this->replies->add($newReply, $newReply->getId());
226+
$this->replies->add($reply, $reply->getId());
229227

230-
return $newReply;
228+
return $reply;
231229
}
232230

233231
/**

0 commit comments

Comments
 (0)