Skip to content

Commit

Permalink
Add question search form by id in admin see BT#15231
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Feb 13, 2019
1 parent 1f4c0cd commit 640d369
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions main/admin/index.php
Expand Up @@ -199,6 +199,7 @@
}

$items[] = ['url' => 'extra_fields.php?type=course', 'label' => get_lang('ManageCourseFields')];
$items[] = ['url' => 'questions.php', 'label' => get_lang('Questions')];

$blocks['courses']['items'] = $items;
$blocks['courses']['extra'] = null;
Expand Down
68 changes: 68 additions & 0 deletions main/admin/questions.php
@@ -0,0 +1,68 @@
<?php
/* For licensing terms, see /license.txt */

use Chamilo\CourseBundle\Entity\CQuizQuestion;

/**
* @package chamilo.admin
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';

$this_section = SECTION_PLATFORM_ADMIN;

api_protect_admin_script();

$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];

$form = new FormValidator('admin_questions', 'get');
$form->addHeader(get_lang('Questions'));
$form->addText('id', get_lang('Id'));
$form->addButtonSearch(get_lang('Search'));

$formContent = $form->returnForm();
$questionContent = '';

if ($form->validate()) {
$id = (int) $form->getSubmitValue('id');
if (!empty($id)) {
$em = Database::getManager();
/** @var CQuizQuestion $question */
$question = $em->getRepository('ChamiloCourseBundle:CQuizQuestion')->find($id);
if ($question) {
// Creating empty exercise
$exercise = new Exercise();
$exercise->course_id = $question->getCId();
ob_start();
ExerciseLib::showQuestion(
$exercise,
$id,
false,
null,
null,
false,
true,
false,
true,
true
);

$questionContent = "<h3>#".$question->getIid()."</h3>";
$questionContent .= "<h4>".Security::remove_XSS($question->getQuestion())."</h4>";
$questionContent .= "<p>".Security::remove_XSS($question->getDescription())."</p>";
$questionContent .= ob_get_contents();

ob_end_clean();
} else {
Display::addFlash(Display::return_message(get_lang('NotFound')));
header('Location:' .api_get_self());
exit;
}
}
}

$tpl = new Template(get_lang('Questions'));
$content = " $formContent $questionContent ";

$tpl->assign('content', $content);
$tpl->display_one_col_template();

0 comments on commit 640d369

Please sign in to comment.