Adding extra field filters for the new question global list see BT#6042

skala
Julio Montoya 12 years ago
parent 4625e10ce6
commit 1de8064eb4
  1. 106
      main/exercice/question.class.php
  2. 46
      main/exercice/unique_answer.class.php
  3. 6
      main/inc/Entity/CQuizQuestion.php
  4. 303
      main/inc/Entity/ExtraField.php
  5. 145
      main/inc/Entity/ExtraFieldValues.php
  6. 16
      main/inc/Entity/QuestionField.php
  7. 184
      main/inc/Entity/QuestionFieldOptions.php
  8. 57
      main/inc/Entity/QuestionFieldValues.php
  9. 12
      main/inc/Entity/Repository/CQuizQuestionRepository.php
  10. 107
      main/inc/ajax/model.ajax.php
  11. 3
      main/inc/lib/display.lib.php
  12. 452
      main/inc/lib/extra_field.lib.php
  13. 3
      main/inc/lib/extra_field_option.lib.php
  14. 131
      main/inc/lib/sessionmanager.lib.php
  15. 5
      main/session/session_list.php
  16. 7
      main/template/default/admin/questionmanager/question_categories.tpl
  17. 122
      main/template/default/admin/questionmanager/questions.tpl
  18. 109
      src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php

@ -1940,7 +1940,7 @@ abstract class Question
return $html;
}
static function question_type_no_review()
public static function question_type_no_review()
{
return array(
HOT_SPOT,
@ -1949,7 +1949,8 @@ abstract class Question
);
}
public static function getMediaLabels() {
public static function getMediaLabels()
{
// Shows media questions
$courseMedias = Question::prepare_course_media_select(api_get_course_int_id());
@ -1965,4 +1966,105 @@ abstract class Question
return $labels;
}
public static function getQuestionColumns()
{
// The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array('id', get_lang('Name'), get_lang('Description'));
// Column config.
$columnModel = array(
array(
'name' => 'iid',
'index' => 'iid',
'width' => '20',
'align' => 'left'
),
array(
'name' => 'question',
'index' => 'question',
'width' => '200',
'align' => 'left'
),
array(
'name' => 'description',
'index' => 'description',
'width' => '100',
'align' => 'left',
'sortable' => 'false'
)
);
$extraField = new \ExtraField('question');
$rules = $extraField->getRules($columns, $columnModel);
$columns[] = get_lang('Actions');
$columnModel[] = array(
'name' => 'actions',
'index' => 'actions',
'width' => '30',
'align' => 'left',
'formatter' => 'action_formatter',
'sortable' => 'false'
);
foreach ($columnModel as $col_model) {
$simple_column_name[] = $col_model['name'];
}
$return_array = array(
'columns' => $columns,
'column_model' => $columnModel,
'rules' => $rules,
'simple_column_name' => $simple_column_name
);
return $return_array;
}
/**
* Get all questions
* @param $options
* @return array
*/
public static function getQuestions($categoryId, $options, $get_count = false)
{
$questionTable = Database::get_course_table(TABLE_QUIZ_QUESTION);
$where = 'WHERE 1 = 1 ';
$extra_field = new ExtraField('question');
$conditions = $extra_field->parseConditions($options);
$inject_joins = $conditions['inject_joins'];
$where .= $conditions['where'];
$inject_where = $conditions['inject_where'];
$inject_extra_fields = $conditions['inject_extra_fields'];
$order = $conditions['order'];
$limit = $conditions['limit'];
if ($get_count == true) {
$select = " SELECT count(*) as total_rows";
} else {
$select = " SELECT s.*, $inject_extra_fields 1";
}
$categoryCondition = null;
if (!empty($categoryId)) {
$categoryRelQuestionTable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$categoryCondition = " INNER JOIN $categoryRelQuestionTable c ON (s.iid = c.question_id)";
$categoryId = intval($categoryId);
$where .= " AND category_id = $categoryId ";
}
$query = " $select FROM $questionTable s $inject_joins $categoryCondition $where $inject_where $order $limit";
$result = Database::query($query);
$questions = array();
if (Database::num_rows($result)) {
$questions = Database::store_result($result, 'ASSOC');
if ($get_count) {
return $questions[0]['total_rows'];
}
}
return $questions;
}
}

