Adding add/edit medias see #5714

skala
Julio Montoya 13 years ago
parent 7d49277af9
commit a3cb652bb6
  1. 2
      main/admin/careers.php
  2. 24
      main/exercice/admin.php
  3. 2
      main/exercice/exercice.php
  4. 108
      main/exercice/media.php
  5. 20
      main/exercice/media_question.class.php
  6. 43
      main/exercice/question.class.php
  7. 22
      main/exercice/question_list_admin.inc.php
  8. 13
      main/inc/ajax/model.ajax.php
  9. 6
      main/inc/lib/database.lib.php
  10. 5
      main/inc/lib/display.lib.php

@ -15,7 +15,6 @@ $this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
//Add the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_jqgrid_js();
@ -38,7 +37,6 @@ if ($action == 'add') {
$interbreadcrumb[]=array('url' => '#','name' => get_lang('Careers'));
}
// The header.
Display::display_header($tool_name);
//jqgrid will use this URL to do the selects

@ -306,19 +306,19 @@ if ($modifyIn == 'thisExercise') {
$noPHP_SELF = true;
}
}
$htmlHeadXtra[] = '<script type="text/javascript">
$htmlHeadXtra[] = '<script>
function multiple_answer_true_false_onchange(variable) {
var result = variable.checked;
var id = variable.id;
var weight_id = "weighting_" + id;
var array_result=new Array(); array_result[1]="1"; array_result[0]= "-0.50"; array_result[-1]= "0";
if (result) {
result = 1;
} else {
result = 0;
}
document.getElementById(weight_id).value = array_result[result];
var result = variable.checked;
var id = variable.id;
var weight_id = "weighting_" + id;
var array_result=new Array(); array_result[1]="1"; array_result[0]= "-0.50"; array_result[-1]= "0";
if (result) {
result = 1;
} else {
result = 0;
}
document.getElementById(weight_id).value = array_result[result];
}
@ -328,7 +328,6 @@ $htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/Java
<script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
<script language=\"JavaScript\" type=\"text/javascript\">
<!--
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 7;
@ -338,7 +337,6 @@ var requiredMinorVersion = 0;
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;
// -----------------------------------------------------------------------------
// -->
</script>
<script language=\"VBScript\" type=\"text/vbscript\">

@ -371,6 +371,8 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
echo '<a href="question_pool.php">';
echo Display::return_icon('database.png', get_lang('QuestionPool'), array('style'=>'width:32px'));
echo '</a>';
echo Display::url(Display::return_icon('looknfeel.png', get_lang('Media')), 'media.php?' . api_get_cidreq());
// end question category
echo '<a href="hotpotatoes.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_hotpotatoes.png', get_lang('ImportHotPotatoesQuiz'),'',ICON_SIZE_MEDIUM).'</a>';
// link to import qti2 ...

