当前位置: 首页>>代码示例>>PHP>>正文


PHP Insight::setPosts方法代码示例

本文整理汇总了PHP中Insight::setPosts方法的典型用法代码示例。如果您正苦于以下问题:PHP Insight::setPosts方法的具体用法?PHP Insight::setPosts怎么用?PHP Insight::setPosts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Insight的用法示例。


在下文中一共展示了Insight::setPosts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $post_dao = DAOFactory::getDAO('PostDAO');
     $insight_text = '';
     foreach ($last_week_of_posts as $post) {
         $big_reshares = $post_dao->getRetweetsByAuthorsOverFollowerCount($post->post_id, $instance->network, $user->follower_count);
         if (isset($big_reshares) && sizeof($big_reshares) > 0) {
             if (!isset($config)) {
                 $config = Config::getInstance();
             }
             if (sizeof($big_reshares) > 1) {
                 $headline = "People with lots of followers " . $this->terms->getVerb('shared') . " " . "{$this->username}";
             } else {
                 $follower_count_multiple = intval($big_reshares[0]->follower_count / $user->follower_count);
                 if ($follower_count_multiple > 1) {
                     $headline = "Someone with <strong>" . $follower_count_multiple . "x</strong> more followers " . $this->terms->getVerb('shared') . " " . $this->username;
                 } else {
                     $headline = $big_reshares[0]->full_name . " " . $this->terms->getVerb('shared') . " " . $this->username;
                 }
             }
             $added_people = 0;
             foreach ($big_reshares as $big_resharer) {
                 $added_people += $big_resharer->follower_count - $user->follower_count;
             }
             $insight_text = number_format($added_people) . " more people saw " . $this->username . "'s " . $this->terms->getNoun('post') . ".";
             $simplified_post_date = date('Y-m-d', strtotime($post->pub_date));
             //Instantiate the Insight object
             $my_insight = new Insight();
             $my_insight->slug = "big_reshare_" . $post->id;
             //slug to label this insight's content
             $my_insight->instance_id = $instance->id;
             $my_insight->date = $simplified_post_date;
             //date of the data this insight applies to
             $my_insight->headline = $headline;
             // or just set a string like 'Ohai';
             $my_insight->text = $insight_text;
             // or just set a strong like "Greetings humans";
             $my_insight->header_image = $header_image;
             $my_insight->filename = basename(__FILE__, ".php");
             $my_insight->emphasis = Insight::EMPHASIS_MED;
             $my_insight->setPeople($big_reshares);
             $my_insight->setPosts(array($post));
             $this->insight_dao->insertInsight($my_insight);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:49,代码来源:bigreshare.php

示例2: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $fav_dao = DAOFactory::getDAO('FavoritePostDAO');
     $days_ago = 0;
     while ($days_ago < $number_days) {
         $since_date = date("Y-m-d", strtotime("-" . $days_ago . " day"));
         if (self::shouldGenerateInsight('favorites_year_ago_flashback', $instance, $insight_date = $since_date, $regenerate_existing_insight = false)) {
             //Generate flashback post list
             $flashback_favs = $fav_dao->getFavoritesFromOneYearAgo($instance->network_user_id, $instance->network, $since_date);
             if (isset($flashback_favs) && sizeof($flashback_favs) > 0) {
                 //Load photos for Instagram
                 if ($instance->network == 'instagram') {
                     $photo_dao = DAOFactory::getDAO('PhotoDAO');
                     $flashback_fav_photos = array();
                     foreach ($flashback_favs as $post) {
                         $photo = $photo_dao->getPhoto($post->post_id, 'instagram');
                         $flashback_fav_photos[] = $photo;
                         $photo = null;
                     }
                     $flashback_favs = $flashback_fav_photos;
                 }
                 $post_year = date(date('Y', strtotime($flashback_favs[0]->pub_date)));
                 $current_year = date('Y');
                 $number_of_years_ago = $current_year - $post_year;
                 $plural = $number_of_years_ago > 1 ? 's' : '';
                 if ($instance->network == 'twitter') {
                     $headline = $this->username . " liked @" . $flashback_favs[0]->author_username . "'s tweet from " . $number_of_years_ago . " year" . $plural . " ago";
                 } else {
                     $post_term = $flashback_favs[0]->is_short_video ? 'video' : '%post';
                     $headline = $this->username . " " . $this->terms->getVerb('liked') . " " . $flashback_favs[0]->author_username . $this->terms->getProcessedText("'s " . $post_term . " from " . $number_of_years_ago . " year" . $plural . " ago");
                 }
                 $my_insight = new Insight();
                 $my_insight->instance_id = $instance->id;
                 $my_insight->slug = 'favorites_year_ago_flashback';
                 $my_insight->date = $since_date;
                 $my_insight->headline = $headline;
                 $my_insight->text = "Can you believe how fast time flies?";
                 $my_insight->emphasis = Insight::EMPHASIS_MED;
                 $my_insight->filename = basename(__FILE__, ".php");
                 $my_insight->setPosts($flashback_favs);
                 $this->insight_dao->insertInsight($my_insight);
             }
         }
         $days_ago++;
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:49,代码来源:favoriteflashbacks.php

示例3: testInsightRelatedDataSetters

 public function testInsightRelatedDataSetters()
 {
     $i = new Insight();
     $i->setPhotos("this is my list of photos");
     $this->assertEqual($i->related_data["photos"], "this is my list of photos");
     $i->setPosts("my posts");
     $this->assertEqual($i->related_data["posts"], "my posts");
     $i->setLineChart("line chart data goes here");
     $this->assertEqual($i->related_data["line_chart"], "line chart data goes here");
     $i->setBarChart("bar chart data goes here");
     $this->assertEqual($i->related_data["bar_chart"], "bar chart data goes here");
     $i->setPeople("list 'o users");
     $this->assertEqual($i->related_data["people"], "list 'o users");
     $i->setLinks("listoflinks");
     $this->assertEqual($i->related_data["links"], "listoflinks");
     $i->setMilestoneNumber("milestone_number");
     $this->assertEqual($i->related_data["milestone_number"], "milestone_number");
 }
开发者ID:nagyistoce,项目名称:ThinkUp,代码行数:18,代码来源:TestOfInsight.php

示例4: testInsightRelatedDataSetters

 public function testInsightRelatedDataSetters()
 {
     $i = new Insight();
     // @TODO Assign and assert that the data is in the array structure it should be
     $i->setPhotos("this is my list of photos");
     $this->assertEqual($i->related_data["photos"], "this is my list of photos");
     $i->setPosts("my posts");
     $this->assertEqual($i->related_data["posts"], "my posts");
     $i->setLineChart("line chart data goes here");
     $this->assertEqual($i->related_data["line_chart"], "line chart data goes here");
     $i->setBarChart("bar chart data goes here");
     $this->assertEqual($i->related_data["bar_chart"], "bar chart data goes here");
     $i->setPeople("list 'o users");
     $this->assertEqual($i->related_data["people"], "list 'o users");
     $i->setLinks("listoflinks");
     $this->assertEqual($i->related_data["links"], "listoflinks");
     $i->setMilestones("milestones");
     $this->assertEqual($i->related_data["milestones"], "milestones");
     $i->setButton("button");
     $this->assertEqual($i->related_data["button"], "button");
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:21,代码来源:TestOfInsight.php

示例5: getInsightForCounts

 public function getInsightForCounts($this_period_count, $last_period_count, $instance, $matching_posts)
 {
     $insight = null;
     if ($this_period_count > 0) {
         $insight = new Insight();
         $insight->slug = $this->getSlug();
         $insight->instance_id = $instance->id;
         $insight->date = $this->insight_date;
         $network = ucfirst($instance->network);
         $potential_headlines = array();
         if ($this_period_count > 1) {
             $potential_headlines[] = '%username gave %total fucks';
             $potential_headlines[] = 'F-bombs rain from the sky';
         } else {
             $potential_headlines[] = '%username really gave a fuck';
         }
         if ($instance->network == 'facebook') {
             $potential_headlines[] = 'Facebook users curse knowledgeably';
         }
         $insight->headline = $this->getVariableCopy($potential_headlines, array('total' => $this_period_count));
         $insight->text = $this->username . ' said &ldquo;fuck&rdquo; ' . $this->terms->getOccurrencesAdverb($this_period_count) . ' in the past month.';
         if ($this_period_count != $last_period_count && $last_period_count > 0) {
             $f_diff = $this_period_count - $last_period_count;
             $diff = $f_diff < 0 ? 'fewer' : 'more';
             $insight->text .= ' That\'s ' . number_format(abs($f_diff)) . ' ' . $diff . ' than the prior month. ';
             if ($diff == 'fewer') {
                 $insight->text .= 'Fucking Awesome.';
             } else {
                 $insight->text .= 'WTF?';
             }
         }
         $insight->filename = basename(__FILE__, ".php");
         $insight->emphasis = Insight::EMPHASIS_HIGH;
         if (count($this->posts_to_include) > 0) {
             $insight->setPosts(array_slice($this->posts_to_include, 0, 10));
             if (count($this->posts_to_include) > 1) {
                 //plural
                 $insight->text .= $this->getVariableCopy(array(" Here are some of the %posts that elicited a \"fuck.\"", " These are some of the %posts that inspired %username to say \"fuck\"."));
             } else {
                 //singular
                 $insight->text .= $this->getVariableCopy(array(" Here is the %post that elicited a \"fuck.\"", " This is the %post that inspired %username to say \"fuck\"."));
             }
         }
     }
     return $insight;
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:46,代码来源:fbombcount.php

示例6: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $year = date('Y');
     $regenerate = false;
     //testing
     //$regenerate = true;
     $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date);
     if ($should_generate_insight) {
         $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
         $filename = basename(__FILE__, ".php");
         $insight = new Insight();
         $insight->instance_id = $instance->id;
         $insight->slug = $this->slug;
         $insight->date = "{$year}-{$this->run_date}";
         $post_dao = DAOFactory::getDAO('PostDAO');
         $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance);
         $qualified_year = "this year.";
         if (date('Y', strtotime($earliest_pub_date)) == date('Y')) {
             if (date('n', strtotime($earliest_pub_date)) > 1) {
                 //not January
                 //Earliest post was this year; figure out what month we have data since this year
                 $since = date('F', strtotime($earliest_pub_date));
                 $qualified_year = "this year (at least since " . $since . ").";
             }
         }
         $copy = array('twitter' => array('normal' => array('headline' => "%username's most talkative day on Twitter in %year", 'body' => "%username tweeted <strong>%total times on %talkative_date</strong>, " . "more than any other day %qualified_year (Strange — the " . "forecast didn't say anything about a tweetstorm.) " . "These are %username's most popular tweets from that day."), 'multiple' => array('headline' => "%username's most talkative day on Twitter in %year", 'body' => "In the running for %username's most talkative day " . "on Twitter, %year, we've got a tie: %username tweeted " . "<strong>%total times on %talkative_date</strong> — more than on any other " . "days %qualified_year These are %username's most popular tweets " . "from each day.")), 'facebook' => array('normal' => array('headline' => "%username's most talkative day on Facebook in %year", 'body' => "%username posted to Facebook <strong>%total times on " . "%talkative_date</strong>, more than any other day %qualified_year " . "These are %username's most popular status updates from that day."), 'multiple' => array('headline' => "%username's most talkative day on Facebook in %year", 'body' => "In the running for %username's most talkative day " . "on Facebook, %year, we've got a tie: %username posted " . "<strong>%total times on %talkative_date</strong> — more than on any other " . "days %qualified_year These are %username's most popular " . "status updates from each day.")), 'instagram' => array('normal' => array('headline' => "%username's most Instagrammed day in %year", 'body' => "%username posted on Instagram <strong>%total times on " . "%talkative_date</strong>, more than any other day %qualified_year " . "These are %username's most popular photos and videos from that day."), 'multiple' => array('headline' => "%username's most Instagrammed day in %year", 'body' => "In the running for %username's most Instagrammed day " . "in %year, we've got a tie: %username posted " . "<strong>%total times on %talkative_date</strong> — more than on any other " . "days %qualified_year These are %username's most popular " . "posts from each day.")));
         $network = $instance->network;
         $most_talkative_days = $this->getMostTalkativeDays($instance);
         if (sizeof($most_talkative_days) == 1) {
             $type = 'normal';
             $date = new DateTime($most_talkative_days[0]['pub_date']);
             $query_date = $date->format("Y-m-d");
             $talkative_dates = $date->format('F jS');
             $popular_posts = $this->mostPopularPosts($instance, $date = $query_date);
         } else {
             if (sizeof($most_talkative_days) > 1) {
                 $type = 'multiple';
                 $dates = array();
                 $popular_posts = array();
                 foreach ($most_talkative_days as $day) {
                     $date = new DateTime($day['pub_date']);
                     $query_date = $date->format("Y-m-d");
                     $dates[] = $date->format('F jS');
                     $posts = $this->mostPopularPosts($instance, $date = $query_date, $limit = 1);
                     $popular_posts[] = $posts[0];
                 }
                 $talkative_dates = $this->makeList($dates);
             }
         }
         $insight->headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year));
         $insight->text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'total' => $most_talkative_days[0]['post_count'], 'talkative_date' => $talkative_dates, 'qualified_year' => $qualified_year));
         $insight->emphasis = Insight::EMPHASIS_HIGH;
         $insight->filename = $filename;
         //Populate Instagram photos
         if ($instance->network == 'instagram') {
             $photo_dao = DAOFactory::getDAO('PhotoDAO');
             $popular_photos = array();
             foreach ($popular_posts as $post) {
                 if ($post->network == 'instagram') {
                     $post = $photo_dao->getPhoto($post->post_id, 'instagram');
                     $popular_photos[] = $post;
                 }
             }
             $popular_posts = $popular_photos;
         }
         foreach ($popular_posts as $post) {
             //Avoid broken avatars
             $post->author_avatar = $user->avatar;
         }
         $insight->setPosts($popular_posts);
         $this->insight_dao->insertInsight($insight);
         $insight = null;
         $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
     }
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:77,代码来源:eoymosttalkativeday.php

