Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions Model/ActionQuizAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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
*
Expand Down
29 changes: 29 additions & 0 deletions Model/QuizPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
)
);
}
}
37 changes: 37 additions & 0 deletions Model/QuizQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
)
);
}
}