Show
Ignore:
Timestamp:
10/01/08 07:41:06 (3 months ago)
Author:
anatoo
Message:

メール周り追加

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/plain_php/trunk/model/phwittr/FriendshipService.php

    r20036 r20338  
    8080    } 
    8181     
    82     function follow($user_id, $follow_user_name) 
     82    function follow($user_id, $follow_user_id) 
    8383    { 
    8484        $smt = $this->pdo->prepare(' 
    8585            insert into followers(user_id, follow_id, created_at)  
    86             values(:user_id, (select id from users where user_name =  
    87             :follow_user_name), now())'); 
     86            values(:user_id, :follow_user_id, now())'); 
    8887        $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
    89         $smt->bindValue(':follow_user_name', $follow_user_name, PDO::PARAM_STR); 
     88        $smt->bindValue(':follow_user_id', $follow_user_id, PDO::PARAM_INT); 
    9089        $smt->execute(); 
    9190    } 
    9291 
    93     function unfollow($user_id, $follow_user_name) 
     92    function request($user_id, $request_user_id) 
     93    { 
     94        $smt = $this->pdo->prepare(' 
     95            insert into requests(user_id, request_id, created_at)  
     96            values(:user_id, :request_user_id, now()) 
     97        '); 
     98        $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
     99        $smt->bindValue(':request_user_id', $request_user_id, PDO::PARAM_INT); 
     100        $smt->execute(); 
     101    } 
     102     
     103    function accept($user_id, $accept_user_id) 
     104    { 
     105        $this->pdo->beginTransaction(); 
     106        $this->deny($user_id, $accept_user_id); 
     107        $this->follow($accept_user_id, $user_id); 
     108        $this->pdo->commit(); 
     109    } 
     110 
     111    function deny($user_id, $deny_user_id) 
     112    { 
     113        $smt = $this->pdo->prepare( 
     114            'delete from requests where user_id = :deny_user_id and ' . 
     115            'request_id = :user_id'); 
     116        $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
     117        $smt->bindValue(':deny_user_id', $deny_user_id, PDO::PARAM_INT); 
     118        $smt->execute(); 
     119    } 
     120     
     121    function unfollow($user_id, $follow_user_id) 
    94122    { 
    95123        $smt = $this->pdo->prepare( 
    96124            'delete from followers where user_id = :user_id and ' . 
    97             'follow_id = (select id from users where user_name = :follow_user_name)'); 
     125            'follow_id = :follow_user_id'); 
    98126        $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
    99         $smt->bindValue(':follow_user_name', $follow_user_name, PDO::PARAM_STR); 
     127        $smt->bindValue(':follow_user_id', $follow_user_id, PDO::PARAM_INT); 
    100128        $smt->execute(); 
    101129    } 
    102130     
    103      
     131    function isFollowing($user_id, $follow_id) 
     132    { 
     133        $smt = $this->pdo->prepare(' 
     134            select followers.user_id  
     135            from followers  
     136            where user_id = :user_id and follow_id = :follow_id 
     137            limit 1 
     138        '); 
     139        $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
     140        $smt->bindValue(':follow_id', $follow_id, PDO::PARAM_INT); 
     141        $smt->execute(); 
     142         
     143        return $smt->fetch(PDO::FETCH_ASSOC) !== false; 
     144    } 
     145    function isRequesting($user_id, $follow_id) 
     146    { 
     147        $smt = $this->pdo->prepare(' 
     148            select requests.user_id  
     149            from requests 
     150            where user_id = :user_id and request_id = :follow_id 
     151            limit 1 
     152        '); 
     153        $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
     154        $smt->bindValue(':follow_id', $follow_id, PDO::PARAM_INT); 
     155        $smt->execute(); 
     156         
     157        return $smt->fetch(PDO::FETCH_ASSOC) !== false; 
     158    } 
    104159}