@ -143,37 +143,43 @@ class UniqueAnswer extends Question
for ($i = 1; $i <= $nb_answers; ++$i) {
$form->addElement('html', '<tr>');
if (isset($answer) && is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i);
if ($answer->correct[$answer_id]) {
$correct = $i;
}
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['comment['.$i.']'] = $answer->comment[$answer_id];
$defaults['weighting['.$i.']'] = Text::float_format($answer->weighting[$answer_id], 1);
$item_list = explode('@@', $answer->destination[$answer_id]);
$try = $item_list[0];
$lp = $item_list[1];
$list_dest = $item_list[2];
$url = $item_list[3];
if ($try == 0) {
$try_result = 0;
} else {
$try_result = 1;
}
if ($url == 0) {
$url_result = '';
} else {
$url_result = $url;
if (!empty($answer->destination[$answer_id])) {
$item_list = explode('@@', $answer->destination[$answer_id]);
$try = $item_list[0];
$lp = $item_list[1];
$list_dest = $item_list[2];
$url = $item_list[3];
if ($try == 0) {
$try_result = 0;
} else {
$try_result = 1;
}
if ($url == 0) {
$url_result = '';
} else {
$url_result = $url;
}
$temp_scenario['url'.$i] = $url_result;
$temp_scenario['try'.$i] = $try_result;
$temp_scenario['lp'.$i] = $lp;
$temp_scenario['destination'.$i] = $list_dest;
}
$temp_scenario['url'.$i] = $url_result;
$temp_scenario['try'.$i] = $try_result;
$temp_scenario['lp'.$i] = $lp;
$temp_scenario['destination'.$i] = $list_dest;
} else {
$defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1');
$defaults['weighting[1]'] = 10;

@ -106,9 +106,15 @@ class CQuizQuestion
**/
private $quizQuestionRelCategoryList;
/**
* @ORM\OneToMany(targetEntity="QuestionFieldValues", mappedBy="question")
*/
private $extraFields;
public function __construct()
{
$this->quizQuestionRelCategoryList = new ArrayCollection();
$this->extraFields = new ArrayCollection();
}
public function getCategories()

@ -0,0 +1,303 @@
<?php
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* ExtraField
*
* @ORM\MappedSuperclass
*/
class ExtraField
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var integer
*
* @ORM\Column(name="field_type", type="integer", precision=0, scale=0, nullable=false, unique=false)
*/
private $fieldType;
/**
* @var string
*
* @ORM\Column(name="field_variable", type="string", length=64, precision=0, scale=0, nullable=false, unique=false)
*/
private $fieldVariable;
/**
* @var string
*
* @ORM\Column(name="field_display_text", type="string", length=64, precision=0, scale=0, nullable=true, unique=false)
*/
private $fieldDisplayText;
/**
* @var string
*
* @ORM\Column(name="field_default_value", type="text", precision=0, scale=0, nullable=true, unique=false)
*/
private $fieldDefaultValue;
/**
* @var integer
*
* @ORM\Column(name="field_order", type="integer", precision=0, scale=0, nullable=true, unique=false)
*/
private $fieldOrder;
/**
* @var boolean
*
* @ORM\Column(name="field_visible", type="boolean", precision=0, scale=0, nullable=true, unique=false)
*/
private $fieldVisible;
/**
* @var boolean
*
* @ORM\Column(name="field_changeable", type="boolean", precision=0, scale=0, nullable=true, unique=false)
*/
private $fieldChangeable;
/**
* @var boolean
*
* @ORM\Column(name="field_filter", type="boolean", precision=0, scale=0, nullable=true, unique=false)
*/
private $fieldFilter;
/**
* @var \DateTime
*
* @ORM\Column(name="tms", type="datetime", precision=0, scale=0, nullable=false, unique=false)
*/
private $tms;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set fieldType
*
* @param integer $fieldType
* @return ExtraField
*/
public function setFieldType($fieldType)
{
$this->fieldType = $fieldType;
return $this;
}
/**
* Get fieldType
*
* @return integer
*/
public function getFieldType()
{
return $this->fieldType;
}
/**
* Set fieldVariable
*
* @param string $fieldVariable
* @return ExtraField
*/
public function setFieldVariable($fieldVariable)
{
$this->fieldVariable = $fieldVariable;
return $this;
}
/**
* Get fieldVariable
*
* @return string
*/
public function getFieldVariable()
{
return $this->fieldVariable;
}
/**
* Set fieldDisplayText
*
* @param string $fieldDisplayText
* @return ExtraField
*/
public function setFieldDisplayText($fieldDisplayText)
{
$this->fieldDisplayText = $fieldDisplayText;
return $this;
}
/**
* Get fieldDisplayText
*
* @return string
*/
public function getFieldDisplayText()
{
return $this->fieldDisplayText;
}
/**
* Set fieldDefaultValue
*
* @param string $fieldDefaultValue
* @return ExtraField
*/
public function setFieldDefaultValue($fieldDefaultValue)
{
$this->fieldDefaultValue = $fieldDefaultValue;
return $this;
}
/**
* Get fieldDefaultValue
*
* @return string
*/
public function getFieldDefaultValue()
{
return $this->fieldDefaultValue;
}
/**
* Set fieldOrder
*
* @param integer $fieldOrder
* @return ExtraField
*/
public function setFieldOrder($fieldOrder)
{
$this->fieldOrder = $fieldOrder;
return $this;
}
/**
* Get fieldOrder
*
* @return integer
*/
public function getFieldOrder()
{
return $this->fieldOrder;
}
/**
* Set fieldVisible
*
* @param boolean $fieldVisible
* @return ExtraField
*/
public function setFieldVisible($fieldVisible)
{
$this->fieldVisible = $fieldVisible;
return $this;
}
/**
* Get fieldVisible
*
* @return boolean
*/
public function getFieldVisible()
{
return $this->fieldVisible;
}
/**
* Set fieldChangeable
*
* @param boolean $fieldChangeable
* @return ExtraField
*/
public function setFieldChangeable($fieldChangeable)
{
$this->fieldChangeable = $fieldChangeable;
return $this;
}
/**
* Get fieldChangeable
*
* @return boolean
*/
public function getFieldChangeable()
{
return $this->fieldChangeable;
}
/**
* Set fieldFilter
*
* @param boolean $fieldFilter
* @return ExtraField
*/
public function setFieldFilter($fieldFilter)
{
$this->fieldFilter = $fieldFilter;
return $this;
}
/**
* Get fieldFilter
*
* @return boolean
*/
public function getFieldFilter()
{
return $this->fieldFilter;
}
/**
* Set tms
*
* @param \DateTime $tms
* @return ExtraField
*/
public function setTms($tms)
{
$this->tms = $tms;
return $this;
}
/**
* Get tms
*
* @return \DateTime
*/
public function getTms()
{
return $this->tms;
}
}

@ -0,0 +1,145 @@
<?php
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* ExtraFieldValues
*
* @ORM\MappedSuperclass
*/
class ExtraFieldValues
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var integer
*
* @ORM\Column(name="field_id", type="integer", precision=0, scale=0, nullable=false, unique=false)
*/
private $fieldId;
/**
* @var string
*
* @ORM\Column(name="field_value", type="text", precision=0, scale=0, nullable=true, unique=false)
*/
private $fieldValue;
/**
* @var \DateTime
*
* @ORM\Column(name="tms", type="datetime", precision=0, scale=0, nullable=false, unique=false)
*/
private $tms;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set questionId
*
* @param integer $questionId
* @return ExtraFieldValues
*/
public function setQuestionId($questionId)
{
$this->questionId = $questionId;
return $this;
}
/**
* Get questionId
*
* @return integer
*/
public function getQuestionId()
{
return $this->questionId;
}
/**
* Set fieldId
*
* @param integer $fieldId
* @return ExtraFieldValues
*/
public function setFieldId($fieldId)
{
$this->fieldId = $fieldId;
return $this;
}
/**
* Get fieldId
*
* @return integer
*/
public function getFieldId()
{
return $this->fieldId;
}
/**
* Set fieldValue
*
* @param string $fieldValue
* @return ExtraFieldValues
*/
public function setFieldValue($fieldValue)
{
$this->fieldValue = $fieldValue;
return $this;
}
/**
* Get fieldValue
*
* @return string
*/
public function getFieldValue()
{
return $this->fieldValue;
}
/**
* Set tms
*
* @param \DateTime $tms
* @return ExtraFieldValues
*/
public function setTms($tms)
{
$this->tms = $tms;
return $this;
}
/**
* Get tms
*
* @return \DateTime
*/
public function getTms()
{
return $this->tms;
}
}

@ -0,0 +1,16 @@
<?php
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* QuestionField
*
* @ORM\Table(name="question_field")
* @ORM\Entity
*/
class QuestionField extends ExtraField
{
}

@ -0,0 +1,184 @@
<?php
use Doctrine\ORM\Mapping as ORM;
/**
* SessionFieldOptions
*
* @ORM\Table(name="session_field_options")
* @ORM\Entity
*/
class SessionFieldOptions
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var integer
*
* @ORM\Column(name="field_id", type="integer", precision=0, scale=0, nullable=false, unique=false)
*/
private $fieldId;
/**
* @var string
*
* @ORM\Column(name="option_value", type="text", precision=0, scale=0, nullable=true, unique=false)
*/
private $optionValue;
/**
* @var string
*
* @ORM\Column(name="option_display_text", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
*/
private $optionDisplayText;
/**
* @var integer
*
* @ORM\Column(name="option_order", type="integer", precision=0, scale=0, nullable=true, unique=false)
*/
private $optionOrder;
/**
* @var \DateTime
*
* @ORM\Column(name="tms", type="datetime", precision=0, scale=0, nullable=false, unique=false)
*/
private $tms;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set fieldId
*
* @param integer $fieldId
* @return SessionFieldOptions
*/
public function setFieldId($fieldId)
{
$this->fieldId = $fieldId;
return $this;
}
/**
* Get fieldId
*
* @return integer
*/
public function getFieldId()
{
return $this->fieldId;
}
/**
* Set optionValue
*
* @param string $optionValue
* @return SessionFieldOptions
*/
public function setOptionValue($optionValue)
{
$this->optionValue = $optionValue;
return $this;
}
/**
* Get optionValue
*
* @return string
*/
public function getOptionValue()
{
return $this->optionValue;
}
/**
* Set optionDisplayText
*
* @param string $optionDisplayText
* @return SessionFieldOptions
*/
public function setOptionDisplayText($optionDisplayText)
{
$this->optionDisplayText = $optionDisplayText;
return $this;
}
/**
* Get optionDisplayText
*
* @return string
*/
public function getOptionDisplayText()
{
return $this->optionDisplayText;
}
/**
* Set optionOrder
*
* @param integer $optionOrder
* @return SessionFieldOptions
*/
public function setOptionOrder($optionOrder)
{
$this->optionOrder = $optionOrder;
return $this;
}
/**
* Get optionOrder
*
* @return integer
*/
public function getOptionOrder()
{
return $this->optionOrder;
}
/**
* Set tms
*
* @param \DateTime $tms
* @return SessionFieldOptions
*/
public function setTms($tms)
{
$this->tms = $tms;
return $this;
}
/**
* Get tms
*
* @return \DateTime
*/
public function getTms()
{
return $this->tms;
}
}

