Пример #1
0
 public function get()
 {
     $instance = new Socialworth($this->post->url);
     $results = $instance->all();
     // {'total': totalscore, 'facebook': facebookscore , 'twitter': twitterscore}
     // for calculating virality, create totalshares that gives more weight to twitter
     $totalShares = round(($results->facebook + 2 * $results->twitter) / 3 * 2);
     $score = Score::create(['twitter' => $results->twitter, 'facebook' => $results->facebook, 'total' => $results->facebook + $results->twitter, 'virality' => $totalShares > 1 ? round(8 * log($totalShares)) : 2]);
     // save the score
     $score->save();
     // associate to
     $this->post->scores()->save($score);
 }
Пример #2
0
 public function get()
 {
     $instance = new Socialworth($this->post->url);
     $results = $instance->all();
     // {'total': totalscore, 'facebook': facebookscore , 'twitter': twitterscore}
     // for calculating virality, create totalshares that gives more weight to twitter
     $totalShares = round(($results->facebook + 2 * $results->twitter) / 3 * 2);
     if ($this->post->score()->get()->count() > 0) {
         $score = $this->post->score;
     } else {
         $score = new Score();
     }
     $score->twitter = $results->twitter;
     $score->facebook = $results->facebook;
     $score->total = $results->facebook + $results->twitter;
     $score->virality = $totalShares > 1 ? round(8 * log($totalShares)) : 2;
     // save the score
     $score->save();
     // associate to
     $this->post->score()->save($score);
 }