Example #1
0
 /**
  * create mapped account to revelant process
  * @param int $userId
  * @param string $service
  * @param string $identity
  */
 public function createAccount($userId, $identity, $service, $data = array())
 {
     $table = Engine_Api::_()->getDbtable('Accounts', 'SocialConnect');
     $table->delete("identity='{$identity}' AND service='{$service}'");
     $table->insert(array('user_id' => $userId, 'identity' => $identity, 'service' => $service, 'profile' => json_encode($data)));
     switch ($service) {
         case 'twitter':
             if (class_exists('User_Model_DbTable_Twitter')) {
                 $table = new User_Model_DbTable_Twitter();
                 $account = $table->fetchRow($table->select()->where('user_id=?', $userId));
                 if ($account) {
                     $account->delete();
                 }
                 $table->insert(array('user_id' => $userId, 'twitter_uid' => $identity, 'twitter_token' => '', 'twitter_secret' => ''));
             }
             break;
         case 'facebook':
             if (class_exists('User_Model_DbTable_Facebook')) {
                 $table = new User_Model_DbTable_Facebook();
                 $account = $table->fetchRow($table->select()->where("user_id = {$userId} OR facebook_uid = {$identity}"));
                 if ($account) {
                     $account->delete();
                 }
                 $table->insert(array('user_id' => $userId, 'facebook_uid' => $identity, 'access_token' => '', 'code' => '', 'expires' => ''));
             }
             break;
     }
 }