@ -0,0 +1,57 @@
<?php
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* QuestionFieldValues
*
* @ORM\Table(name="question_field_values")
* @ORM\Entity
*/
class QuestionFieldValues extends ExtraFieldValues
{
/**
* @var integer
*
* @ORM\Column(name="question_id", type="integer", precision=0, scale=0, nullable=false, unique=false)
*/
private $questionId;
/**
* @ORM\ManyToOne(targetEntity="CQuizQuestion")
* @ORM\JoinColumn(name="question_id", referencedColumnName="iid")
*/
private $question;
/**
* @ORM\OneToOne(targetEntity="QuestionField")
* @ORM\JoinColumn(name="field_id", referencedColumnName="id")
*/
private $field;
/**
* Set questionId
*
* @param integer $questionId
* @return QuestionFieldValues
*/
public function setQuestionId($questionId)
{
$this->questionId = $questionId;
return $this;
}
/**
* Get questionId
*
* @return integer
*/
public function getQuestionId()
{
return $this->questionId;
}
}

@ -19,19 +19,23 @@ class CQuizQuestionRepository extends EntityRepository
*/
public function getQuestionsByCategory($categoryId)
{
// Setting alias for this class "q" = CQuizQuestion
// Setting alias for this class "q" = CQuizQuestion.
$qb = $this->createQueryBuilder('q');
// Select all question information
// Select all question information.
$qb->select('q');
// Inner join with the table c_quiz_question_rel_category
// Inner join with the table c_quiz_question_rel_category.
$qb->innerJoin('q.quizQuestionRelCategoryList', 'c');
// Inner join with question extra fields.
//$qb->innerJoin('q.extraFields', 'e');
$wherePart = $qb->expr()->andx();
$wherePart->add($qb->expr()->eq('c.categoryId', $categoryId));
$qb->where($wherePart);
//echo $qb->getQuery()->getSQL()."<br>";
return $qb;
}
}
}

@ -118,72 +118,26 @@ if ($_REQUEST['_search'] == 'true') {
}
$filters = isset($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false;
//for now
$extra_field = new ExtraField('session');
// for now
if (!empty($filters)) {
//Getting double select if exists
$double_select = array();
foreach ($filters->rules as $rule) {
if (strpos($rule->field, '_second') === false) {
} else {
$my_field = str_replace('_second', '', $rule->field);
$double_select[$my_field] = $rule->data;
}
switch($action) {
case 'get_questions':
$type = 'question';
break;
case 'get_sessions':
$type = 'session';
break;
}
$condition_array = array();
foreach ($filters->rules as $rule) {
if (strpos($rule->field, 'extra_') === false) {
//normal fields
$field = $rule->field;
if (!empty($rule->data)) {
$condition_array[] = get_where_clause($field, $rule->op, $rule->data);
}
} else {
//Extra fields
//normal
if (strpos($rule->field, '_second') === false) {
//No _second
$original_field = str_replace('extra_', '', $rule->field);
$field_option = $extra_field->get_handler_field_info_by_field_variable($original_field);
if ($field_option['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
if (isset($double_select[$rule->field])) {
$data = explode('#', $rule->data);
$rule->data = $data[1].'::'.$double_select[$rule->field];
} else {
// only was sent 1 select
$data = explode('#', $rule->data);
$rule->data = $data[1];
}
if (!empty($rule->data)) {
$condition_array[] = ' ('.get_where_clause($rule->field, $rule->op, $rule->data).') ';
$extra_fields[] = array('field' => $rule->field, 'id' => $field_option['id']);
}
} else {
if (!empty($rule->data)) {
$condition_array[] = ' ('.get_where_clause($rule->field, $rule->op, $rule->data).') ';
$extra_fields[] = array('field' => $rule->field, 'id' => $field_option['id']);
}
}
} else {
$my_field = str_replace('_second', '', $rule->field);
$original_field = str_replace('extra_', '', $my_field);
$field_option = $extra_field->get_handler_field_info_by_field_variable($original_field);
$extra_fields[] = array('field' => $rule->field, 'id' => $field_option['id']);
}
}
}
$extraField = new ExtraField($type);
$result = $extraField->getExtraFieldRules($filters);
$extra_fields = $result['extra_fields'];
$condition_array = $result['condition_array'];
if (!empty($condition_array)) {
$where_condition .= ' AND ( ';
$where_condition .= implode($filters->groupOp, $condition_array);
$where_condition .= ' ) ';
}
}
@ -202,9 +156,13 @@ switch ($action) {
case 'get_questions':
$categoryId = isset($_REQUEST['categoryId']) ? $_REQUEST['categoryId'] : null;
/** @var \Doctrine\ORM\EntityManager $em */
$em = $app['orm.em'];
/*$em = $app['orm.em'];
$repo = $em->getRepository('Entity\CQuizQuestionRelCategory');
$count = $repo->getCountQuestionByCategory($categoryId);
$count = $repo->getCountQuestionByCategory($categoryId);*/
if (isset($_REQUEST['categoryId'])) {
$categoryId = intval($_REQUEST['categoryId']);
}
$count = Question::getQuestions($categoryId, array('where'=> $where_condition, 'extra' => $extra_fields), true);
break;
case 'get_user_list_plugin_widescale':
$count = UserManager::get_user_data(null, null, null, null, true);
@ -252,7 +210,7 @@ switch ($action) {
}
$count = ExerciseLib::get_count_exam_results($exercise_id, $where_condition);
break;
case 'get_hotpotatoes_exercise_results':
case 'get_hotpotatoes_exercise_results':
$hotpot_path = $_REQUEST['path'];
$count = ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
break;
@ -340,17 +298,17 @@ if (isset($_REQUEST['oper']) && $_REQUEST['oper'] == 'del') {
$obj->delete($_REQUEST['id']);
}
$is_allowedToEdit = api_is_allowed_to_edit(null,true) || api_is_allowed_to_edit(true) || api_is_drh();
$is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh();
//5. Querying the DB for the elements
$columns = array();
switch ($action) {
case 'get_questions':
$columns = array('iid', 'question', 'description', 'actions');
// @todo implement a class that manages jqgrid petitions
/** @var \Entity\Repository\CQuizQuestionRepository $repo */
$repo = $em->getRepository('Entity\CQuizQuestion');
/*$repo = $em->getRepository('Entity\CQuizQuestion');
var_dump($where_condition, $extra_fields);
$qb = $repo->getQuestionsByCategory($categoryId);
if (!empty($sidx) && strlen($sidx) > 1) {
$sidx = 'q.'.$sidx;
@ -361,22 +319,15 @@ switch ($action) {
$qb->getMaxResults($limit);
$query = $qb->getQuery();
//echo $qb->getQuery()->getSQL();
$questions = $query->getResult();
$questions = $query->getResult();*/
/** @var \Entity\CQuizCategory $category */
/*$category = $repo->find($categoryId);
$questions = $category->getQuestions();*/
$columns = Question::getQuestionColumns();
$columns = $columns['simple_column_name'];
$result = Question::getQuestions($categoryId, array('where'=> $where_condition, 'order'=>"$sidx $sord", 'extra' => $extra_fields, 'limit'=> "$start , $limit"));
$result = array();
foreach ($questions as $question) {
$row = array();
$row['iid'] = $question->getIid();
$row['question'] = $question->getQuestion();
$row['description'] = $question->getDescription();
//$row['iid'] = $question->getIid();
//$row['iid'] = $question->getIid();
$result[] = $row;
}
break;
case 'get_user_list_plugin_widescale':
$columns = array('username', 'firstname', 'lastname', 'exam_password');
@ -426,8 +377,8 @@ switch ($action) {
$column_names[] = $extra['3'];
}
}
$result = CourseManager::get_user_list_from_course_code(null, null, "LIMIT $start, $limit", " $sidx $sord", null, null, true);
break;
$result = CourseManager::get_user_list_from_course_code(null, null, "LIMIT $start, $limit", " $sidx $sord", null, null, true);
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);
@ -797,4 +748,4 @@ if (in_array($action, $allowed_actions)) {
}
echo json_encode($response);
}
exit;
exit;

@ -1104,7 +1104,6 @@ class Display
$all_text = addslashes(get_lang('All'));
$json .= '$("'.$obj->pager.' option[value='.$all_value.']").text("'.$all_text.'");';
$json .= "\n";
//Adding edit/delete icons
@ -1846,4 +1845,4 @@ class Display
}
return $html;
}
}
}