示例7: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $year = date('Y');
     $regenerate = false;
     //testing
     //$regenerate = true;
     $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date, $count_related_posts = null, array('instagram'));
     if ($should_generate_insight) {
         $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
         $insight = new Insight();
         $insight->instance_id = $instance->id;
         $insight->slug = $this->slug;
         $insight->date = "{$year}-{$this->run_date}";
         $count = 0;
         $post_dao = DAOFactory::getDAO('PostDAO');
         $network = $instance->network;
         $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network);
         foreach ($last_year_of_posts as $post) {
             if ($this->hasLOL($post)) {
                 $count++;
             }
         }
         $most_popular_lolees = $this->getMostPopularLOLees($instance);
         $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance);
         $qualified_year = $year;
         if (date('Y', strtotime($earliest_pub_date)) == date('Y')) {
             if (date('n', strtotime($earliest_pub_date)) > 1) {
                 //not January
                 //Earliest post was this year; figure out what month we have data since this year
                 $since = date('F', strtotime($earliest_pub_date));
                 $qualified_year = $year . " (at least since " . $since . ")";
             }
         }
         $copy = array('twitter' => array('normal' => array('headline' => "%username's Twitter LOLs, %year", 'body' => array('normal' => "%username found <strong>%total things</strong> to LOL about on " . "Twitter in %qualified_year, including these LOLed-at tweets.", 'one' => "%username found <strong>%total things</strong> to LOL about on " . "Twitter in %qualified_year, including this LOLed-at tweet.", 'none' => "%username found <strong>%total things</strong> to LOL about on " . "Twitter in %qualified_year. Not a bad year!")), 'one' => array('headline' => "Funny, but rarely LOL-funny", 'body' => array('normal' => "%username found <strong>1 thing</strong> to LOL about on " . "Twitter in %qualified_year."))), 'facebook' => array('normal' => array('headline' => "%username's LOLs of Facebook, %year", 'body' => array('normal' => "ROFL. %username LOLed at <strong>%total things</strong> on Facebook " . "in %qualified_year, including these LOL-worthy status updates.", 'one' => "ROFL. %username LOLed at <strong>%total things</strong> on Facebook " . "in %qualified_year, including this LOL-worthy status update.", 'none' => "ROFL. %username LOLed at <strong>%total things</strong> on Facebook " . "in %qualified_year. Gotta love a good LOL.")), 'one' => array('headline' => "%username's one LOL on Facebook, %year", 'body' => array('normal' => "%username LOLed <strong>once</strong> on Facebook " . "in %qualified_year. Not the funniest of years."))));
         if ($count === 0) {
             return;
         }
         if ($count > 1) {
             $type = 'normal';
             if (count($most_popular_lolees) > 1) {
                 $body_type = 'normal';
             } else {
                 if (count($most_popular_lolees) === 1) {
                     $body_type = 'one';
                 } else {
                     $body_type = 'none';
                 }
             }
         } else {
             $type = 'one';
             $body_type = 'normal';
         }
         $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('total' => $count, 'year' => $year));
         $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body'][$body_type]), array('total' => $count, 'qualified_year' => $qualified_year));
         $insight->headline = $headline;
         $insight->text = $insight_text;
         $lolees = array_slice($most_popular_lolees, 0, 12);
         $insight->setPosts($lolees);
         $insight->filename = basename(__FILE__, ".php");
         $insight->emphasis = Insight::EMPHASIS_HIGH;
         $this->insight_dao->insertInsight($insight);
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:66,代码来源:eoylolcount.php

