Skip to content

Commit

Permalink
AI-55 Modified fetching of posts
Browse files Browse the repository at this point in the history
  • Loading branch information
Edzelopez committed Mar 30, 2016
1 parent 1eaff5b commit 6aca53e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions CRM/Attentively/BAO/Attentively.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ static public function pullPosts() {
$allTerms = $allTermsNick = '';
CRM_Attentively_BAO_AttentivelyWatchedTerms::getWatchedTerms($terms);
$watchedTerms = CRM_Core_OptionGroup::values('attentively_terms', FALSE, FALSE, FALSE, NULL, 'label', FALSE);
foreach ($watchedTerms as $key => $ind) {
$terms[$key]['term'] = $key;
$terms[$key]['nickname'] = $ind;
}
foreach ($terms as $term) {
$allTerms .= $term['term'] . ',';
$allTermsNick .= $term['nickname'] . ',';
}
foreach ($watchedTerms as $ind) {
$terms[$ind]['term'] = $ind;
$terms[$ind]['nickname'] = $ind;
}
if (empty($allTerms)) {
return array('error' => ts('You must specify watched terms before you can pull posts. Please specify them at Administer >> System Settings >> Option Groups >> Attentive.ly Watched Terms'));
}
Expand All @@ -265,8 +265,10 @@ static public function pullPosts() {

if ($result['success']) {
// Store posts
$count = 0;
foreach ($result['posts'] as $key => $value) {
$check = CRM_Core_DAO::singleValueQuery("SELECT 1 FROM civicrm_attentively_posts WHERE post_timestamp = {$value->post_timestamp}");
$check = CRM_Core_DAO::singleValueQuery("SELECT 1 FROM civicrm_attentively_posts
WHERE post_timestamp = '{$value->post_timestamp}' AND member_id = '{$value->member_id}' AND network = '{$value->network}'");
if ($check)
continue;
// Add contacts with no contact ID
Expand Down Expand Up @@ -302,12 +304,13 @@ static public function pullPosts() {
VALUES ( '{$value->member_id}', '{$value->contact_id}', '{$value->network}', %1, %2, '{$value->post_timestamp}', %3)";
$params = array(
1 => array($value->post_content, 'String'),
2 => array(date('Y-m-d H:i:s', strtotime($value->post_date)), 'String'),
2 => array(date('Y-m-d H:i:s', $value->post_timestamp), 'String'),
3 => array($value->post_url, 'String'),
);
$dao = CRM_Core_DAO::executeQuery($sql, $params);
$count++;
}
return count($result['posts']);
return $count;
}
else {
$errors[] = $result['error'];
Expand Down

0 comments on commit 6aca53e

Please sign in to comment.