public function deleteSection($sectionName) { if ($sectionName === null || mb_strlen($sectionName) === 0) { return false; } $section = $this->sectionDao->findBySectionName($sectionName); if ($section !== null) { $nextSection = $this->sectionDao->findPreviousSection($section->sortOrder); if ($nextSection === null) { $nextSection = $this->sectionDao->findNextSection($section->sortOrder); } } else { return false; } $questions = $this->questionDao->findQuestionsBySectionNameList(array($sectionName)); $nextSectionName = isset($nextSection) ? $nextSection->name : null; $lastOrder = $this->questionDao->findLastQuestionOrder($nextSectionName); if ($lastOrder === null) { $lastOrder = 0; } foreach ($questions as $key => $question) { $questions[$key]->sectionName = $nextSectionName; $questions[$key]->sortOrder = ++$lastOrder; } if (count($questions) > 0) { $this->questionDao->batchReplace($questions); } $key = BOL_LanguageService::getInstance()->findKey(self::QUESTION_LANG_PREFIX, $this->getQuestionLangKeyName(self::LANG_KEY_TYPE_QUESTION_SECTION, $sectionName)); if ($key !== null) { BOL_LanguageService::getInstance()->deleteKey($key->id); } $this->sectionDao->deleteById($section->id); return true; }
public function findNearestSection(BOL_QuestionSection $section) { if (empty($section)) { return null; } $nearestSection = $this->sectionDao->findPreviousSection($section); if (empty($nearestSection)) { $nearestSection = $this->sectionDao->findNextSection($section); } if (empty($nearestSection)) { $moveQuestionsToSection = $this->findVisibleNotDeletableSection(); } return $nearestSection; }