@ -46,6 +46,7 @@ class ExtraField extends Model
//Used for the model
$this->table = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
$this->handler_id = 'course_code';
$this->primaryKey = 'id';
break;
case 'user':
$this->table_field_options = Database::get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
@ -54,6 +55,7 @@ class ExtraField extends Model
//Used for the model
$this->table = Database::get_main_table(TABLE_MAIN_USER_FIELD);
$this->handler_id = 'user_id';
$this->primaryKey = 'user_id';
break;
case 'session':
$this->table_field_options = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_OPTIONS);
@ -62,21 +64,24 @@ class ExtraField extends Model
//Used for the model
$this->table = Database::get_main_table(TABLE_MAIN_SESSION_FIELD);
$this->handler_id = 'session_id';
$this->primaryKey = 'id';
break;
case 'question':
$this->table_field_options = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_OPTIONS);
$this->table_field_values = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_VALUES);
$this->table_field_options = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_OPTIONS);
$this->table_field_values = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_VALUES);
//Used for the model
$this->table = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD);
$this->table = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD);
$this->handler_id = 'question_id';
$this->primaryKey = 'iid';
break;
}
$this->pageUrl = 'extra_fields.php?type='.$this->type;
$this->pageUrl = 'extra_fields.php?type='.$this->type;
$this->pageName = get_lang(ucwords($this->type).'Fields'); // Example QuestionFields
}
static function getValidExtraFieldTypes() {
static function getValidExtraFieldTypes()
{
return array(
'user',
'course',
@ -501,7 +506,7 @@ class ExtraField extends Model
if (isset($field_details['options']) && !empty($field_details['options'])) {
foreach ($field_details['options'] as $option_details) {
$options[$option_details['option_value']] = $option_details['option_display_text'];
$group[] = $form->createElement(
$group[] = $form->createElement(
'checkbox',
'extra_'.$field_details['field_variable'],
$option_details['option_value'],
@ -548,7 +553,9 @@ class ExtraField extends Model
if (!empty($field_details['options'])) {
foreach ($field_details['options'] as $option_id => $option_details) {
if ($get_lang_variables) {
$options[$option_details['option_value']] = get_lang($option_details['option_display_text']);
$options[$option_details['option_value']] = get_lang(
$option_details['option_display_text']
);
} else {
$options[$option_details['option_value']] = $option_details['option_display_text'];
}
@ -814,13 +821,13 @@ EOF;
function setupBreadcrumb(&$breadcrumb, $action)
{
if ($action == 'add') {
$breadcrumb[]=array('url' => $this->pageUrl,'name' => $this->pageName);
$breadcrumb[]=array('url' => '#','name' => get_lang('Add'));
$breadcrumb[] = array('url' => $this->pageUrl, 'name' => $this->pageName);
$breadcrumb[] = array('url' => '#', 'name' => get_lang('Add'));
} elseif ($action == 'edit') {
$breadcrumb[]=array('url' => $this->pageUrl,'name' => $this->pageName);
$breadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
$breadcrumb[] = array('url' => $this->pageUrl, 'name' => $this->pageName);
$breadcrumb[] = array('url' => '#', 'name' => get_lang('Edit'));
} else {
$breadcrumb[]=array('url' => '#','name' => $this->pageName);
$breadcrumb[] = array('url' => '#', 'name' => $this->pageName);
}
}
@ -832,26 +839,90 @@ EOF;
{
// action links
echo '<div class="actions">';
echo '<a href="../admin/index.php">' . Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM) . '</a>';
echo '<a href="' . api_get_self() . '?action=add&type='.$this->type.'">' . Display::return_icon('add_user_fields.png', get_lang('Add'), '', ICON_SIZE_MEDIUM) . '</a>';
echo '<a href="../admin/index.php">'.Display::return_icon(
'back.png',
get_lang('BackTo').' '.get_lang('PlatformAdmin'),
'',
ICON_SIZE_MEDIUM
).'</a>';
echo '<a href="'.api_get_self().'?action=add&type='.$this->type.'">'.Display::return_icon(
'add_user_fields.png',
get_lang('Add'),
'',
ICON_SIZE_MEDIUM
).'</a>';
echo '</div>';
echo Display::grid_html($this->type.'_fields');
}
public function getJqgridColumnNames() {
return array(get_lang('Name'), get_lang('FieldLabel'), get_lang('Type'), get_lang('FieldChangeability'), get_lang('Visibility'), get_lang('Filter'), get_lang('FieldOrder'), get_lang('Actions'));
public function getJqgridColumnNames()
{
return array(
get_lang('Name'),
get_lang('FieldLabel'),
get_lang('Type'),
get_lang('FieldChangeability'),
get_lang('Visibility'),
get_lang('Filter'),
get_lang('FieldOrder'),
get_lang('Actions')
);
}
public function getJqgridColumnModel() {
public function getJqgridColumnModel()
{
return array(
array('name'=>'field_display_text', 'index'=>'field_display_text', 'width'=>'180', 'align'=>'left'),
array('name'=>'field_variable', 'index'=>'field_variable', 'width'=>'', 'align'=>'left','sortable'=>'true'),
array('name'=>'field_type', 'index'=>'field_type', 'width'=>'', 'align'=>'left','sortable'=>'true'),
array('name'=>'field_changeable', 'index'=>'field_changeable', 'width'=>'50', 'align'=>'left','sortable'=>'true'),
array('name'=>'field_visible', 'index'=>'field_visible', 'width'=>'40', 'align'=>'left','sortable'=>'true'),
array('name'=>'field_filter', 'index'=>'field_filter', 'width'=>'30', 'align'=>'left','sortable'=>'true'),
array('name'=>'field_order', 'index'=>'field_order', 'width'=>'40', 'align'=>'left','sortable'=>'true'),
array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
array('name' => 'field_display_text', 'index' => 'field_display_text', 'width' => '180', 'align' => 'left'),
array(
'name' => 'field_variable',
'index' => 'field_variable',
'width' => '',
'align' => 'left',
'sortable' => 'true'
),
array(
'name' => 'field_type',
'index' => 'field_type',
'width' => '',
'align' => 'left',
'sortable' => 'true'
),
array(
'name' => 'field_changeable',
'index' => 'field_changeable',
'width' => '50',
'align' => 'left',
'sortable' => 'true'
),
array(
'name' => 'field_visible',
'index' => 'field_visible',
'width' => '40',
'align' => 'left',
'sortable' => 'true'
),
array(
'name' => 'field_filter',
'index' => 'field_filter',
'width' => '30',
'align' => 'left',
'sortable' => 'true'
),
array(
'name' => 'field_order',
'index' => 'field_order',
'width' => '40',
'align' => 'left',
'sortable' => 'true'
),
array(
'name' => 'actions',
'index' => 'actions',
'width' => '100',
'align' => 'left',
'formatter' => 'action_formatter',
'sortable' => 'false'
)
);
}
@ -866,7 +937,7 @@ EOF;
$form->addElement('hidden', 'id', $id);
// Setting the form elements
$header = get_lang('Add');
$header = get_lang('Add');
$defaults = array();
if ($action == 'edit') {
@ -881,34 +952,57 @@ EOF;
// Field type
$types = self::get_field_types();
$form->addElement('select', 'field_type', get_lang('FieldType'), $types, array('id' => 'field_type', 'class' => 'chzn-select', 'data-placeholder' => get_lang('Select')));
$form->addElement(
'select',
'field_type',
get_lang('FieldType'),
$types,
array('id' => 'field_type', 'class' => 'chzn-select', 'data-placeholder' => get_lang('Select'))
);
$form->addElement('label', get_lang('Example'), '<div id="example">-</div>');
//$form->addElement('advanced_settings','<a class="btn btn-show" id="advanced_parameters" href="javascript://">'.get_lang('AdvancedParameters').'</a>');
//$form->addElement('html','<div id="options" style="display:none">');
$form->addElement('text', 'field_variable', get_lang('FieldLabel'), array('class' => 'span5'));
$form->addElement('text', 'field_options', get_lang('FieldPossibleValues'), array('id' => 'field_options', 'class' => 'span6'));
$form->addElement(
'text',
'field_options',
get_lang('FieldPossibleValues'),
array('id' => 'field_options', 'class' => 'span6')
);
if ($action == 'edit') {
if (in_array($defaults['field_type'], array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) {
$url = Display::url(get_lang('EditExtraFieldOptions'), 'extra_field_options.php?type='.$this->type.'&field_id=' . $id);
if (in_array(
$defaults['field_type'],
array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT)
)
) {
$url = Display::url(
get_lang('EditExtraFieldOptions'),
'extra_field_options.php?type='.$this->type.'&field_id='.$id
);
$form->addElement('label', null, $url);
$form->freeze('field_options');
}
}
$form->addElement('text', 'field_default_value', get_lang('FieldDefaultValue'), array('id' => 'field_default_value', 'class' => 'span5'));
$form->addElement(
'text',
'field_default_value',
get_lang('FieldDefaultValue'),
array('id' => 'field_default_value', 'class' => 'span5')
);
$group = array();
$group = array();
$group[] = $form->createElement('radio', 'field_visible', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'field_visible', null, get_lang('No'), 0);
$form->addGroup($group, '', get_lang('Visible'), '', false);
$group = array();
$group = array();
$group[] = $form->createElement('radio', 'field_changeable', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'field_changeable', null, get_lang('No'), 0);
$form->addGroup($group, '', get_lang('FieldChangeability'), '', false);
$group = array();
$group = array();
$group[] = $form->createElement('radio', 'field_filter', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'field_filter', null, get_lang('No'), 0);
$form->addGroup($group, '', get_lang('FieldFilter'), '', false);
@ -923,9 +1017,9 @@ EOF;
$defaults['field_options'] = $option->get_field_options_by_field_to_string($id);
$form->addElement('button', 'submit', get_lang('Modify'), 'class="save"');
} else {
$defaults['field_visible'] = 0;
$defaults['field_visible'] = 0;
$defaults['field_changeable'] = 0;
$defaults['field_filter'] = 0;
$defaults['field_filter'] = 0;
$form->addElement('button', 'submit', get_lang('Add'), 'class="save"');
}
@ -949,27 +1043,42 @@ EOF;
{
//With this function we can add actions to the jgrid (edit, delete, etc)
return 'function action_formatter(cellvalue, options, rowObject) {
return \'<a href="?action=edit&type='.$this->type.'&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.'&type='.$this->type.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
return \'<a href="?action=edit&type='.$this->type.'&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.'&type='.$this->type.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon(
'delete.png',
get_lang('Delete'),
'',
ICON_SIZE_SMALL
).'</a>'.
'\';
}';
}
public function getRules(&$columns, &$column_model)
{
$fields = $this->get_all(array('field_visible = ? AND field_filter = ?' => array(1, 1)), 'option_display_text');
$fields = $this->get_all(
array('field_visible = ? AND field_filter = ?' => array(1, 1)),
'option_display_text'
);
$extraFieldOption = new ExtraFieldOption($this->type);
$rules = array();
if (!empty($fields)) {
foreach ($fields as $field) {
$search_options = array();
$type = 'text';
$type = 'text';
if (in_array($field['field_type'], array(self::FIELD_TYPE_SELECT, self::FIELD_TYPE_DOUBLE_SELECT))) {
$type = 'select';
$type = 'select';
$search_options['sopt'] = array('eq', 'ne'); //equal not equal
} else {
$search_options['sopt'] = array('cn', 'nc');//contains not contains
$search_options['sopt'] = array('cn', 'nc'); //contains not contains
}
$search_options['searchhidden'] = 'true';
@ -977,8 +1086,8 @@ EOF;
if ($field['field_type'] == self::FIELD_TYPE_DOUBLE_SELECT) {
//Add 2 selects
$options = $extraFieldOption->get_field_options_by_field($field['id']);
$options = self::extra_field_double_select_convert_array_to_ordered_array($options);
$options = $extraFieldOption->get_field_options_by_field($field['id']);
$options = self::extra_field_double_select_convert_array_to_ordered_array($options);
$first_options = array();
if (!empty($options)) {
@ -992,55 +1101,256 @@ EOF;
}
}
$search_options['value'] = implode(';', $first_options);
$search_options['value'] = implode(';', $first_options);
$search_options['dataInit'] = 'fill_second_select';
//First
$column_model[] = array(
'name' => 'extra_'.$field['field_variable'],
'index' => 'extra_'.$field['field_variable'],
'width' => '100',
'hidden' => 'true',
'search' => 'true',
'stype' => 'select',
'name' => 'extra_'.$field['field_variable'],
'index' => 'extra_'.$field['field_variable'],
'width' => '100',
'hidden' => 'true',
'search' => 'true',
'stype' => 'select',
'searchoptions' => $search_options
);
$columns[] = $field['field_display_text'].' (1)';
$rules[] = array('field' => 'extra_'.$field['field_variable'], 'op' => 'cn');
$columns[] = $field['field_display_text'].' (1)';
$rules[] = array('field' => 'extra_'.$field['field_variable'], 'op' => 'cn');
//Second
$search_options['value'] = $field['id'].':';
$search_options['value'] = $field['id'].':';
$search_options['dataInit'] = 'register_second_select';
$column_model[] = array(
'name' => 'extra_'.$field['field_variable'].'_second',
'index' => 'extra_'.$field['field_variable'].'_second',
'width' => '100',
'hidden' => 'true',
'search' => 'true',
'stype' => 'select',
'name' => 'extra_'.$field['field_variable'].'_second',
'index' => 'extra_'.$field['field_variable'].'_second',
'width' => '100',
'hidden' => 'true',
'search' => 'true',
'stype' => 'select',
'searchoptions' => $search_options
);
$columns[] = $field['field_display_text'].' (2)';
$rules[] = array('field' => 'extra_'.$field['field_variable'].'_second', 'op' => 'cn');
$columns[] = $field['field_display_text'].' (2)';
$rules[] = array('field' => 'extra_'.$field['field_variable'].'_second', 'op' => 'cn');
continue;
} else {
$search_options['value'] = $extraFieldOption->get_field_options_to_string($field['id'], false, 'option_display_text');
$search_options['value'] = $extraFieldOption->get_field_options_to_string(
$field['id'],
false,
'option_display_text'
);
}
$column_model[] = array(
'name' => 'extra_'.$field['field_variable'],
'index' => 'extra_'.$field['field_variable'],
'width' => '100',
'hidden' => 'true',
'search' => 'true',
'stype' => $type,
'name' => 'extra_'.$field['field_variable'],
'index' => 'extra_'.$field['field_variable'],
'width' => '100',
'hidden' => 'true',
'search' => 'true',
'stype' => $type,
'searchoptions' => $search_options
);
$columns[] = $field['field_display_text'];
$rules[] = array('field' => 'extra_'.$field['field_variable'], 'op' => 'cn');
$columns[] = $field['field_display_text'];
$rules[] = array('field' => 'extra_'.$field['field_variable'], 'op' => 'cn');
}
}
return $rules;
}
/**
* @param array $options
* @return array
*/
function parseConditions($options)
{
$inject_extra_fields = null;
$extraFieldOption = new ExtraFieldOption($this->type);
$double_fields = array();
if (isset($options['extra'])) {
$extra_fields = $options['extra'];
if (!empty($extra_fields)) {
$counter = 1;
foreach ($extra_fields as &$extra) {
$extra_field_obj = new ExtraField($this->type);
$extra_field_info = $extra_field_obj->get($extra['id']);
$extra['extra_field_info'] = $extra_field_info;
if (in_array(
$extra_field_info['field_type'],
array(
ExtraField::FIELD_TYPE_SELECT,
ExtraField::FIELD_TYPE_SELECT,
ExtraField::FIELD_TYPE_DOUBLE_SELECT
)
)
) {
$inject_extra_fields .= " fvo$counter.option_display_text as {$extra['field']}, ";
} else {
$inject_extra_fields .= " fv$counter.field_value as {$extra['field']}, ";
}
if (isset($extra_fields_info[$extra['id']])) {
$info = $extra_fields_info[$extra['id']];
} else {
$info = $this->get($extra['id']);
$extra_fields_info[$extra['id']] = $info;
}
if ($info['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
$double_fields[$info['id']] = $info;
}
$counter++;
}
}
}
$options_by_double = array();
foreach ($double_fields as $double) {
$my_options = $extraFieldOption->get_field_options_by_field(
$double['id'],
true
);
$options_by_double['extra_'.$double['field_variable']] = $my_options;
}
$field_value_to_join = array();
//filter can be all/any = and/or
$inject_joins = null;
$inject_where = null;
$where = null;
if (!empty($options['where'])) {
if (!empty($options['extra'])) {
//Removing double 1=1
$options['where'] = str_replace(' 1 = 1 AND', '', $options['where']);
//Always OR
$counter = 1;
foreach ($extra_fields as $extra_info) {
$extra_field_info = $extra_info['extra_field_info'];
$inject_joins .= " INNER JOIN $this->table_field_values fv$counter ON (s.".$this->primaryKey." = fv$counter.".$this->handler_id.") ";
//Add options
if (in_array(
$extra_field_info['field_type'],
array(
ExtraField::FIELD_TYPE_SELECT,
ExtraField::FIELD_TYPE_SELECT,
ExtraField::FIELD_TYPE_DOUBLE_SELECT
)
)
) {
$options['where'] = str_replace(
$extra_info['field'],
'fv'.$counter.'.field_id = '.$extra_info['id'].' AND fvo'.$counter.'.option_value',
$options['where']
);
$inject_joins .= " INNER JOIN $this->table_field_options fvo$counter ".
" ON (fv$counter.field_id = fvo$counter.field_id AND fv$counter.field_value = fvo$counter.option_value) ";
} else {
//text, textarea, etc
$options['where'] = str_replace(
$extra_info['field'],
'fv'.$counter.'.field_id = '.$extra_info['id'].' AND fv'.$counter.'.field_value',
$options['where']
);
}
$field_value_to_join[] = " fv$counter.$this->handler_id ";
$counter++;
}
if (!empty($field_value_to_join)) {
//$inject_where .= " AND s.id = ".implode(' = ', $field_value_to_join);
}
}
$where .= ' AND '.$options['where'];
}
$order = null;
if (!empty($options['order'])) {
$order = " ORDER BY ".$options['order'];
}
$limit = null;
if (!empty($options['limit'])) {
$limit = " LIMIT ".$options['limit'];
}
return array(
'order' => $order,
'limit' => $limit,
'where' => $where,
'inject_where' => $inject_where,
'inject_joins' => $inject_joins,
'field_value_to_join' => $field_value_to_join,
'inject_extra_fields' => $inject_extra_fields,
);
}
public function getExtraFieldRules($filters)
{
$extra_fields = array();
// Getting double select if exists
$double_select = array();
foreach ($filters->rules as $rule) {
if (strpos($rule->field, '_second') === false) {
} else {
$my_field = str_replace('_second', '', $rule->field);
$double_select[$my_field] = $rule->data;
}
}
$condition_array = array();
foreach ($filters->rules as $rule) {
if (strpos($rule->field, 'extra_') === false) {
//normal fields
$field = $rule->field;
if (!empty($rule->data)) {
$condition_array[] = get_where_clause($field, $rule->op, $rule->data);
}
} else {
//Extra fields
//normal
if (strpos($rule->field, '_second') === false) {
//No _second
$original_field = str_replace('extra_', '', $rule->field);
$field_option = $this->get_handler_field_info_by_field_variable($original_field);
if ($field_option['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
if (isset($double_select[$rule->field])) {
$data = explode('#', $rule->data);
$rule->data = $data[1].'::'.$double_select[$rule->field];
} else {
// only was sent 1 select
$data = explode('#', $rule->data);
$rule->data = $data[1];
}
if (!empty($rule->data)) {
$condition_array[] = ' ('.get_where_clause($rule->field, $rule->op, $rule->data).') ';
$extra_fields[] = array('field' => $rule->field, 'id' => $field_option['id']);
}
} else {
if (!empty($rule->data)) {
$condition_array[] = ' ('.get_where_clause($rule->field, $rule->op, $rule->data).') ';
$extra_fields[] = array('field' => $rule->field, 'id' => $field_option['id']);
}
}
} else {
$my_field = str_replace('_second', '', $rule->field);
$original_field = str_replace('extra_', '', $my_field);
$field_option = $this->get_handler_field_info_by_field_variable($original_field);
$extra_fields[] = array('field' => $rule->field, 'id' => $field_option['id']);
}
}
}
return array(
'extra_fields' => $extra_fields,
'condition_array' => $condition_array
);
}
}

@ -521,4 +521,7 @@ class ExtraFieldOption extends Model
return $form;
}
}

@ -182,10 +182,9 @@ class SessionManager
* @return mixed Integer for number of rows, or array of results
* @assert (array(),true) !== false
*/
public static function get_sessions_admin($options = array(), $get_count = false) {
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_field_values = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
$tbl_session_field_options = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_OPTIONS);
public static function get_sessions_admin($options = array(), $get_count = false)
{
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$where = 'WHERE 1 = 1 ';
$user_id = api_get_user_id();
@ -198,58 +197,14 @@ class SessionManager
$where .=" AND s.id_coach = $user_id ";
}
$inject_extra_fields = null;
$extra_fields = array();
$extra_fields_info = array();
//for now only sessions
$extra_field = new ExtraField('session');
$double_fields = array();
$extra_field_option = new ExtraFieldOption('session');
$extra_present = false;
if (isset($options['extra'])) {
$extra_fields = $options['extra'];
if (!empty($extra_fields)) {
$extra_present = true;
$counter = 1;
foreach ($extra_fields as &$extra) {
$extra_field_obj= new ExtraField('session');
$extra_field_info = $extra_field_obj->get($extra['id']);
$extra['extra_field_info'] = $extra_field_info;
if (in_array($extra_field_info['field_type'], array(
ExtraField::FIELD_TYPE_SELECT,
ExtraField::FIELD_TYPE_SELECT,
ExtraField::FIELD_TYPE_DOUBLE_SELECT
))
) {
$inject_extra_fields .= " fvo$counter.option_display_text as {$extra['field']}, ";
} else {
$inject_extra_fields .= " fv$counter.field_value as {$extra['field']}, ";
}
if (isset($extra_fields_info[$extra['id']])) {
$info = $extra_fields_info[$extra['id']];
} else {
$info = $extra_field->get($extra['id']);
$extra_fields_info[$extra['id']] = $info;
}
if ($info['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
$double_fields[$info['id']] = $info;
}
$counter++;
}
}
}
$options_by_double = array();
foreach ($double_fields as $double) {
$my_options = $extra_field_option->get_field_options_by_field($double['id'], true);
$options_by_double['extra_'.$double['field_variable']] = $my_options;
}
$conditions = $extra_field->parseConditions($options);
$inject_joins = $conditions['inject_joins'];
$where .= $conditions['where'];
$inject_where = $conditions['inject_where'];
$inject_extra_fields = $conditions['inject_extra_fields'];
$order = $conditions['order'];
$limit = $conditions['limit'];
if ($get_count == true) {
$select = " SELECT count(*) as total_rows";
@ -266,70 +221,20 @@ class SessionManager
" s.id ";
}
//filter can be all/any = and/or
$inject_joins = null;
$inject_where = null;
$field_value_to_join = array();
if (!empty($options['where'])) {
if (!empty($options['extra'])) {
//Removing double 1=1
$options['where'] = str_replace(' 1 = 1 AND', '', $options['where']);
//Always OR
$counter = 1;
foreach ($extra_fields as $extra_info) {
$extra_field_info = $extra_info['extra_field_info'];
$inject_joins .= " INNER JOIN $tbl_session_field_values fv$counter ON (s.id = fv$counter.session_id) ";
//Add options
if (in_array($extra_field_info['field_type'], array(
ExtraField::FIELD_TYPE_SELECT,
ExtraField::FIELD_TYPE_SELECT,
ExtraField::FIELD_TYPE_DOUBLE_SELECT
))
) {
$options['where'] = str_replace($extra_info['field'], 'fv'.$counter.'.field_id = '.$extra_info['id'].' AND fvo'.$counter.'.option_value', $options['where']);
$inject_joins .= " INNER JOIN $tbl_session_field_options fvo$counter ".
" ON (fv$counter.field_id = fvo$counter.field_id AND fv$counter.field_value = fvo$counter.option_value) ";
} else {
//text, textarea, etc
$options['where'] = str_replace($extra_info['field'], 'fv'.$counter.'.field_id = '.$extra_info['id'].' AND fv'.$counter.'.field_value', $options['where']);
}
$field_value_to_join[] = " fv$counter.session_id ";
$counter++;
}
if (!empty($field_value_to_join)) {
//$inject_where .= " AND s.id = ".implode(' = ', $field_value_to_join);
}
}
$where .= ' AND '.$options['where'];
}
$query = "$select FROM $tbl_session s $inject_joins $where $inject_where";
if (api_is_multiple_url_enabled()) {
$table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
//" LEFT JOIN $tbl_session_rel_course src ON (src.id_session = s.id) ".
if ($access_url_id != -1) {
$where.= " AND ar.access_url_id = $access_url_id ";
$query = "$select FROM $tbl_session s $inject_joins INNER JOIN $table_access_url_rel_session ar ON (ar.session_id = s.id) $where";
}
}
if (!empty($options['order'])) {
$query .= " ORDER BY ".$options['order'];
}
if (!empty($options['limit'])) {
$query .= " LIMIT ".$options['limit'];
}
$query .= $order;
$query .= $limit;
if ($get_count == false) {
//echo $query;exit;
}
$result = Database::query($query);
$formatted_sessions = array();
@ -340,6 +245,7 @@ class SessionManager
return $sessions[0]['total_rows'];
}
foreach ($sessions as $session) {
$session_id = $session['id'];
$session['name'] = Display::url($session['name'], "resume_session.php?id_session=".$session['id']);
@ -365,8 +271,7 @@ class SessionManager
break;
}
//Cleaning double selects
// Cleaning double selects.
foreach ($session as $key => &$value) {
if (isset($options_by_double[$key]) || isset($options_by_double[$key.'_second'])) {
$options = explode('::', $value);
@ -666,7 +571,8 @@ class SessionManager
/**
*
*/
static function compare_arrays_to_merge($array1, $array2) {
static function compare_arrays_to_merge($array1, $array2)
{
if (empty($array2)) {
return $array1;
}
@ -2614,7 +2520,7 @@ class SessionManager
break;
}
//Inject extra session fields
// Inject extra session fields
$session_field = new SessionField();
$rules = $session_field->getRules($columns, $column_model);
@ -2634,7 +2540,8 @@ class SessionManager
return $return_array;
}
static function getSessionsByCategory($categoryId) {
static function getSessionsByCategory($categoryId)
{
$categoryId = intval($categoryId);
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$sql = "select * FROM $tableSession WHERE session_category_id = $categoryId";

@ -232,13 +232,12 @@ $(function() {
prmSearch
);
// create the searching dialog
// Create the searching dialog.
grid.searchGrid(prmSearch);
//Fixes search table
// Fixes search table.
var searchDialogAll = $("#fbox_"+grid[0].id);
searchDialogAll.addClass("table");
var searchDialog = $("#searchmodfbox_"+grid[0].id);
searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
searchDialog.css({position:"relative", "z-index":"auto", "float":"left"})

@ -18,13 +18,17 @@
}
$(function() {
{% if app.request.get('categoryId') %}
var categoryId = '{{ app.request.get('categoryId') }}';
loadQuestions(categoryId);
{% endif %}
$('.load_categories li').on('click', 'a', function() {
$('.load_categories li').each(function() {
$(this).removeClass('active');
});
$(this).parent().addClass('active');
var url = $(this).attr('href');
var id = url.replace(/[^\d\.]/g, '');
loadQuestions(id);
@ -39,6 +43,7 @@
{{ global_category_tree }}
</div>
{% endblock %}
{% block right_column %}
<div class="questions">
</div>

@ -1,8 +1,128 @@
<script>
function setSearchSelect(columnName) {
$("#questions").jqGrid('setColProp', columnName, {
/*searchoptions:{
dataInit:function(el){
$("option[value='1']",el).attr("selected", "selected");
setTimeout(function(){
$(el).trigger('change');
}, 1000);
}
}*/
});
}
var added_cols = [];
var original_cols = [];
function clean_cols(grid, added_cols) {
//Cleaning
for (key in added_cols) {
//console.log('hide: ' + key);
grid.hideCol(key);
};
grid.showCol('name');
grid.showCol('display_start_date');
grid.showCol('display_end_date');
grid.showCol('course_title');
}
function show_cols(grid, added_cols) {
grid.showCol('name').trigger('reloadGrid');
for (key in added_cols) {
//console.log('show: ' + key);
grid.showCol(key);
};
}
var second_filters = [];
$(function () {
{{ js }}
setSearchSelect("status");
var grid = $("#questions"),
prmSearch = {
multipleSearch : true,
overlay : false,
width: 'auto',
caption: '{{ 'Search' | get_lang }}',
formclass:'data_table',
onSearch : function() {
var postdata = grid.jqGrid('getGridParam', 'postData');
if (postdata && postdata.filters) {
filters = jQuery.parseJSON(postdata.filters);
clean_cols(grid, added_cols);
added_cols = [];
$.each(filters, function(key, value){
//console.log('key: ' + key );
if (key == 'rules') {
$.each(value, function(subkey, subvalue) {
if (subvalue.data == undefined) {
}
//if (added_cols[value.field] == undefined) {
added_cols[subvalue.field] = subvalue.field;
//}
//grid.showCol(value.field);
});
}
});
show_cols(grid, added_cols);
}
},
onReset: function() {
clean_cols(grid, added_cols);
}
};
original_cols = grid.jqGrid('getGridParam', 'colModel');
grid.jqGrid('navGrid','#questions_pager',
{edit:false,add:false,del:false},
{height:280,reloadAfterSubmit:false}, // edit options
{height:280,reloadAfterSubmit:false}, // add options
{reloadAfterSubmit:false},// del options
prmSearch
);
// create the searching dialog
grid.searchGrid(prmSearch);
// Fixes search table.
var searchDialogAll = $("#fbox_"+grid[0].id);
searchDialogAll.addClass("table");
var searchDialog = $("#searchmodfbox_"+grid[0].id);
searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
searchDialog.css({position:"relative", "z-index":"auto", "float":"left"})
var gbox = $("#gbox_"+grid[0].id);
gbox.before(searchDialog);
gbox.css({clear:"left"});
//Select first elements by default
$('.input-elm').each(function(){
$(this).find('option:first').attr('selected', 'selected');
});
$('.delete-rule').each(function(){
$(this).click(function(){
$('.input-elm').each(function(){
$(this).find('option:first').attr('selected', 'selected');
});
});
});
});
</script>
<div class="questions">
{% if category %}
<h3>{{ category.title }}</h3>
{% endif %}
{{ grid }}
</div>
</div>

@ -127,50 +127,38 @@ class QuestionManagerController
public function getQuestionsByCategoryAction(Application $app, $categoryId)
{
// Getting CQuizCategory repo.
$repo = $app['orm.em']->getRepository('Entity\CQuizCategory');
/** @var \Doctrine\ORM\EntityManager $em */
$em = $app['orm.em'];
$repo = $em->getRepository('Entity\CQuizCategory');
/** @var \Entity\CQuizCategory $category */
$category = $repo->find($categoryId);
$questions = $category->getQuestions();
//$questions = $category->getQuestions();
/*$questionFields = $em->getRepository('Entity\QuestionField')->findAll();
$rules = array();
foreach ($questionFields as $extraField) {
$extraField->getFieldVariable();
$rules[] = ;
}*/
$questionColumns = \Question::getQuestionColumns();
$columnModel = $questionColumns['column_model'];
$columns = $questionColumns['columns'];
$rules = $questionColumns['rules'];
$grid = \Display::grid_html('questions');
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_questions&categoryId='.$categoryId;
//The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array('id', get_lang('Name'), get_lang('Description'), get_lang('Actions'));
// Column config.
$columnModel = array(
array(
'name' => 'iid',
'index' => 'iid',
'width' => '20',
'align' => 'left'
),
array(
'name' => 'question',
'index' => 'question',
'width' => '200',
'align' => 'left'
),
array(
'name' => 'description',
'index' => 'description',
'width' => '100',
'align' => 'left',
'sortable' => 'false'
),
array(
'name' => 'actions',
'index' => 'actions',
'width' => '30',
'align' => 'left',
'formatter' => 'action_formatter',
'sortable' => 'false'
$extraParams['postData'] =array(
'filters' => array(
"groupOp" => "AND",
"rules" => $rules
)
);
// Autowidth.
$extraParams['autowidth'] = 'true';
// Height auto.
@ -186,24 +174,10 @@ class QuestionManagerController
$js = \Display::grid_js('questions', $url, $columns, $columnModel, $extraParams, array(), $actionLinks, true);
$app['template']->assign('category', $category);
$app['template']->assign('grid', $grid);
$app['template']->assign('js', $js);
//$adapter = new DoctrineCollectionAdapter($questions);
//$adapter = new FixedAdapter($nbResults, array());
/*$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage(10); // 10 by default
$pagerfanta->setCurrentPage(1); // 1 by default
*/
//$this->app['pagerfanta.view.router.name'] = 'userportal';
/*$this->app['pagerfanta.view.router.params'] = array(
'filter' => $filter,
'type' => 'courses',
'page' => $page
);*/
//$app['template']->assign('pagination', $pagerfanta);
$response = $app['template']->render_template('admin/questionmanager/questions.tpl');
return new Response($response, 200, array());
}
@ -222,17 +196,43 @@ class QuestionManagerController
$app['extraJS'] = $extraJS;
// Getting CQuizCategory repo.
/** @var \Gedmo\Tree\Entity\Repository\NestedTreeRepository $repo */
$repo = $app['orm.em']->getRepository('Entity\CQuizCategory');
$categoryId = $app['request']->get('categoryId');
$subtree = null;
if (isset($categoryId)) {
// Insert node.
/*
$options = array(
'decorate' => true,
'rootOpen' => '<ul class="nav nav-list">',
'rootClose' => '</ul>',
'childOpen' => '<li>',
'childClose' => '</li>'
);
$node = $repo->find($categoryId);
$qb = $repo->getChildrenQueryBuilder($node, true, 'title', 'ASC', true);
$query = $qb->getQuery();
$subtree = $repo->buildTree($query->getArrayResult(), $options);
var_dump($subtree);*/
}
$options = array(
'decorate' => true,
'rootOpen' => '<ul class="nav nav-list">',
'rootClose' => '</ul>',
'childOpen' => '<li>',
'childClose' => '</li>',
'nodeDecorator' => function ($row) use ($app) {
'nodeDecorator' => function ($row) use ($app, $categoryId, $subtree) {
$url = $app['url_generator']->generate('admin_questions_get_categories', array('id' => $row['iid']));
return \Display::url($row['title'], $url, array('id' => $row['iid']));
$url = \Display::url($row['title'], $url, array('id' => $row['iid']));
if ($row['iid'] == $categoryId) {
$url .= $subtree;
}
return $url;
}
//'representationField' => 'slug',
//'html' => true
@ -246,16 +246,13 @@ class QuestionManagerController
->where('node.cId <> 0 AND node.lvl = 0')
->orderBy('node.root, node.lft', 'ASC');
$categoryId = $app['request']->get('categoryId');
if (isset($categoryId)) {
/*$qb->add('where', 'node.rgt = :categoryId');
$qb->setParameter('categoryId', $categoryId);*/
}
//$node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false
//$qb = $repo->getChildrenQueryBuilder(null, true, 'title', 'ASC', true);
$query = $qb->getQuery();
$tree = $repo->buildTree($query->getArrayResult(), $options);
$app['template']->assign('category_tree', $tree);
// Getting globals

Loading…
Cancel
Save