示例8: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $filename = basename(__FILE__, ".php");
     $insight_text = '';
     //Find out if insight already exists
     $should_generate_insight = self::shouldGenerateInsight('top_amplifier', $instance, date('Y-m-d'));
     if ($should_generate_insight) {
         //insight does not exist
         //Get yesterday's retweets
         $yesterdays_retweets = array();
         $simplified_date_yesterday = date('Y-m-d', strtotime('-1 day'));
         foreach ($last_week_of_posts as $post) {
             if ($post->in_retweet_of_post_id != null && $post->in_rt_of_user_id != null) {
                 $simplified_post_date = date('Y-m-d', strtotime($post->pub_date));
                 if ($simplified_date_yesterday == $simplified_post_date) {
                     $yesterdays_retweets[] = $post;
                 }
             }
         }
         $largest_added_audience = 0;
         $insight_retweeted_user = null;
         $insight_retweet = null;
         //Get top amplifier from yesterday
         foreach ($yesterdays_retweets as $post) {
             if (!isset($user_dao)) {
                 $user_dao = DAOFactory::getDAO('UserDAO');
             }
             $retweeted_user = $user_dao->getDetails($post->in_rt_of_user_id, $post->network);
             //if user exists and has fewer followers than instance user compare to current top
             if (isset($retweeted_user) && $retweeted_user->follower_count < $user->follower_count) {
                 $added_audience = $user->follower_count - $retweeted_user->follower_count;
                 if ($added_audience > $largest_added_audience) {
                     $largest_added_audience = $added_audience;
                     $insight_retweeted_user = $retweeted_user;
                     $insight_retweet = $post;
                 }
             }
         }
         //If there's a top amplifier from yesterday, insert the insight
         if ($largest_added_audience > 0 && isset($insight_retweeted_user) && isset($insight_retweet)) {
             $multiplier = floor($user->follower_count / $insight_retweeted_user->follower_count);
             if ($multiplier > 1 && TimeHelper::getTime() / 10 % 2 == 1) {
                 $largest_added_audience = number_format($multiplier) . 'x';
             } else {
                 $largest_added_audience = number_format($largest_added_audience);
             }
             $retweeted_username = $insight_retweeted_user->username;
             if ($instance->network == 'twitter') {
                 $retweeted_username = '@' . $retweeted_username;
             }
             $headline = $this->getVariableCopy(array($insight_retweeted_user->full_name . " can thank %username for %added more people seeing this %post", "%added more people saw %repostedee's %post thanks to %username", '%username boosted ' . $insight_retweeted_user->full_name . '\'s %post to %added more people'), array('repostedee' => $retweeted_username, 'added' => $largest_added_audience));
             $my_insight = new Insight();
             $my_insight->instance_id = $instance->id;
             $my_insight->slug = 'top_amplifier';
             //slug to label this insight's content
             $my_insight->date = date('Y-m-d');
             //date of the data this insight applies to
             $my_insight->headline = $headline;
             // or just set a string like 'Ohai';
             $my_insight->text = $insight_text;
             // or just set a strong like "Greetings humans";
             $my_insight->header_image = $insight_retweeted_user->avatar;
             $my_insight->emphasis = Insight::EMPHASIS_MED;
             $my_insight->filename = basename(__FILE__, ".php");
             $my_insight->setPosts(array($insight_retweet));
             $my_insight->setPeople(array($insight_retweeted_user));
             $this->insight_dao->insertInsight($my_insight);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:73,代码来源:amplifier.php

示例9: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $year = date('Y');
     $regenerate = false;
     //testing
     //$regenerate = true;
     $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date);
     if ($should_generate_insight) {
         $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
         $insight = new Insight();
         $insight->instance_id = $instance->id;
         $insight->slug = $this->slug;
         $insight->date = "{$year}-{$this->run_date}";
         $count = 0;
         $post_dao = DAOFactory::getDAO('PostDAO');
         $network = $instance->network;
         $last_year_of_posts = $post_dao->getThisYearOfPostsWithLinksIterator($author_id = $instance->network_user_id, $network = $network);
         $scored_pics = $this->getScoredPics($last_year_of_posts);
         $posts = $this->getMostPopularPics($instance, $scored_pics);
         $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance);
         $qualified_year = ".";
         if (date('Y', strtotime($earliest_pub_date)) == date('Y')) {
             if (date('n', strtotime($earliest_pub_date)) > 1) {
                 //not January
                 //Earliest post was this year; figure out what month we have data since this year
                 $since = date('F', strtotime($earliest_pub_date));
                 $qualified_year = " (at least since " . $since . ").";
             }
         }
         $copy = array('twitter' => array('normal' => array('headline' => "%username's most popular picture on Twitter, %year", 'body' => "With tweets limited to 140 characters, a picture " . "is worth at least 1,000 characters. In %year, these were the " . "most popular pics %username shared on Twitter%qualified_year"), 'one' => array('headline' => "%username's most popular picture on Twitter, %year", 'body' => "With tweets limited to 140 characters, a picture " . "is worth at least 1,000 characters. In %year, this was the " . "most popular pic %username shared on Twitter%qualified_year"), 'none' => array('headline' => "%username must yearn for the text-only days of Twitter", 'body' => "%username didn't share any pics on Twitter this year%qualified_year " . "Bummer! On the plus side: %username probably doesn't need to worry about " . "leaked nudes!")), 'facebook' => array('normal' => array('headline' => "%username's most popular picture on Facebook, %year", 'body' => "What's a newsfeed without the photos? In %year, " . "these were the most popular pics %username shared on Facebook%qualified_year"), 'one' => array('headline' => "%username's most popular picture on Facebook, %year", 'body' => "What's a newsfeed without the photos? In %year, " . "this was the most popular pic %username shared on Facebook%qualified_year"), 'none' => array('headline' => "No photos on Facebook?", 'body' => "%username didn't share any pics on Facebook this year%qualified_year " . "Bummer! On the plus side: %username probably doesn't need to worry about " . "leaked nudes!")));
         if (sizeof($posts) > 1) {
             $type = 'normal';
         } else {
             if (sizeof($posts) == 1) {
                 $type = 'one';
             } else {
                 $type = 'none';
             }
         }
         $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year));
         $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'qualified_year' => $qualified_year));
         $insight->headline = $headline;
         $insight->text = $insight_text;
         //Avoid InsightFieldExceedsMaxLengthException
         $posts = array_slice($posts, 0, 12);
         //Avoid broken avatars
         foreach ($posts as $post) {
             $post->author_avatar = $user->avatar;
         }
         $insight->setPosts($posts);
         $insight->filename = basename(__FILE__, ".php");
         $insight->emphasis = Insight::EMPHASIS_HIGH;
         $this->insight_dao->insertInsight($insight);
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:Nitin216,项目名称:ThinkUp,代码行数:58,代码来源:eoypopularpic.php

