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/AcountService.php

    r20036 r20338  
    33class AcountService 
    44{ 
     5    /** 
     6     * @var PDO 
     7     */ 
    58    protected $pdo; 
    69     
     
    3639        $smt->bindValue(':delete_flag', $delete_flag, PDO::PARAM_INT); 
    3740        $smt->execute(); 
    38         return $smt->rowCount() === 1 ? true : false; 
     41        return $smt->rowCount() === 1; 
    3942    } 
    4043    function updatePicture($user_id, $image) 
     
    5053        } 
    5154        $smt->execute(); 
    52         return $smt->rowCount() === 1 ? true : false ; 
     55        return $smt->rowCount() === 1; 
    5356    } 
    5457    function updatePassword($user_id, $password) 
     
    6164        $smt->bindValue(':password', $password, PDO::PARAM_STR); 
    6265        $smt->execute(); 
    63         return $smt->rowCount() === 1 ? true : false; 
     66        return $smt->rowCount() === 1; 
    6467    } 
    6568    function updateEmail($user_id, $email) 
     
    7073        $smt->bindValue(':email', $email, PDO::PARAM_STR); 
    7174        $smt->execute(); 
    72         return $smt->rowCount() === 1 ? true : false; 
     75        return $smt->rowCount() === 1; 
    7376    } 
    7477     
     
    9497        $smt->bindValue(':act_key', $act_key, PDO::PARAM_STR); 
    9598        $smt->execute(); 
    96         return $smt->rowCount() === 1 ? true : false ; 
     99        return $smt->rowCount() === 1; 
    97100    } 
    98101     
    99102    function setPrivate($user_id) 
    100103    { 
    101         // @todo 後で実装する 
    102         return true; 
     104        $smt = $this->pdo->prepare(' 
     105            update users set private_flag = 1 where id = :user_id limit 1 
     106        '); 
     107        $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
     108        $smt->execute(); 
     109        return $smt->rowCount() === 1; 
    103110    } 
    104111    function setPublic($user_id) 
    105112    { 
    106         // @todo 後で実装する 
     113        $this->pdo->beginTransaction(); 
     114         
     115        $smt = $this->pdo->prepare(' 
     116            update users set private_flag = 0 where id = :user_id limit 1 
     117        '); 
     118        $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
     119        $smt->execute(); 
     120         
     121        if (!$smt->rowCount() === 1) { 
     122            $this->pdo->rollBack(); 
     123            return false; 
     124        } 
     125         
     126        $smt = $this->pdo->prepare(' 
     127            select * from requests 
     128            where request_id = :user_id 
     129        '); 
     130        $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
     131        $smt->execute(); 
     132        $arr = $smt->fetchAll(PDO::FETCH_ASSOC); // $user_idをリクエストしている行列を得る 
     133        if ($arr == false) { 
     134            $this->pdo->commit(); 
     135            return true; 
     136        } 
     137         
     138        foreach ($arr as $r) { 
     139            $smt = $this->pdo->prepare(' 
     140                insert into  
     141                followers(user_id, follow_id, created_at)  
     142                values(:user_id, :follow_id, NOW()) 
     143            '); 
     144            $smt->bindValue(':user_id', $r['user_id'], PDO::PARAM_INT); 
     145            $smt->bindValue(':follow_id', $user_id, PDO::PARAM_INT); 
     146            $smt->execute(); 
     147        } 
     148         
     149        $smt = $this->pdo->prepare(' 
     150            delete from requests where request_id = :user_id 
     151        '); 
     152        $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
     153        $smt->execute(); 
     154         
     155        $this->pdo->commit(); 
    107156        return true; 
    108157    }