Example #1
0
 public function search($text)
 {
     $response = $this->_twitter->search($text);
     $factory = new Factory\Tweet;
     $collection = new Collection\Collection();
     foreach ($response->results as $tweetData) {
         $tweet = $factory->create($tweetData);
         if (!$tweet->hasLocation()) {
             $tweet->setLocation($this->findLocationByUsername($tweet->getFrom()));
         }
         $collection->append($tweet);
     }
     return $collection;
 }
Example #2
0
 public function findAll()
 {
     $response = array();
     $statement = \Kernel\Registry::get('db')->prepare('SELECT * FROM tweets');
     $statement->execute();
     foreach ($statement->fetchAll(\PDO::FETCH_ASSOC) as $item) {
         $response[] = \Application\Model\Factory\Tweet::create($item);
     }
     return $response;
 }
Example #3
0
 public function save()
 {
     try {
         $tweet = Factory\Tweet::create(array('name' => $this->_getParam('name'), 'message' => $this->_getParam('message'), 'timestamp' => time()));
         $repository = new Repository\Tweet();
         $parentTweet = $repository->find($this->_getParam('id'));
         if (!$parentTweet) {
             $repository->save($tweet);
         } else {
             $parentTweet->add($tweet);
             $repository->save($parentTweet);
         }
         $this->getView()->message = 'OK';
     } catch (\InvalidArgumentException $exception) {
         $this->getView()->message = $exception->getMessage();
     }
 }