示例10: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $year = date('Y');
     $regenerate = false;
     //testing
     //$regenerate = true;
     $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date);
     if ($should_generate_insight) {
         $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
         $insight = new Insight();
         $insight->instance_id = $instance->id;
         $insight->slug = $this->slug;
         $insight->date = "{$year}-{$this->run_date}";
         $count = 0;
         $post_dao = DAOFactory::getDAO('PostDAO');
         $network = $instance->network;
         $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network);
         $scored_posts = $this->getScoredPosts($last_year_of_posts);
         $top_post = $this->getMostPopularPost($instance, $scored_posts);
         $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance);
         $qualified_year = $year . ".";
         if (date('Y', strtotime($earliest_pub_date)) == date('Y')) {
             if (date('n', strtotime($earliest_pub_date)) > 1) {
                 //not January
                 //Earliest post was this year; figure out what month we have data since this year
                 $since = date('F', strtotime($earliest_pub_date));
                 $qualified_year = $year . " (at least since " . $since . ").";
             }
         }
         $copy = array('twitter' => array('normal' => array('headline' => "%username's most popular tweet of %year", 'body' => "We don't tweet for the glory, but a little " . "attention doesn't hurt. With <strong>%list_of_stats</strong>, " . "this is %username's most popular tweet of %qualified_year")), 'facebook' => array('normal' => array('headline' => "%username's most popular status update of %year", 'body' => "Sometimes you just say the right thing. With <strong>" . "%list_of_stats</strong>, this is %username's most " . "popular status update of %qualified_year")));
         $stats = array();
         if ($top_post->favlike_count_cache > 0) {
             $stats[] = $top_post->favlike_count_cache . " " . $this->terms->getNoun('like', $top_post->favlike_count_cache);
         }
         if ($top_post->retweet_count_cache > 0) {
             $stats[] = $top_post->retweet_count_cache . " " . $this->terms->getNoun('retweet', $top_post->retweet_count_cache);
         }
         if ($top_post->reply_count_cache > 0) {
             $stats[] = $top_post->reply_count_cache . " " . $this->terms->getNoun('reply', $top_post->reply_count_cache);
         }
         $list_of_stats = $this->makeList($stats);
         $type = 'normal';
         $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year));
         $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('qualified_year' => $qualified_year, 'list_of_stats' => $list_of_stats));
         $insight->headline = $headline;
         $insight->text = $insight_text;
         $insight->setPosts(array($top_post));
         $insight->filename = basename(__FILE__, ".php");
         $insight->emphasis = Insight::EMPHASIS_HIGH;
         $this->insight_dao->insertInsight($insight);
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:55,代码来源:eoymostpopular.php

