Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Andrew
  5.  * Date: 11/21/2014
  6.  * Time: 7:17 PM
  7.  */
  8.  
  9. public class Account implements IAccount
  10. {
  11.     public static function Create($accountData)
  12.     {
  13.         $newAccount = R::dispense( Model_Account::$beanEntityName );
  14.         $newAccount->import($accountData);
  15.         $newAccount->state = R::enum(Model_Account::$accountStateEnumBeanEntityName . ":enabled");
  16.  
  17.         return R::store($newAccount);
  18.     }
  19.  
  20.     public static function Update($accountData)
  21.     {
  22.         $account = Account::GetById($accountData->id );
  23.  
  24.         if($account == null)
  25.             throw new Exception("Account ". $accountData->id . " could not be found");
  26.         $account->import($accountData);
  27.         R::store($account);
  28.     }
  29.  
  30.     private static function ToggleState($accountId, $state){
  31.         $account = Account::GetById($accountId);
  32.  
  33.         if($account == null)
  34.             throw new Exception("Account ". $accountId . " could not be found");
  35.         $account->state = $state;
  36.         R::store($account);
  37.     }
  38.  
  39.     public static function Disable($accountId)
  40.     {
  41.         Account::ToggleState($accountId,R::enum(Model_Account::$accountStateEnumBeanEntityName . ":disabled") );
  42.     }
  43.  
  44.     public static function Enable($accountId)
  45.     {
  46.         Account::ToggleState($accountId,R::enum(Model_Account::$accountStateEnumBeanEntityName . ":enabled") );
  47.     }
  48.  
  49.     public static function GetById($accountId)
  50.     {
  51.         return R::load( Model_Account::$beanEntityName , $accountId);
  52.     }
  53.  
  54.     public static function GetBySessionToken($sessionTokenId)
  55.     {
  56.         $sessionToken = R::findOne( Model_SessionToken::$beanEntityName , 'tokenId = ?', array( $sessionTokenId));
  57.  
  58.         if($sessionToken == null)
  59.             throw new Exception("Session Token Id provided was invalid");
  60.  
  61.         return $sessionToken->account;
  62.     }
  63. }
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement