/**
  * Partendo dall'oggetto che la Api Twitter restituisce per ogni tweet, verifica in base alla proprietà <code>id_str</code>
  * se il tweet è già presente nel database. In caso affermativo restituisce true, altrimenti inserisce in nuovo record
  * nel database e lo restituisce.
  * @param mixed $data Oggetto del tweet restituito dalla Api Twitter
  * @return mixed True se il tweet è già presente nel database, altrimenti nuovo record creato
  */
 public static function CreateFromObj($data)
 {
     $tweet = self::find()->where('id_str=:idstr', [':idstr' => $data->id_str])->one();
     if (!$tweet) {
         # Nuovo tweet: lo inserisco nel database
         $tweet = new TwitterTweet();
         $tweet->id_str = $data->id_str;
         $tweet->created = date('Y-m-d H:i:s', strtotime($data->created_at));
         $text = trim(str_replace('#' . Yii::$app->twitter->hashtag, '<span class="hashtag">#' . Yii::$app->twitter->hashtag . '</span>', $data->text));
         $urls = $data->entities->urls;
         if (is_array($urls)) {
             foreach ($urls as $url) {
                 $text = str_replace($url->url, Html::a($url->display_url, $url->expanded_url, array('target' => 'blank')), $text);
             }
         }
         $tweet->text = $text;
         $tweet->save();
         $tweet->refresh();
         return $tweet;
     }
     return true;
 }