示例11: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $has_never_run = !$this->insight_dao->doesInsightExist($this->slug, $instance->id);
     if (Utils::isTest() || $has_never_run && (date("Y-m-d") == '2015-06-27' || date("Y-m-d") == '2015-06-28')) {
         $this->logger->logInfo("Should generate insight", __METHOD__ . ',' . __LINE__);
         $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-06/white-house-rainbow.jpg', 'alt_text' => '1600 Pennsylvania Avenue', 'credit' => 'Photo: Jason Goldman', 'img_link' => 'https://twitter.com/Goldman44/status/614599247959322624');
         $topics = array('lovewins' => array("LoveWins", "marriage equality", "scotus", "gay marriage", "pride"));
         $matches = array();
         $matched_posts = array();
         $matched = false;
         foreach ($last_week_of_posts as $post) {
             foreach ($topics as $key => $strings) {
                 foreach ($strings as $string) {
                     if (preg_match_all('/\\b' . strtolower($string) . '\\b/i', strtolower($post->post_text), $matches)) {
                         $matched = true;
                         $this->logger->logInfo("FOUND " . $string . " in " . $post->post_text, __METHOD__ . ',' . __LINE__);
                     } else {
                         $this->logger->logInfo("Didn't find " . $string . " in " . $post->post_text, __METHOD__ . ',' . __LINE__);
                     }
                 }
             }
             if ($matched) {
                 $this->logger->logInfo("Matched post " . $post->post_text, __METHOD__ . ',' . __LINE__);
                 $matched_posts[] = $post;
             }
             $matched = false;
         }
         if (count($matched_posts) > 0) {
             if ($instance->network == 'facebook') {
                 $headline = $this->username . " had enough pride for all 50 states";
                 $insight_text = $this->username . ' joined the <a href="https://facebook.com/celebratepride">marriage equality celebration</a> ' . 'this week!';
             } else {
                 $headline = $this->username . " joined the #LoveWins celebration";
                 $insight_text = $this->username . ' was all about <a href="https://twitter.com/hashtag/LoveWins">marriage equality</a> ' . 'this week.';
             }
             $insight = new Insight();
             $insight->instance_id = $instance->id;
             $insight->slug = $this->slug;
             $insight->date = date("Y-m-d");
             $insight->headline = $headline;
             $insight->text = $insight_text;
             $insight->filename = basename(__FILE__, ".php");
             $insight->emphasis = Insight::EMPHASIS_HIGH;
             $insight->setHeroImage($hero_image);
             $matched_posts_sliced = array_slice($matched_posts, 0, 5);
             $insight->setPosts($matched_posts_sliced);
             $this->insight_dao->insertInsight($insight);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:53,代码来源:lovewins.php

示例12: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     if ($instance->network != 'facebook') {
         $this->logger->logInfo("Done generating insight (Skipped Non-Facebook)", __METHOD__ . ',' . __LINE__);
         return;
     }
     $year = date('Y');
     $regenerate = false;
     //testing
     //$regenerate = true;
     $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date);
     if ($should_generate_insight) {
         $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
         $post_dao = DAOFactory::getDAO('PostDAO');
         $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $instance->network);
         $topics = array('ferguson' => array("Ferguson", "Mike Brown", "Michael Brown"), 'obamacare' => array("Obamacare"), 'immigration' => array("immigration"), 'gamergate' => array("GamerGate"), 'isis' => array("ISIS"), 'israel' => array("Israel"), 'palestine' => array("Palestine"), 'hamas' => array("Hamas"), 'donaldsterling' => array("Donald Sterling"), 'marriage' => array("gay marriage", "marriage equality", "same-sex marriage"), 'ebola' => array("ebola"), 'climatechange' => array("climate change", "global warming"));
         $matches = array();
         foreach ($last_year_of_posts as $post) {
             foreach ($topics as $key => $strings) {
                 foreach ($strings as $string) {
                     if (preg_match_all('/\\b' . $string . '\\b/i', $post->post_text) > 0) {
                         $matches[$key] = array('term' => $string, 'post' => $post);
                         unset($topics[$key]);
                         break;
                     }
                 }
             }
         }
         $insight = new Insight();
         if (count($matches) == 0) {
             $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance);
             $qualified_year = "";
             if (date('Y', strtotime($earliest_pub_date)) == date('Y')) {
                 if (date('n', strtotime($earliest_pub_date)) > 1) {
                     //not January
                     //Earliest post was this year; figure out what month we have data since this year
                     $since = date('F', strtotime($earliest_pub_date));
                     $qualified_year = " (at least since " . $since . ")";
                 }
             }
             $headline = $this->username . ' kept the drama off Facebook in 2014';
             $insight_text = $this->username . " avoided contentious topics like immigration and ebola in {$year}" . $qualified_year . ', which can be a good way to keep Facebook more friendly.';
             $posts = null;
             //Show avatar if there are no posts
             $insight->header_image = $user->avatar;
         } else {
             $headline = $this->username . " took on {$year}'s hot-button issues";
             $posts = array();
             $mentioned = array();
             foreach ($matches as $m) {
                 if (count($posts) < 3) {
                     $posts[] = $m['post'];
                 }
                 $mentioned[] = $m['term'];
             }
             $num = count($mentioned);
             if ($num > 1) {
                 $mentioned[$num - 1] = 'and ' . $mentioned[$num - 1];
             }
             $mention_string = join($num == 2 ? ' ' : ', ', $mentioned);
             $insight_text = $this->username . " mentioned {$mention_string} on Facebook in {$year}. " . "It's great to use Facebook to discuss issues that matter.";
         }
         $insight->instance_id = $instance->id;
         $insight->slug = $this->slug;
         $insight->date = "{$year}-{$this->run_date}";
         $insight->headline = $headline;
         $insight->text = $insight_text;
         $insight->filename = basename(__FILE__, ".php");
         $insight->emphasis = Insight::EMPHASIS_HIGH;
         if ($posts) {
             $posts = array_slice($posts, 0, 12);
             $link_dao = DAOFactory::getDAO('LinkDAO');
             foreach ($posts as $post) {
                 $post->links = $link_dao->getLinksForPost($post->post_id, $post->network);
             }
             $insight->setPosts($posts);
         }
         $this->insight_dao->insertInsight($insight);
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:83,代码来源:eoycontroversialtopics.php

