コード例 #1
0
 public function deleteAccountType($accountType)
 {
     if (!isset($accountType)) {
         return false;
     }
     $accountTypeName = trim($accountType);
     $account = null;
     $repleaceToAccount = null;
     $prevKey = null;
     $accounts = $this->accountDao->findAll();
     if (count($accounts) <= 1) {
         return false;
     }
     foreach ($accounts as $key => $value) {
         if ($repleaceToAccount === null && $account !== null) {
             $repleaceToAccount = $accounts[$key];
         }
         if ($accountTypeName == $value->name) {
             $account = $value;
             if ($prevKey !== null) {
                 $repleaceToAccount = $accounts[$prevKey];
             }
         }
         $prevKey = $key;
     }
     if ($account === null) {
         return false;
     }
     /* $questions = $this->questionDao->findQuestionsForAccountType($account->name);
             $questionIdList = array();
     
             foreach ( $questions as $key => $value )
             {
                 $questionIdList[] = $value['id'];
             }
     
             $this->deleteQuestion($questionIdList); */
     //$this->userService->replaceAccountTypeForUsers($account->name, $repleaceToAccount->name);
     BOL_QuestionService::getInstance()->deleteUsersRoleByAccountType($account);
     $this->accountToQuestionDao->deleteByAccountType($account->name);
     $key = BOL_LanguageService::getInstance()->findKey(self::QUESTION_LANG_PREFIX, $this->getQuestionLangKeyName(self::LANG_KEY_TYPE_ACCOUNT_TYPE, $account->name));
     if ($key !== null) {
         BOL_LanguageService::getInstance()->deleteKey($key->id);
     }
     $this->accountDao->deleteById($account->id);
     $this->updateQuestionsEditStamp();
     $deleted = (bool) OW::getDbo()->getAffectedRows();
     if ($deleted) {
         $event = new OW_Event(self::EVENT_ON_ACCOUNT_TYPE_DELETE, array('id' => $account->id, 'name' => $account->name));
         OW::getEventManager()->trigger($event);
     }
     return $deleted;
 }