Ejemplo n.º 1
0
 public function saveTwitterUser(TwitterUserEntity $twitterUser, $setFoodtruck = false)
 {
     $hydrator = new ClassMethods();
     $data = $hydrator->extract($twitterUser);
     $select = $this->sql->select();
     //$whereArr = array('screen_name' => $twitterUser->getScreenName());
     $whereArr = array('twitter_id' => $twitterUser->getTwitterId());
     $select->where($whereArr);
     $statement = $this->sql->prepareStatementForSqlObject($select);
     echo "<br><br>" . $select->getSqlString($this->dbAdapter->getPlatform());
     $results = $statement->execute();
     //echo "\n".$results->count()."\n";
     //$results->current();
     if ($results->count() > 0) {
         // update action
         $action = $this->sql->update();
         $rows = new ResultSet();
         $arr = $rows->initialize($results)->toArray();
         $isFoodtruck = (int) $arr[0]['foodtruck'];
         if ($setFoodtruck == false) {
             unset($data['foodtruck']);
         }
         $action->set($data);
         $action->where(array('screen_name' => $twitterUser->getScreenName()));
         $data['foodtruck'] = $isFoodtruck;
     } else {
         // insert action
         $action = $this->sql->insert();
         $action->values($data);
     }
     $statement = $this->sql->prepareStatementForSqlObject($action);
     echo "<br><br>\n" . $action->getSqlString($this->dbAdapter->getPlatform()) . "\n";
     $result = $statement->execute();
     // save profile pic to blvd users
     // TODO use $results to see if profile image url is already set in db
     // TODO dont' iterate over blvdEntity
     // TODO use service locator to get BlvdMapper
     $blvdMapper = new BlvdMapper($this->dbAdapter);
     //this needs to be done manually as instagram may have added them already
     if ($blvdMapper->getBlvdWithTwitterUsername($twitterUser->getScreenName()) == false) {
         $blvdMapper->saveTwitterUserToBlvd($twitterUser);
     }
     if ($twitterUser->getProfileImageUrl() != '') {
         if ($blvdEntity = $blvdMapper->getBlvdWithTwitterUsername($twitterUser->getScreenName())) {
             foreach ($blvdEntity as $key => $ent) {
                 $ent->setProfilePictureUrl($twitterUser->getProfileImageUrl());
                 $blvdMapper->saveBlvd($ent);
                 break;
             }
         }
     }
     $hydrator = new ClassMethods();
     $twitterUser = new TwitterUserEntity();
     $hydrator->hydrate($data, $twitterUser);
     return $twitterUser;
     return $result;
 }