示例13: generateInsight


//.........这里部分代码省略.........
             if ($do30 && !$headline) {
                 $winning_percent = 0;
                 $winning_activity = null;
                 foreach ($activities as $activity => $object_key) {
                     if (isset($baselines['avg_' . $activity . '_count_last_30_days']->value)) {
                         $base_value = $baselines['avg_' . $activity . '_count_last_30_days']->value;
                         $value = $post->{$object_key};
                         $percent_change = $value / ($base_value == 0 ? 1 : $base_value);
                         if ($value > $base_value * 2 && $percent_change > $winning_percent) {
                             $winning_percent = $percent_change;
                             $winning_activity = $activity;
                             $winning_multiplier = floor($value / $base_value);
                         }
                     }
                 }
                 if ($winning_activity) {
                     $slug = $winning_activity . '_spike_30_day_' . $post->id;
                     $emphasis = Insight::EMPHASIS_MED;
                     $my_insight_posts = array($post);
                     switch ($winning_activity) {
                         case 'fave':
                             $headline = $this->username . ' got ' . $this->terms->getMultiplierAdverb($winning_multiplier) . ' the ' . $this->terms->getNoun('like', InsightTerms::PLURAL);
                             $insight_text = "<strong>" . number_format($post->favlike_count_cache) . " people</strong> " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post') . ", which is more than " . "<strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> {$this->username}'s 30-day average.";
                             break;
                         case 'reply':
                             $plural = $post->reply_count_cache == 1 ? InsightTerms::SINGULAR : InsightTerms::PLURAL;
                             $headline = $this->username . " got <strong>" . number_format($post->reply_count_cache) . " " . $this->terms->getNoun('reply', $plural) . '</strong>';
                             $insight_text = "That's more than <strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> " . $this->username . "'s 30-day average.";
                             break;
                         case 'retweet':
                             $headline = "<strong>" . number_format($post->all_retweets) . " people</strong>" . " {$share_verb} " . "{$this->username}!";
                             $insight_text = "Seems like this one is going viral. This " . $this->terms->getNoun('post') . " got more than <strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> {$this->username}'s 30-day average.";
                             break;
                     }
                 }
             }
             if ($do7 && !$headline) {
                 $winning_percent = 0;
                 $winning_activity = null;
                 foreach ($activities as $activity => $object_key) {
                     if (isset($baselines['avg_' . $activity . '_count_last_7_days']->value)) {
                         $base_value = $baselines['avg_' . $activity . '_count_last_7_days']->value;
                         $value = $post->{$object_key};
                         $percent_change = $value / ($base_value == 0 ? 1 : $base_value);
                         if ($value > $base_value * 2 && $percent_change > $winning_percent) {
                             $winning_percent = $percent_change;
                             $winning_activity = $activity;
                             $winning_multiplier = floor($value / $base_value);
                         }
                     }
                 }
                 if ($winning_activity) {
                     $slug = $winning_activity . '_spike_7_day_' . $post->id;
                     $emphasis = Insight::EMPHASIS_LOW;
                     $my_insight_posts = array($post);
                     switch ($winning_activity) {
                         case 'fave':
                             $headline = $this->username . ' hit a nerve this week';
                             $insight_text = "<strong>" . number_format($post->favlike_count_cache) . " people</strong> " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post') . ", more than <strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> {$this->username}'s 7-day average.";
                             break;
                         case 'reply':
                             $plural = $post->reply_count_cache == 1 ? InsightTerms::SINGULAR : InsightTerms::PLURAL;
                             $headline = $this->username . " got <strong>" . number_format($post->reply_count_cache) . " " . $this->terms->getNoun('reply', $plural) . '</strong>';
                             $insight_text = "That's more than <strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> {$this->username}'s 7-day average.";
                             break;
                         case 'retweet':
                             $headline = "<strong>" . number_format($post->all_retweets) . " people</strong> thought {$this->username} " . "was worth " . $present_tense_share_verb;
                             $insight_text = "That's more than <strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> {$this->username}'s average over the last 7 days.";
                             break;
                     }
                 }
             }
             if (isset($slug) && isset($headline)) {
                 // Clean up previous insights for this post
                 $to_delete = array('fave_high_365', 'fave_high_30', 'fave_high_7', 'fave_spike_30', 'fave_spike_7', 'reply_high_365', 'reply_high_30', 'reply_high_7', 'reply_spike_30', 'reply_spike_7', 'retweet_high_365', 'retweet_high_30', 'retweet_high_7', 'retweet_spike_30', 'retweet_spike_7');
                 foreach ($to_delete as $base_slug) {
                     $delete_slug = $base_slug . '_day_' . $post->id;
                     if ($slug != $delete_slug) {
                         $this->insight_dao->deleteInsight($delete_slug, $instance->id, $post_date);
                     }
                 }
                 $my_insight = new Insight();
                 $my_insight->slug = $slug;
                 $my_insight->instance_id = $instance->id;
                 $my_insight->date = $post_date;
                 $my_insight->headline = $headline;
                 $my_insight->text = $insight_text;
                 $my_insight->header_image = '';
                 $my_insight->filename = basename(__FILE__, ".php");
                 $my_insight->emphasis = $emphasis;
                 if (isset($my_insight_posts)) {
                     $my_insight->setPosts($my_insight_posts);
                 }
                 $this->insight_dao->insertInsight($my_insight);
             }
             $headline = null;
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:101,代码来源:activityspike.php