@ -0,0 +1,108 @@
<?php
use \ChamiloSession as Session;
$language_file = array('exercice','tracking');
// including the global library
require_once '../inc/global.inc.php';
// Access control
api_protect_course_script(true);
$course_id = api_get_course_int_id();
//Add the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_jqgrid_js();
$interbreadcrumb[] = array("url" => "exercice.php", "name" => get_lang('Exercices'));
Display::display_header(get_lang('Media'));
$action = isset($_GET['action']) ? $_GET['action'] : null;
$page_url = "media.php?".api_get_cidreq();
switch ($action) {
case 'add':
$url = $page_url.'&action='.Security::remove_XSS($_GET['action']);
$objQuestion = Question::getInstance(MEDIA_QUESTION);
$form = new FormValidator('question_admin_form','post', $url);
// question form elements
$objQuestion->createForm($form);
$objQuestion->createAnswersForm($form);
if ($form->validate()) {
// question
$objQuestion->processCreation($form, null);
// answers
$objQuestion->processAnswersCreation($form, null);
}
$form->display();
break;
case 'edit':
$url = $page_url.'&action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
$objQuestion = Question::read($_GET['id']);
$form = new FormValidator('question_admin_form','post', $url);
// question form elements
$objQuestion->createForm($form);
$objQuestion->createAnswersForm($form);
$form->addElement('hidden', 'id', intval($_GET['id']));
$defaults = array();
$defaults['questionName'] = $objQuestion->question;
$defaults['questionDescription'] = $objQuestion->description;
$defaults['questionLevel'] = $objQuestion->level;
$defaults['questionCategory'] = $objQuestion->category_list;
$defaults['parent_id'] = $objQuestion->parent_id;
$form->setDefaults($defaults);
$form->display();
if ($form->validate()) {
// question
$objQuestion->processCreation($form, null);
// answers
$objQuestion->processAnswersCreation($form, null);
}
break;
case 'delete':
$objQuestion = Question::read($_GET['id']);
$objQuestion->delete();
break;
}
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_course_exercise_medias';
//The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('Name'), get_lang('Actions'));
//Column config
$column_model = array(
array('name'=>'name', 'index'=>'name', 'width'=>'80', 'align'=>'left'),
array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
);
//Autowidth
$extra_params['autowidth'] = 'true';
//height auto
$extra_params['height'] = 'auto';
//With this function we can add actions to the jgrid (edit, delete, etc)
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
'\';
}';
?>
<script>
$(function() {
<?php
// grid definition see the $career->display() function
echo Display::grid_js('medias', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
?>
});
</script>
<?php
$items = array(
array('content' => Display::return_icon('add.png'), 'url' => $page_url.'&action=add')
);
echo Display::actions($items);
echo Display::grid_html('medias');

@ -14,16 +14,20 @@ class MediaQuestion extends Question {
$this->save_media($params);
}
function save_media($params) {
function save_media($params) {
$table_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$new_params = array(
'c_id' => api_get_course_int_id(),
'question' => $params['questionName'],
'description' => $params['questionDescription'],
'parent_id' => 0,
'type' => MEDIA_QUESTION
);
Database::insert($table_question, $new_params);
'c_id' => api_get_course_int_id(),
'question' => $params['questionName'],
'description' => $params['questionDescription'],
'parent_id' => 0,
'type' => MEDIA_QUESTION
);
if (isset($params['id'])) {
Database::update($table_question, $new_params, array('id = ? and c_id = ?' => array($params['id'], api_get_course_int_id())));
} else {
Database::insert($table_question, $new_params);
}
}
function createAnswersForm ($form) {

@ -28,7 +28,7 @@ define('MULTIPLE_ANSWER_TRUE_FALSE', 11);
define('MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE', 12);
define('ORAL_EXPRESSION', 13);
define('GLOBAL_MULTIPLE_ANSWER', 14);
define('MEDIA_QUESTION', 15); //
define('MEDIA_QUESTION', 15);
//Some alias used in the QTI exports
define('MCUA', 1);
@ -297,8 +297,7 @@ abstract class Question
function updateParentId($id) {
$this->parent_id = intval($id);
}
}
/**
* changes the question description
@ -988,7 +987,7 @@ abstract class Question
* @author - Olivier Brouckaert
* @param - integer $deleteFromEx - exercise ID if the question is only removed from one exercise
*/
function delete($deleteFromEx=0) {
function delete($deleteFromEx = 0) {
$course_id = api_get_course_int_id();
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
@ -996,7 +995,7 @@ abstract class Question
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$id=$this->id;
$id = $this->id;
// if the question must be removed from all exercises
if(!$deleteFromEx) {
@ -1304,7 +1303,7 @@ abstract class Question
* @param FormValidator $form the formvalidator instance
* @param Exercise $objExercise the Exercise instance
*/
function processCreation ($form, $objExercise) {
function processCreation ($form, $objExercise = null) {
$this->updateParentId($form->getSubmitValue('parent_id'));
$this->updateTitle($form->getSubmitValue('questionName'));
$this->updateDescription($form->getSubmitValue('questionDescription'));
@ -1537,12 +1536,38 @@ abstract class Question
return array($img, $explanation);
}
static function get_course_medias($course_id) {
$table_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$result = Database::select('*', $table_question, array('where'=>array('c_id = ? AND parent_id = 0 AND type = ?' =>array($course_id, MEDIA_QUESTION)), 'order'=>'question'));
/**
* Get course medias
* @param int course id
*/
static function get_course_medias($course_id, $start = 0, $limit = 100, $sidx = "question", $sord = "ASC", $where_condition = array()) {
$table_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$default_where = array('c_id = ? AND parent_id = 0 AND type = ?' => array($course_id, MEDIA_QUESTION));
if (!empty($where_condition)) {
//$where_condition
}
$result = Database::select('*', $table_question,
array(
'limit' => " $start, $limit",
'where' => $default_where,
'order' => "$sidx $sord"));
return $result;
}
/**
* Get count course medias
* @param int course id
*/
static function get_count_course_medias($course_id) {
$table_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$result = Database::select('count(*) as count', $table_question, array('where'=>array('c_id = ? AND parent_id = 0 AND type = ?' => array($course_id, MEDIA_QUESTION))),'first');
if ($result && isset($result['count'])) {
return $result['count'];
}
return 0;
}
static function prepare_course_media_select($course_id) {
$medias = self::get_course_medias($course_id);
$media_list = array();

@ -185,10 +185,10 @@ if (!$inATest) {
if ($show_quiz_edition) {
$delete_link = '<a id="delete_'.$id.'" class="opener" href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&deleteQuestion='.$id.'" >'.Display::return_icon('delete.png',get_lang('RemoveFromTest'), array(), ICON_SIZE_SMALL).'</a>';
}
$edit_link = Display::tag('div',$edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
$clone_link = Display::tag('div',$clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
$delete_link = Display::tag('div',$delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
$actions = Display::tag('div',$edit_link.$clone_link.$delete_link, array('class'=>'edition','style'=>'width:100px; right:10px; margin-top: 0px; position: absolute; top: 10%;'));
$edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
$clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
$delete_link = Display::tag('div', $delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
$actions = Display::tag('div', $edit_link.$clone_link.$delete_link, array('class'=>'edition','style'=>'width:100px; right:10px; margin-top: 0px; position: absolute; top: 10%;'));
$title = Security::remove_XSS($objQuestionTmp->selectTitle());
$move = Display::return_icon('all_directions.png',get_lang('Move'), array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;'));
@ -198,11 +198,16 @@ if (!$inATest) {
// Question type
list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
$questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM), array('style'=>$styleType));
// Question category
$question_media = null;
if (!empty($objQuestionTmp->parent_id)) {
$objQuestionMedia = Question::read($objQuestionTmp->parent_id);
$question_media = Display::label($objQuestionMedia->question, 'info');
}
$questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM).$question_media, array('style' => $styleType));
// Question category
$category_labels = Testcategory::return_category_labels($objQuestionTmp->category_list, $category_list);
if (empty($category_labels)) {
@ -216,6 +221,8 @@ if (!$inATest) {
$txtQuestionLevel = '-';
}
$questionLevel = Display::tag('div', $txtQuestionLevel, array('style'=>$styleLevel));
// Question score
$questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore));
@ -224,6 +231,7 @@ if (!$inATest) {
echo '<div class="header_operations">';
echo $questionName;
echo $questionType;
echo $questionCategory;
echo $questionLevel;
echo $questionScore;

@ -176,6 +176,10 @@ if (!$sidx) $sidx = 1;
//@todo rework this
switch ($action) {
case 'get_course_exercise_medias':
$course_id = api_get_course_int_id();
$count = Question::get_count_course_medias($course_id);
break;
case 'get_user_skill_ranking':
$skill = new Skill();
$count = $skill->get_user_list_skill_ranking_count();
@ -292,7 +296,11 @@ $is_allowedToEdit = api_is_allowed_to_edit(null,true) || api_is_allowed_to_edit(
//5. Querying the DB for the elements
$columns = array();
switch ($action) {
switch ($action) {
case 'get_course_exercise_medias':
$columns = array('question');
$result = Question::get_course_medias($course_id, $start, $limit, $sidx, $sord, $where_condition);
break;
case 'get_user_skill_ranking':
$columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank');
$result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition);
@ -587,7 +595,8 @@ $allowed_actions = array('get_careers',
'get_event_email_template',
'get_user_skill_ranking',
'get_extra_fields',
'get_extra_field_options'
'get_extra_field_options',
'get_course_exercise_medias',
);
//5. Creating an obj to return a json

@ -1161,10 +1161,12 @@ class Database {
$clean_columns = (string)$columns;
}
}
$sql = "SELECT $clean_columns FROM $table_name $conditions";
$sql = "SELECT $clean_columns FROM $table_name $conditions";
//var_dump($sql);
$result = self::query($sql);
$array = array();
//if (self::num_rows($result) > 0 ) {
if ($type_result == 'all') {
while ($row = self::fetch_array($result, $option)) {
if (isset($row['id'])) {

@ -1410,6 +1410,11 @@ class Display {
return $html;
}
/**
* Return a list of actions in a div
* @param array array(array('content' => 'Hello', 'url' => 'chamilo.org'));
* @return string
*/
public static function actions($items) {
$html = null;
if (!empty($items)) {

Loading…
Cancel
Save