*/
protected $data;
- public function __construct($quiz, $dest, $forceScorm = false)
+ public function __construct($quiz, $dest, $theme = null, $forceScorm = false)
{
$this->quiz = $quiz instanceof Quiz ? $quiz : Quiz::withoutGlobalScopes()->find($quiz);
- $this->theme = $this->quiz->getTheme();
+ $this->theme = $theme ?? $this->quiz->getTheme();
$this->compilePath = protected_path($this->getBaseURL() . '/compile/' . $this->quiz->id);
$this->dest = $dest;
$this->forceScorm = $forceScorm;
}
$nointerface = !!request('nointerface', false);
$shortLoading = !!request('shortLoading', false);
+ $forceTheme = false;
- self::_getQuizAndTheme($id, $hash, $quiz, $theme);
+ self::_getQuizAndTheme($id, $hash, $quiz, $theme, $forceTheme);
if (null === $time || ((null === $path || $path === 'index.html') && $time > 0 && $time < (time() - 60) && !$nointerface && !$shortLoading)) {
$url = backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time()) . '/' . $q;
return $this->loadingCompile($url, $id, $hash);
}
- return $this->preview($quiz, $theme, $path);
+ return $this->preview($quiz, $theme, $forceTheme, $path);
}
* @param string $path
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Foundation\Application|\Illuminate\Http\Response
*/
- protected function preview($quiz, $theme, $path = 'index.html')
+ protected function preview($quiz, $theme, $forceTheme = false, $path = 'index.html')
{
- $dest = protected_path('quiz/final/' . $quiz->id);
+ $id = $forceTheme ? $quiz->id . '-' . $theme->id : $quiz->id;
+
+ $dest = protected_path('quiz/final/' . $id);
if ($path === 'index.html') {
- $quiz->compile($dest);
+ $quiz->compile($dest, $theme);
}
$p = $dest . '/' . $path;
return response(null)->header('Content-Type', Files::_getMimeType($p))->header('X-Sendfile', $p);
{
PHP::neverStop(false);
- self::_getQuizAndTheme($id, $hash, $quiz, $theme);
+ self::_getQuizAndTheme($id, $hash, $quiz, $theme, $forceTheme);
if (null === $theme || null === $quiz) {
abort(404);
}
* @param $theme QuizTheme
* @return void
*/
- protected static function _getQuizAndTheme($id, $hash, &$quiz, &$theme)
+ protected static function _getQuizAndTheme($id, $hash, &$quiz, &$theme, &$forceTheme)
{
$ee = explode('-', $id);
$forceThemeData = request('theme', false);
if (null === $quiz) {
abort(404, __('Lien de prévisualisation invalide'));
}
- if (!isset($theme)) {
+ if (!isset($theme) || $quiz->theme === $theme->id) {
+ $forceTheme = false;
$theme = $quiz->getTheme();
+ } else {
+ $forceTheme = true;
}
}
}
* @param $quiz self
* @throws \JsonException
*/
- public function compile($dest, $forceScorm = false, $user = null)
+ public function compile($dest, $theme = null, $forceScorm = false, $user = null)
{
- $job = new QuizCompiler($this, $dest, $forceScorm);
+ $job = new QuizCompiler($this, $dest, $theme, $forceScorm);
$job->handle();
}