Add function needed for BT#10052

1.10.x
jmontoyaa 9 years ago
parent 9972888054
commit 6b51fae1a3
  1. 3
      main/inc/lib/database.constants.inc.php
  2. 147
      main/inc/lib/display.lib.php

@ -197,7 +197,7 @@ define('TABLE_DROPBOX_POST', 'dropbox_post');
define('TABLE_DROPBOX_FILE', 'dropbox_file'); define('TABLE_DROPBOX_FILE', 'dropbox_file');
define('TABLE_DROPBOX_PERSON', 'dropbox_person'); define('TABLE_DROPBOX_PERSON', 'dropbox_person');
// Course quiz (or test, or exercice) tables // Course quiz (or test, or exercise) tables
define('TABLE_QUIZ_QUESTION', 'quiz_question'); define('TABLE_QUIZ_QUESTION', 'quiz_question');
define('TABLE_QUIZ_TEST', 'quiz'); define('TABLE_QUIZ_TEST', 'quiz');
define('TABLE_QUIZ_ORDER', 'quiz_order'); define('TABLE_QUIZ_ORDER', 'quiz_order');
@ -206,6 +206,7 @@ define('TABLE_QUIZ_TEST_QUESTION', 'quiz_rel_question');
define('TABLE_QUIZ_QUESTION_OPTION', 'quiz_question_option'); define('TABLE_QUIZ_QUESTION_OPTION', 'quiz_question_option');
define('TABLE_QUIZ_QUESTION_CATEGORY', 'quiz_question_category'); define('TABLE_QUIZ_QUESTION_CATEGORY', 'quiz_question_category');
define('TABLE_QUIZ_QUESTION_REL_CATEGORY', 'quiz_question_rel_category'); define('TABLE_QUIZ_QUESTION_REL_CATEGORY', 'quiz_question_rel_category');
define('TABLE_QUIZ_REL_CATEGORY', 'quiz_rel_category');
// Linked resource table // Linked resource table
//@todo table exists? //@todo table exists?

@ -2030,6 +2030,153 @@ class Display
return null; return null;
} }
/**
*
* @param int $nextValue
* @param array $list
* @param int $current
* @param int $fixedValue
* @param array $conditions
* @param string $link
* @param bool $isMedia
* @param bool $addHeaders
* @return string
*/
public static function progressPaginationBar(
$nextValue,
$list,
$current,
$fixedValue = null,
$conditions = array(),
$link = null,
$isMedia = false,
$addHeaders = true,
$linkAttributes = array()
) {
if ($addHeaders) {
$pagination_size = 'pagination-mini';
$html = '<div class="exercise_pagination pagination '.$pagination_size.'"><ul>';
} else {
$html = null;
}
$affectAllItems = false;
if ($isMedia && isset($fixedValue) && ($nextValue + 1 == $current)) {
$affectAllItems = true;
}
$localCounter = 0;
foreach ($list as $itemId) {
$isCurrent = false;
if ($affectAllItems) {
$isCurrent = true;
} else {
if (!$isMedia) {
$isCurrent = $current == ($localCounter + $nextValue + 1) ? true : false;
}
}
$html .= self::parsePaginationItem(
$itemId,
$isCurrent,
$conditions,
$link,
$nextValue,
$isMedia,
$localCounter,
$fixedValue,
$linkAttributes
);
$localCounter++;
}
if ($addHeaders) {
$html .= '</ul></div>';
}
return $html;
}
/**
*
* @param int $itemId
* @param bool $isCurrent
* @param array $conditions
* @param string $link
* @param int $nextValue
* @param bool $isMedia
* @param int $localCounter
* @param int $fixedValue
* @return string
*/
static function parsePaginationItem(
$itemId,
$isCurrent,
$conditions,
$link,
$nextValue = 0,
$isMedia = false,
$localCounter = null,
$fixedValue = null,
$linkAttributes = array())
{
$defaultClass = "before";
$class = $defaultClass;
foreach ($conditions as $condition) {
$array = isset($condition['items']) ? $condition['items'] : array();
$class_to_applied = $condition['class'];
$type = isset($condition['type']) ? $condition['type'] : 'positive';
$mode = isset($condition['mode']) ? $condition['mode'] : 'add';
switch ($type) {
case 'positive':
if (in_array($itemId, $array)) {
if ($mode == 'overwrite') {
$class = " $defaultClass $class_to_applied";
} else {
$class .= " $class_to_applied";
}
}
break;
case 'negative':
if (!in_array($itemId, $array)) {
if ($mode == 'overwrite') {
$class = " $defaultClass $class_to_applied";
} else {
$class .= " $class_to_applied";
}
}
break;
}
}
if ($isCurrent) {
$class = "before current";
}
if ($isMedia && $isCurrent) {
$class = "before current";
}
if (empty($link)) {
$link_to_show = "#";
} else {
$link_to_show = $link.($nextValue + $localCounter);
}
$label = $nextValue + $localCounter + 1;
if ($isMedia) {
$label = ($fixedValue + 1) .' '.chr(97 + $localCounter);
$link_to_show = $link.$fixedValue.'#questionanchor'.$itemId;
}
$link = Display::url($label.' ', $link_to_show, $linkAttributes);
return '<li class = "'.$class.'">'.$link.'</li>';
}
/**
* @param int $current
* @param int $total
* @return string
*/
public static function paginationIndicator($current, $total)
{
$html = null;
if (!empty($current) && !empty($total)) {
$label = sprintf(get_lang('PaginationXofY'), $current, $total);
$html = self::url($label, '#', array('class' => 'btn disabled'));
}
return $html;
}
/** /**
* Adds a message in the queue * Adds a message in the queue
* @param string $message * @param string $message

Loading…
Cancel
Save