示例14: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $year = date('Y');
     $regenerate = false;
     //testing
     //$regenerate = true;
     $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date);
     if ($should_generate_insight) {
         $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
         $insight = new Insight();
         $insight->instance_id = $instance->id;
         $insight->slug = $this->slug;
         $insight->date = "{$year}-{$this->run_date}";
         $post_dao = DAOFactory::getDAO('PostDAO');
         $network = $instance->network;
         $last_year_of_posts = $post_dao->getThisYearOfPostsWithLinksIterator($author_id = $instance->network_user_id, $network = $network);
         $domain_counts = $this->getDomainCounts($last_year_of_posts);
         $this->logger->logInfo("Got domain counts ", __METHOD__ . ',' . __LINE__);
         $popular_domain = $this->getPopularDomain($domain_counts);
         $this->logger->logInfo("Got popular domain " . Utils::varDumpToString($popular_domain), __METHOD__ . ',' . __LINE__);
         $posts = $this->getMostPopularPostsLinkingTo($instance, $popular_domain);
         $this->logger->logInfo("Got popular posts linking to ", __METHOD__ . ',' . __LINE__);
         $most_recent_unexpanded_link_date = $post_dao->getMostRecentUnexpandedLinkPubDate($instance);
         if (isset($most_recent_unexpanded_link_date)) {
             $this->logger->logInfo("Most recent unexpanded link date is " . $most_recent_unexpanded_link_date . " - " . date('Y-m-d', strtotime($most_recent_unexpanded_link_date)), __METHOD__ . ',' . __LINE__);
         } else {
             $this->logger->logInfo("No links have gone unexpanded ", __METHOD__ . ',' . __LINE__);
         }
         $qualified_year = "";
         if (isset($most_recent_unexpanded_link_date) && date('Y', strtotime($most_recent_unexpanded_link_date)) == date('Y')) {
             if (date('n', strtotime($most_recent_unexpanded_link_date)) > 1) {
                 //not January
                 //Earliest post was this year; figure out what month we have data since this year
                 $since = date('F', strtotime($most_recent_unexpanded_link_date));
                 $qualified_year = " (at least since " . $since . ")";
             }
         }
         $copy = array('twitter' => array('normal' => array('headline' => "ICYMI: %username's most linked-to site of {$year}", 'body' => "What's Twitter without the tabs? In {$year}, %username " . "shared more #content from <strong>%domain</strong> than from any other web " . "site%qualified_year. These were %username's most popular tweets with a link to " . "<strong>%domain</strong>."), 'one' => array('headline' => "ICYMI: %username's most linked-to site of {$year}", 'body' => "What's Twitter without the tabs? In {$year}, %username " . "shared more #content from <strong>%domain</strong> than from any other web " . "site%qualified_year. This was %username's most popular tweet with a link to " . "<strong>%domain</strong>."), 'none' => array('headline' => "%username tweeted nary a link in {$year}", 'body' => "This year, %username didn't post a single link on " . "Twitter%qualified_year. You can do better than that, internet!")), 'facebook' => array('normal' => array('headline' => "%username's most-shared site of {$year}", 'body' => "Looks like <strong>%domain</strong> owes %username a thank you. In " . "{$year}, %username directed friends to <strong>%domain</strong> more than " . "to any other site%qualified_year. Here are the posts with links to " . "<strong>%domain</strong>."), 'one' => array('headline' => "%username's most-shared site of {$year}", 'body' => "Looks like <strong>%domain</strong> owes %username a thank you. In " . "{$year}, %username directed friends to <strong>%domain</strong> more than " . "to any other site%qualified_year. Here is the post that links to <strong>%domain</strong>."), 'none' => array('headline' => "%username shared no links in {$year}", 'body' => "%username didn't share any links on Facebook this year%qualified_year. " . "Maybe the internet will do better in 2015!")));
         if (sizeof($posts) > 1) {
             $type = 'normal';
         } else {
             if (sizeof($posts) == 1) {
                 $type = 'one';
             } else {
                 $type = 'none';
                 //Don't show this insight if there are no multiple posts linking to a single popular domain
                 return;
             }
         }
         $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']));
         $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('domain' => str_replace('www.', '', $popular_domain), 'qualified_year' => $qualified_year));
         $insight->headline = $headline;
         $insight->text = $insight_text;
         //Avoid InsightFieldExceedsMaxLengthException
         $posts = array_slice($posts, 0, 12);
         //Avoid broken avatars
         foreach ($posts as $post) {
             $post->author_avatar = $user->avatar;
         }
         $insight->setPosts($posts);
         $insight->filename = basename(__FILE__, ".php");
         $insight->emphasis = Insight::EMPHASIS_HIGH;
         $this->insight_dao->insertInsight($insight);
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:Nitin216,项目名称:ThinkUp,代码行数:68,代码来源:eoymostlinks.php

