Example #1
0
    public function create(\stdClass $data)
    {
        $tweet = new Model\Tweet;
        $tweet->setCreated($data->created_at);
        $tweet->setFrom($data->from_user);
        $tweet->setText($data->text);

        if ($data->geo) {
            $tweet->setLocation(new Model\Location($data->geo->coordinates[0], $data->geo->coordinates[1]));
        }
        return $tweet;
    }
Example #2
0
 public static function create(array $data)
 {
     $tweet = new Model();
     $tweet->setName($data['name']);
     $tweet->setMessage($data['message']);
     $tweet->setTimeStamp($data['timestamp']);
     if (array_key_exists('tweets', $data)) {
         if (is_string($data['tweets'])) {
             $data['tweets'] = unserialize($data['tweets']);
         }
         foreach ($data['tweets'] as $_data) {
             $tweet->add(self::create($_data));
         }
     }
     return $tweet;
 }
Example #3
0
 public function save(Model\Tweet $tweet)
 {
     $tweets = array();
     foreach ($tweet as $item) {
         $tweets[] = array('name' => $item->getName(), 'message' => $item->getMessage(), 'timestamp' => $item->getTimeStamp());
     }
     if ($this->find($tweet->getId())) {
         $sql = 'UPDATE tweets SET tweets=:tweets WHERE id=:id';
         $statement = \Kernel\Registry::get('db')->prepare($sql);
         @$statement->bindParam('id', $tweet->getId(), \PDO::PARAM_STR, 32);
         @$statement->bindParam('tweets', serialize($tweets), \PDO::PARAM_STR);
         return $statement->execute();
     }
     $sql = 'INSERT INTO tweets(id, name, message, timestamp, tweets) VALUES(:id, :name, :message, :timestamp, :tweets)';
     $statement = \Kernel\Registry::get('db')->prepare($sql);
     @$statement->bindParam('id', $tweet->getId(), \PDO::PARAM_STR, 32);
     @$statement->bindParam('name', $tweet->getName(), \PDO::PARAM_STR, 32);
     @$statement->bindParam('message', $tweet->getMessage(), \PDO::PARAM_STR, 160);
     @$statement->bindParam('timestamp', $tweet->getTimeStamp(), \PDO::PARAM_INT);
     @$statement->bindParam('tweets', serialize($tweets), \PDO::PARAM_STR);
     return $statement->execute();
 }
Example #4
0
 public function isSatisfiedBy(Tweet $tweet)
 {
     return !$this->_collection->has($tweet->getFrom());
 }
Example #5
0
 public function isSatisfiedBy(Tweet $tweet)
 {
     return $tweet->hasLocation();
 }