Exemple #1
0
 public static function create($user)
 {
     $manager = new TransactionManager();
     $transaction = $manager->get();
     $user->setTransaction($transaction);
     if (true !== $user->create()) {
         $transaction->rollback("create user failed");
         return false;
     }
     $userId = sprintf("%s='%s'", MyConst::FIELD_EMAIL, $user->email);
     $user = MaUser::findFirst($userId);
     if (empty($user)) {
         $transaction->rollback("cannot find user created");
         return false;
     }
     $myspace = new MaTeam();
     $myspace->setTransaction($transaction);
     $myspace->owner = $user->id;
     $myspace->name = 'MyMate';
     $myspace->mission = 'Record My Growths';
     $myspace->flag = MyConst::TEAM_FLAG_MYSPACE;
     if (true !== $myspace->create()) {
         $transaction->rollback("create myspace failed");
         return false;
     }
     $mymate = new MaTeam();
     $mymate->setTransaction($transaction);
     $mymate->owner = $user->id;
     $mymate->name = 'MyMate';
     $mymate->mission = 'Follow and Share Growths With My Closest Friends';
     $mymate->flag = MyConst::TEAM_FLAG_MYMATE;
     if (true !== $mymate->create()) {
         $transaction->rollback("create mymate failed");
         return false;
     }
     $mentora = new MaTeam();
     $mentora->setTransaction($transaction);
     $mentora->owner = $user->id;
     $mentora->name = 'Mentors';
     $mentora->flag = MyConst::TEAM_FLAG_MENTOR;
     if (true !== $mentora->create()) {
         $transaction->rollback("create mentora failed");
         return false;
     }
     $newbie = new MaTeam();
     $newbie->setTransaction($transaction);
     $newbie->owner = $user->id;
     $newbie->name = 'Students';
     $newbie->flag = MyConst::TEAM_FLAG_MENTOR;
     if (true !== $newbie->create()) {
         $transaction->rollback("create newbie failed");
         return false;
     }
     $transaction->commit();
     return true;
 }