示例15: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     if (Utils::isTest() || date("Y-m-d") == $this->run_date) {
         $this->logger->logInfo("Should generate insight", __METHOD__ . ',' . __LINE__);
         $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-05/starwars.jpg', 'alt_text' => 'RockTrooper', 'credit' => 'Photo: JD Hancock', 'img_link' => 'https://www.flickr.com/photos/jdhancock/4932301604');
         $post_dao = DAOFactory::getDAO('PostDAO');
         $last_year_of_posts = $post_dao->getPostsByUserInRange($author_id = $instance->network_user_id, $network = $instance->network, $from = date('Y-m-d', strtotime('-1 year')), $until = date('Y-m-d'), $order_by = 'pub_date', $direction = 'DESC', $iterator = true, $is_public = false);
         $topics = array('force' => array("star wars", "force awakens", "bb-8", "darth vader", "bb8", "StarWars", "StarWarsDay"));
         $matches = array();
         $matched_posts = array();
         $matched = false;
         //print_r($last_year_of_posts);
         foreach ($last_year_of_posts as $post) {
             foreach ($topics as $key => $strings) {
                 foreach ($strings as $string) {
                     if (preg_match_all('/\\b' . strtolower($string) . '\\b/i', strtolower($post->post_text), $matches)) {
                         $matched = true;
                     }
                     //DEBUG
                     // else {
                     //     $this->logger->logInfo("Didn't find ".$string." in ".$post->post_text,
                     //         __METHOD__.','.__LINE__);
                     // }
                 }
             }
             if ($matched) {
                 $this->logger->logInfo("Matched post " . $post->post_text, __METHOD__ . ',' . __LINE__);
                 $matched_posts[] = $post;
             }
             $matched = false;
         }
         if (count($matched_posts) > 0) {
             $headline = "The Force is strong with " . $this->username . " on #StarWarsDay";
             $insight_text = $this->username . " was ready for Star Wars Day. May the fourth be with you... always.";
             $insight = new Insight();
             $insight->instance_id = $instance->id;
             $insight->slug = $this->slug;
             $insight->date = $this->run_date;
             $insight->headline = $headline;
             $insight->text = $insight_text;
             $insight->filename = basename(__FILE__, ".php");
             $insight->emphasis = Insight::EMPHASIS_HIGH;
             $insight->setHeroImage($hero_image);
             $matched_posts_sliced = array_slice($matched_posts, 0, 20);
             $insight->setPosts($matched_posts_sliced);
             $this->insight_dao->insertInsight($insight);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:52,代码来源:maythefourth.php


注:本文中的Insight::setPosts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。