diff --git a/Model/ActionQuizAdd.php b/Model/ActionQuizAdd.php index 5b488ee..ad7f0f8 100644 --- a/Model/ActionQuizAdd.php +++ b/Model/ActionQuizAdd.php @@ -249,7 +249,38 @@ protected function _getQuizCloneById($quizId) { )); // ID値のみクリア $this->clearQuizId($quiz); + // Wysiwygエディタ内のファイルの複製処理 + $quiz = $this->_copyWysiwygFiles($quiz); + return $quiz; + } +/** + * _copyWysiwygFiles + * + * 引数で指定された小テストの中を分析し、 + * ウィジウィグに設定されているファイルは複製を作ります + * + * @param array $quiz 小テストデータ + * @return array $quiz 複製を作り終えた小テストデータ + */ + protected function _copyWysiwygFiles($quiz) { + $wysiswyg = new WysiwygZip(); + $flatQuiz = Hash::flatten($quiz); + foreach ($flatQuiz as $key => &$value) { + $model = null; + $model = $this->__getModelFromDataName($key); + if (!$model) { + continue; + } + $columnName = substr($key, strrpos($key, '.') + 1); + if ($model->hasField($columnName)) { + if ($model->getColumnType($columnName) == 'text') { + $wysiswygZipFile = $wysiswyg->createWysiwygZip($value); + $value = $wysiswyg->getFromWysiwygZip($wysiswygZipFile); + } + } + } + $quiz = Hash::expand($flatQuiz); return $quiz; } @@ -336,13 +367,7 @@ protected function _getQuizzes($folderPath, $quizzes, $importKey) { $flatQuiz = Hash::flatten($q); foreach ($flatQuiz as $key => &$value) { $model = null; - if (strpos($key, 'QuizQuestion.') !== false) { - $model = $this->QuizQuestion; - } elseif (strpos($key, 'QuizPage.') !== false) { - $model = $this->QuizPage; - } elseif (strpos($key, 'Quiz.') !== false) { - $model = $this->Quiz; - } + $model = $this->__getModelFromDataName($key); if (!$model) { continue; } @@ -364,7 +389,24 @@ protected function _getQuizzes($folderPath, $quizzes, $importKey) { } return $quizzes; } - +/** + * __getModelFromDataName + * + * @param string $keyName データフィールド名の頭の部分(モデル名) + * @return Model + */ + private function __getModelFromDataName($keyName) { + if (strpos($keyName, 'QuizQuestion.') !== false) { + $model = $this->QuizQuestion; + } elseif (strpos($keyName, 'QuizPage.') !== false) { + $model = $this->QuizPage; + } elseif (strpos($keyName, 'Quiz.') !== false) { + $model = $this->Quiz; + } else { + $model = false; + } + return $model; + } /** * __checkFingerPrint * diff --git a/Model/QuizPage.php b/Model/QuizPage.php index 715976a..a96934f 100644 --- a/Model/QuizPage.php +++ b/Model/QuizPage.php @@ -330,4 +330,33 @@ public function deleteQuizPage($quizId) { } return true; } + +/** + * getAliveCondition + * 現在使用中状態であるか判断する。CleanUpプラグインで使用 + * + * @param array $key 判断対象のデータのキー + * @return array + */ + public function getAliveCondition($key) { + return array( + 'conditions' => array( + 'QuizPage.key' => $key, + 'OR' => array( + 'Quiz.is_active' => true, + 'Quiz.is_latest' => true, + ), + ), + 'joins' => array( + array( + 'table' => 'quizzes', + 'alias' => 'Quiz', + 'type' => 'INNER', + 'conditions' => array( + 'QuizPage.quiz_id = Quiz.id' + ) + ) + ) + ); + } } diff --git a/Model/QuizQuestion.php b/Model/QuizQuestion.php index 70bf0ff..dab02d1 100644 --- a/Model/QuizQuestion.php +++ b/Model/QuizQuestion.php @@ -389,4 +389,41 @@ public function deleteQuizQuestion($quizPageId) { } return true; } + +/** + * getAliveCondition + * 現在使用中状態であるか判断する。CleanUpプラグインで使用 + * + * @param array $key 判断対象のデータのキー + * @return array + */ + public function getAliveCondition($key) { + return array( + 'conditions' => array( + 'QuizQuestion.key' => $key, + 'OR' => array( + 'Quiz.is_active' => true, + 'Quiz.is_latest' => true, + ), + ), + 'joins' => array( + array( + 'table' => 'quiz_pages', + 'alias' => 'QuizPage', + 'type' => 'INNER', + 'conditions' => array( + $this->alias . '.quiz_page_id = QuizPage.id' + ) + ), + array( + 'table' => 'quizzes', + 'alias' => 'Quiz', + 'type' => 'INNER', + 'conditions' => array( + 'QuizPage.quiz_id = Quiz.id' + ) + ) + ) + ); + } }