Tracking: Add global learning path item by author report (requires plugin activation) - refs BT#17943

pull/3643/head
carlos alvarado 6 years ago committed by GitHub
parent 2287ef3ad4
commit 74e1bb4c19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 79
      main/inc/lib/extra_field.lib.php
  2. 39
      main/inc/lib/extra_field_option.lib.php
  3. 14
      main/inc/lib/extra_field_value.lib.php
  4. 314
      main/inc/lib/myspace.lib.php
  5. 55
      main/lp/learnpath.class.php
  6. 379
      main/lp/lp_add_author.php
  7. 15
      main/lp/lp_add_item.php
  8. 34
      main/lp/lp_controller.php
  9. 13
      main/lp/lp_edit_item.php
  10. 19
      main/mySpace/admin_view.php
  11. 235
      plugin/check_extra_field_author_company/CheckExtraFieldAuthorsCompanyPlugin.php
  12. 6
      plugin/check_extra_field_author_company/plugin.php

@ -1181,18 +1181,46 @@ class ExtraField extends Model
// When a variable is 'authors', this will be a
// select element of teachers (see BT#17648)
$variable = $field_details['variable'];
if ($variable != 'authors') {
$authors = ($variable == 'authors' || $variable == 'authorlpitem') ? true : false;
if ($authors == false) {
foreach ($field_details['options'] as $optionDetails) {
$options[$optionDetails['option_value']] = $optionDetails['display_text'];
}
} else {
$conditions = [
'enabled' => 1,
'status' => COURSEMANAGER,
];
$teachers = UserManager::get_user_list($conditions);
foreach ($teachers as $teacher) {
$options[$teacher['id']] = $teacher['complete_name'];
if ($variable == 'authors') {
$conditions = [
'enabled' => 1,
'status' => COURSEMANAGER,
];
echo __FILE__."::".__LINE__."<pre>".var_export($conditions, true)."</pre><br>";
$teachers = UserManager::get_user_list($conditions);
foreach ($teachers as $teacher) {
$options[$teacher['id']] = $teacher['complete_name'];
}
} elseif ($variable == 'authorlpitem') {
/* Authors*/
$options = [];
$field = new ExtraField('user');
$authorLp = $field->get_handler_field_info_by_field_variable('authorlp');
$idExtraField = (int) (isset($authorLp['id']) ? $authorLp['id'] : 0);
if ($idExtraField != 0) {
$extraFieldValueUser = new ExtraFieldValue('user');
$arrayExtraFieldValueUser = $extraFieldValueUser->get_item_id_from_field_variable_and_field_value(
$authorLp['variable'],
1,
true,
false,
true);
foreach ($arrayExtraFieldValueUser as $item) {
$teacher = api_get_user_info($item['item_id']);
// $teachers[] = $teacher;
$options[$teacher['id']] = $teacher['complete_name'];
}
}
/* Authors*/
}
}
$form->addElement(
@ -1920,6 +1948,17 @@ class ExtraField extends Model
}
/**
* Gets the set of values of an extra_field searching for the variable name.
*
* Example:
* <code>
* <?php
* $extraField = new ExtraField('lp_item');
* $extraFieldArray = $extraField->get_handler_field_info_by_field_variable('authorlpitem');
* echo "<pre>".var_export($extraFieldArray,true)."</pre>";
* ?>
* </code>
*
* @param string $variable
*
* @return array|bool
@ -3128,30 +3167,6 @@ JAVASCRIPT;
return $result;
}
/**
* Gets the display name of an extra field.
*
* @param string $variableName
*/
public static function getDisplayNameByVariable($variableName = null)
{
if ($variableName == null) {
return null;
}
$variableName = Database::escape_string($variableName);
$tblExtraField = Database::get_main_table(TABLE_EXTRA_FIELD);
$query = "SELECT display_text
FROM $tblExtraField
WHERE variable = '$variableName'";
$companyField = Database::fetch_assoc(Database::query($query));
if ($companyField == false or !isset($companyField['display_text'])) {
return null;
}
return $companyField['display_text'];
}
/**
* @param \FormValidator $form
* @param int $defaultValueId

@ -120,6 +120,22 @@ class ExtraFieldOption extends Model
}
/**
* Save option.
*
* Example:
* <code>
* <?php
* $fieldOption = new ExtraFieldOption('user');
* $fieldOption->saveOptions([
* 'field_id'=> 1,
* 'option_value'=> 1,
* 'display_text'=> 'extra value option 1',
* 'option_order'=>0
* ]);
* echo "<pre>".var_export($fieldOption,true)."</pre>";
* ?>
* </code>
*
* @param array $params
* @param bool $showQuery
*
@ -151,6 +167,20 @@ class ExtraFieldOption extends Model
/**
* Saves an option into the corresponding *_field_options table.
*
* Example:
* <code>
* <?php
* $fieldOption = new ExtraFieldOption('user');
* $fieldOption->save([
* 'field_id'=> 1,
* 'option_value'=> 1,
* 'display_text'=> 'extra value option 1',
* 'option_order=>0'
* ]);
* echo "<pre>".var_export($fieldOption,true)."</pre>";
* ?>
* </code>
*
* @param array $params Parameters to be considered for the insertion
* @param bool $showQuery Whether to show the query (sent to the parent save() method)
*
@ -499,6 +529,15 @@ class ExtraFieldOption extends Model
/**
* Gets an array of options for a specific field.
*
* Example:
* <code>
* <?php
* $fieldOption = new ExtraFieldOption('user');
* $fieldOption->get_field_options_by_field(1);
* echo "<pre>".var_export($fieldOption,true)."</pre>";
* ?>
* </code>
*
* @param int $field_id The field ID
* @param bool $add_id_in_array Whether to add the row ID in the result
* @param null $ordered_by Extra ordering query bit

@ -837,6 +837,20 @@ class ExtraFieldValue extends Model
* Gets the ID from the item (course, session, etc) for which
* the given field is defined with the given value.
*
* Example:
* <code>
* <?php
* $extraFieldValueUser = new ExtraFieldValue('user');
* $arrayExtraFieldValueUser = $extraFieldValueUser->get_item_id_from_field_variable_and_field_value(
* 'variable',
* 1,
* true,
* false,
* true);
* echo "<pre>".var_export($arrayExtraFieldValueUser,true)."</pre>";
* ?>
* </code>
*
* @param string $variable Field (type of data) we want to check
* @param string $value Data we are looking for in the given field
* @param bool $transform Whether to transform the result to a human readable strings

@ -73,7 +73,8 @@ class MySpace
],
];
$companyField = ExtraField::getDisplayNameByVariable('company');
$field = new ExtraField('user');
$companyField = $field->get_handler_field_info_by_field_variable('company');
if (!empty($companyField)) {
$actions[] =
[
@ -81,7 +82,8 @@ class MySpace
'content' => get_lang('UserByEntityReport'),
];
}
$authorsField = ExtraField::getDisplayNameByVariable('authors');
$field = new ExtraField('lp');
$authorsField = $field->get_handler_field_info_by_field_variable('authors');
if (!empty($authorsField)) {
$actions[] =
[
@ -89,6 +91,15 @@ class MySpace
'content' => get_lang('LpByAuthor'),
];
}
$field = new ExtraField('lp_item');
$authorsItemField = $field->get_handler_field_info_by_field_variable('authorlpitem');
if (!empty($authorsItemField)) {
$actions[] =
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=learningPathByItem',
'content' => get_lang('LearningPathItemByAuthor'),
];
}
return Display::actions($actions, null);
}
@ -1347,6 +1358,305 @@ class MySpace
}
}
/**
* Displays a list as a table of teachers who are set authors of lp's item by a extra_field authors.
*
* @param string|null $startDate
* @param string|null $endDate
* @param bool $csv
*/
public static function displayResumeLpByItem(
$startDate = null,
$endDate = null,
$csv = false
) {
$tableHtml = '';
$table = '';
$tblExtraField = Database::get_main_table(TABLE_EXTRA_FIELD);
$tblExtraFieldValue = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$extraFieldLpByAutorName = 'authorlpitem';
$extraFieldLpPrice = 'price';
$queryExtraFieldPrice = "SELECT id ".
" FROM $tblExtraField ".
" WHERE variable = '$extraFieldLpPrice'";
$queryExtraFieldValue = "SELECT id ".
" FROM $tblExtraField ".
" WHERE variable = '$extraFieldLpByAutorName'";
// search items of lp
$cLpItemsQuery = "select item_id as lp_item_id ".
" from $tblExtraFieldValue ".
" where field_id IN ( $queryExtraFieldValue ) ".
" group by lp_item_id";
$queryResult = Database::query($cLpItemsQuery);
$cLpItems = [];
while ($row = Database::fetch_array($queryResult, 'ASSOC')) {
$cLpItems[] = (int) $row['lp_item_id'];
}
if (count($cLpItems) == 0) {
$tableContent = "<div class='table-responsive'>".
"<table class='table table-hover table-striped table-bordered data_table'>".
"<thead>".
"<tr>".
"<th class=\"th-header\">".get_lang('NoDataAvailable')."</th>".
"</tr>".
"</thead>".
"</tbody>".
"</tbody>".
"</table>".
"</div>";
$tableHtml = $tableContent;
} else {
$cLpItems = implode(',', $cLpItems);
// search by price
$cLpItemsPriceQuery = "select value as price, item_id as lp_item_id ".
" from $tblExtraFieldValue ".
" where field_id IN ( $queryExtraFieldPrice ) and item_id in ($cLpItems)";
$queryResult = Database::query($cLpItemsPriceQuery);
$lpItemPrice = [];
while ($row = Database::fetch_array($queryResult, 'ASSOC')) {
$lpItemPrice[$row['lp_item_id']] = $row['price'];
}
// search authors of lp
$autorsStr = '';
$autorsQuery = "select value as users_id ".
" from $tblExtraFieldValue ".
" where field_id IN ( $queryExtraFieldValue ) ".
" group by users_id ";
$queryResult = Database::query($autorsQuery);
while ($row = Database::fetch_array($queryResult, 'ASSOC')) {
$autorsStr .= " ".str_replace(';', ' ', $row['users_id']);
$autorsStr = trim($autorsStr);
}
$autorsStr = str_replace(' ', ',', $autorsStr);
//search autors detailed
$authors = [];
if (!empty($autorsStr)) {
$autorsStr = explode(',', $autorsStr);
foreach ($autorsStr as $item) {
$authors[$item] = api_get_user_info($item);
}
}
unset($autorsStr);
//search info of lp's items
$cLpItemsData = [];
if (!empty($cLpItems)) {
$query = "select * ".
" from c_lp_item ".
" where iid in ($cLpItems)";
$queryResult = Database::query($query);
while ($row = Database::fetch_array($queryResult, 'ASSOC')) {
$row['price'] = isset($lpItemPrice[$row['iid']]) ? $lpItemPrice[$row['iid']] : 0;
$cLpItemsData[$row['iid']] = $row;
}
}
$query = "select item_id as lp_item_id ,value as users_id ".
" from $tblExtraFieldValue ".
" where field_id IN ( $queryExtraFieldValue )";
$queryResult = Database::query($query);
$printData = [];
while ($row = Database::fetch_array($queryResult, 'ASSOC')) {
$cLpItem = (int) $row['lp_item_id'];
// get full lp data
$cLpItemData = isset($cLpItemsData[$cLpItem]) ? $cLpItemsData[$cLpItem] : [];
$authorData = $row['users_id'];
if (!empty($authorData)) {
if (strpos($authorData, ";") === false) {
$printData[(int) $authorData][$cLpItem] = $cLpItemData;
} else {
foreach (explode(';', $authorData) as $item) {
$printData[$item][$cLpItem] = $cLpItemData;
}
}
}
}
$index = 0;
}
if ($csv == false) {
if (empty($tableHtml)) {
$table .= "<div class='table-responsive'>".
"<table class='table table-hover table-striped table-bordered data_table'>".
"<thead>".
"<tr>".
"<th class=\"th-header\">".get_lang('Author')."</th>".
"<th class=\"th-header\">".get_lang('ContentList')."</th>".
"<th class=\"th-header\">".get_lang('Tariff')."</th>".
"<th class=\"th-header\">".get_lang('CountOfSubscribedUsers')."</th>".
"<th class=\"th-header\">".get_lang('ToInvoice')."</th>".
"<th class=\"th-header\">".get_lang('StudentList')."</th>".
"</tr>".
"</thead>".
"<tbody>";
//Icon Constant
$iconAdd = Display::return_icon('add.png', get_lang('ShowOrHide'), '', ICON_SIZE_SMALL);
$iconRemove = Display::return_icon('error.png', get_lang('ShowOrHide'), '', ICON_SIZE_SMALL);
$lastAuthor = '';
$total = 0;
foreach ($printData as $authorId => $lpItemData) {
$autor = $authors[$authorId];
$totalSudent = 0;
foreach ($lpItemData as $lpItemId => $lpitem) {
$title = $lpitem['title'];
$price = $lpitem['price'];
$hide = "class='author_$authorId hidden' ";
if ($lastAuthor != $autor) {
$table .= "<tr>";
$table .= "<td>".$autor['complete_name'].
"</td>";
} else {
$table .= "<tr $hide >";
$table .= "<td></td>";
}
$hiddenField = 'student_show_'.$index;
$hiddenFieldLink = 'student_show_'.$index.'_';
if ($lastAuthor != $autor) {
$table .= "<td>$title".
"</td>";
} else {
$table .= "<td>$title</td>";
}
$table .= "<td>$price</td>";
$registeredUsers = self::getCompanyLearnpathSubscription($startDate, $endDate, $lpitem['lp_id']);
$studenRegister = count($registeredUsers);
$table .= "<td>$studenRegister</td>";
$facturar = ($studenRegister * $price);
$table .= "<td>$facturar</td>";
$total += $facturar;
$totalSudent += $studenRegister;
if ($studenRegister != 0) {
$table .= "<td>".
"<a href='#!' id='$hiddenFieldLink' onclick='showHideStudent(\"$hiddenField\")'>".
"<div class='icon_add'>$iconAdd</div>".
"<div class='icon_remove hidden'>$iconRemove</div>".
"</a>".
"<div id='$hiddenField' class='hidden'>";
for ($i = 0; $i < $studenRegister; $i++) {
$tempStudent = api_get_user_info($registeredUsers[$i]);
$table .= $tempStudent['complete_name']."<br>";
}
$index++;
$table .= "</div>".
"</td>";
} else {
$table .= "<td></td>";
}
$table .= "</tr>";
$lastAuthor = $autor;
}
//footer
$table .= "<tr><th class=\"th-header\"></th>".
"<th class=\"th-header\">".
"<a href='#!' id='$hiddenFieldLink' onclick='ShowMoreAuthor(\"$authorId\")'>".
"<div class='icon_add_author_$authorId'>$iconAdd</div>".
"<div class='icon_remove_author_$authorId hidden'>$iconRemove</div>".
"</a>"."</th>".
"<th class=\"th-header\"></th>".
"<th class=\"th-header\">$totalSudent</th>".
"<th class=\"th-header\">$total</th>".
"<th class=\"th-header\"></tr>";
$total = 0;
}
$table .= "</tbody>".
"</table>".
"</div>";
$tableHtml = $table;
}
$form = new FormValidator('searchDate', 'get');
$form->addHidden('display', 'learningPathByItem');
$today = new DateTime();
if (empty($startDate)) {
$startDate = $today->modify('first day of this month')->format('Y-m-d');
}
if (empty($endDate)) {
$endDate = $today->modify('last day of this month')->format('Y-m-d');
}
$form->addDatePicker(
'startDate',
get_lang('DateStart'),
[
'value' => $startDate,
]);
$form->addDatePicker(
'endDate',
get_lang('DateEnd'),
[
'value' => $endDate,
]);
$form->addButtonSearch(get_lang('Search'));
if (count($printData) != 0) {
//$form->addButtonSave(get_lang('Ok'), 'export');
$form
->addButton(
'export_csv',
get_lang('ExportAsCSV'),
'check',
'primary',
null,
null,
[
]
);
}
$tableContent = $form->returnForm();
$tableContent .= $tableHtml;
$tpl = new Template('', false, false, false, false, false, false);
$tpl->assign('table', $tableContent);
$templateName = $tpl->get_template('my_space/course_summary.tpl');
$tpl->display($templateName);
} else {
$csv_content = [];
$csv_row = [];
$csv_row[] = get_lang('Author');
$csv_row[] = get_lang('ContentList');
$csv_row[] = get_lang('Tariff');
$csv_row[] = get_lang('CountOfSubscribedUsers');
$csv_row[] = get_lang('ToInvoice');
$csv_row[] = get_lang('StudentList');
$csv_content[] = $csv_row;
foreach ($printData as $authorId => $lpItemData) {
$autor = $authors[$authorId];
foreach ($lpItemData as $lpItemId => $lpitem) {
$title = $lpitem['title'];
$price = $lpitem['price'];
$csv_row = [];
$csv_row[] = $autor['complete_name'];
$csv_row[] = $title;
$csv_row[] = $price;
$registeredUsers = self::getCompanyLearnpathSubscription($startDate, $endDate, $lpitem['lp_id']);
$studenRegister = count($registeredUsers);
$csv_row[] = $studenRegister;
$facturar = ($studenRegister * $price);
$csv_row[] = $facturar;
$totalSudent += $studenRegister;
if ($studenRegister != 0) {
$studentsName = '';
for ($i = 0; $i < $studenRegister; $i++) {
$tempStudent = api_get_user_info($registeredUsers[$i]);
$studentsName .= $tempStudent['complete_name']." / ";
$totalStudent++;
}
$csv_row[] = trim($studentsName, " / ");
$csv_content[] = $csv_row;
$index++;
$lpCount++;
}
}
}
Export::arrayToCsv($csv_content, 'reporting_lp_by_authors');
}
}
/**
* Display a sortable table that contains an overview of all the reporting progress of all courses.
*/

@ -6596,6 +6596,7 @@ class learnpath
* @param bool $isConfigPage Optional. If is the config page, show the edit button
* @param bool $allowExpand Optional. Allow show the expand/contract button
* @param string $action
* @param array $extraField
*
* @return string
*/
@ -6604,19 +6605,32 @@ class learnpath
$showRequirementButtons = true,
$isConfigPage = false,
$allowExpand = true,
$action = ''
$action = '',
$extraField = []
) {
$actionsRight = '';
$lpId = $this->lp_id;
$back = Display::url(
Display::return_icon(
'back.png',
get_lang('ReturnToLearningPaths'),
'',
ICON_SIZE_MEDIUM
),
'lp_controller.php?'.api_get_cidreq()
);
if (!isset($extraField['backTo']) && empty($extraField['backTo'])) {
$back = Display::url(
Display::return_icon(
'back.png',
get_lang('ReturnToLearningPaths'),
'',
ICON_SIZE_MEDIUM
),
'lp_controller.php?'.api_get_cidreq()
);
} else {
$back = Display::url(
Display::return_icon(
'back.png',
get_lang('Back'),
'',
ICON_SIZE_MEDIUM
),
$extraField['backTo']
);
}
/*if ($backToBuild) {
$back = Display::url(
@ -6742,9 +6756,9 @@ class learnpath
[
'title' => get_lang('ClearAllPrerequisites'),
'href' => 'lp_controller.php?'.api_get_cidreq().'&'.http_build_query([
'action' => 'clear_prerequisites',
'lp_id' => $lpId,
]),
'action' => 'clear_prerequisites',
'lp_id' => $lpId,
]),
],
];
$actionsRight = Display::groupButtonWithDropDown(
@ -6754,6 +6768,21 @@ class learnpath
);
}
if (isset($extraField['authorlp'])) {
$actionsLeft .= Display::url(
Display::return_icon(
'add-groups.png',
get_lang('Author'),
'',
ICON_SIZE_MEDIUM
),
'lp_controller.php?'.api_get_cidreq().'&'.http_build_query([
'action' => 'author_view',
'lp_id' => $lpId,
])
);
}
$toolbar = Display::toolbarAction(
'actions-lp-controller',
[$actionsLeft, $actionsRight]

@ -0,0 +1,379 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* This is a learning path editor autor.
*
* @author Carlos Alvarado
* @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update
* @author Julio Montoya - Improving the list of templates
*
* @package chamilo.learnpath
*/
$this_section = SECTION_COURSES;
api_protect_course_script();
$isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
$lpId = isset($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : 0;
$submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
$type = isset($_GET['type']) ? $_GET['type'] : null;
$action = isset($_GET['action']) ? $_GET['action'] : null;
$is_allowed_to_edit = api_is_allowed_to_edit(null, false);
$listUrl = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=view&lp_id='.$lpId.'&'.api_get_cidreq().'&isStudentView=true';
if (!$is_allowed_to_edit) {
header("Location: $listUrl");
exit;
}
/** @var learnpath $learnPath */
$learnPath = Session::read('oLP');
/*
echo "<pre>".var_export($learnPath->authorsAvaible,true)."</pre>";
exit();
*/
if (empty($learnPath)) {
api_not_allowed();
}
if ($learnPath->get_lp_session_id() != api_get_session_id()) {
// You cannot edit an LP from a base course.
header("Location: $listUrl");
exit;
}
$htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array()."
function load_cbo(id, previousId) {
if (!id) {
return false;
}
previousId = previousId || 'previous';
var cbo = document.getElementById(previousId);
for (var i = cbo.length - 1; i > 0; i--) {
cbo.options[i] = null;
}
var k=0;
for (var i = 1; i <= child_name[id].length; i++){
var option = new Option(child_name[id][i - 1], child_value[id][i - 1]);
option.style.paddingLeft = '40px';
cbo.options[i] = option;
k = i;
}
cbo.options[k].selected = true;
$('#' + previousId).selectpicker('refresh');
}
$(function() {
if ($('#previous')) {
if('parent is'+$('#idParent').val()) {
load_cbo($('#idParent').val());
}
}
$('.lp_resource_element').click(function() {
window.location.href = $('a', this).attr('href');
});
CKEDITOR.on('instanceReady', function (e) {
showTemplates('content_lp');
});
});
</script>";
if (api_is_in_gradebook()) {
$interbreadcrumb[] = [
'url' => Category::getUrl(),
'name' => get_lang('ToolGradebook'),
];
}
$htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']);
$interbreadcrumb[] = [
'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
'name' => get_lang('LearningPaths'),
];
$interbreadcrumb[] = [
'url' => api_get_self()."?action=build&lp_id=$lpId&".api_get_cidreq(),
'name' => $learnPath->getNameNoTags(),
];
switch ($type) {
case 'dir':
$interbreadcrumb[] = [
'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id().'&'.api_get_cidreq(),
'name' => get_lang('NewStep'),
];
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewChapter')];
break;
case 'document':
$interbreadcrumb[] = [
'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id().'&'.api_get_cidreq(),
'name' => get_lang('NewStep'),
];
break;
default:
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewStep')];
break;
}
if ($action === 'add_item' && $type === 'document') {
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewDocumentCreated')];
}
// Theme calls.
$show_learn_path = true;
$lp_theme_css = $learnPath->get_theme();
Display::display_header(null, 'Path');
$suredel = trim(get_lang('AreYouSureToDeleteJS'));
?>
<script>
function stripslashes(str) {
str = str.replace(/\\'/g, '\'');
str = str.replace(/\\"/g, '"');
str = str.replace(/\\\\/g, '\\');
str = str.replace(/\\0/g, '\0');
return str;
}
function confirmation(name) {
name = stripslashes(name);
if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
return true;
} else {
return false;
}
}
$(function () {
jQuery('.scrollbar-inner').scrollbar();
$('#subtab ').on('click', 'a:first', function () {
window.location.reload();
});
expandColumnToogle('#hide_bar_template', {
selector: '#lp_sidebar'
}, {
selector: '#doc_form'
});
$('.lp-btn-associate-forum').on('click', function (e) {
var associate = confirm('<?php echo get_lang('ConfirmAssociateForumToLPItem'); ?>');
if (!associate) {
e.preventDefault();
}
});
$('.lp-btn-dissociate-forum').on('click', function (e) {
var dissociate = confirm('<?php echo get_lang('ConfirmDissociateForumToLPItem'); ?>');
if (!dissociate) {
e.preventDefault();
}
});
// hide the current template list for new documment until it tab clicked
$('#frmModel').hide();
});
// document template for new document tab handler
$(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
var id = e.target.id;
if (id == 'subtab2') {
$('#frmModel').show();
} else {
$('#frmModel').hide();
}
})
</script>
<?php
$extraField = [];
$form = new FormValidator('configure_homepage_'.$action,
'post',
$_SERVER['REQUEST_URI'].'&sub_action=author_view',
'',
['style' => 'margin: 0px;']);
$extraField['backTo'] = api_get_self().'?action=add_item&type=step&lp_id='.intval($lpId).'&'.api_get_cidreq();
echo $learnPath->build_action_menu(false,
true,
false,
true,
'',
$extraField);
echo '<div class="row">';
echo '<div id="lp_sidebar" class="col-md-4">';
echo $learnPath->return_new_tree(null, false);
// Second Col
$message = Session::read('message');
$messageError = Session::read('messageError');
// Show the template list.
if (($type == 'document' || $type == 'step') && !isset($_GET['file'])) {
// Show the template list.
echo '<div id="frmModel" class="scrollbar-inner lp-add-item">';
echo '</div>';
}
echo '</div>';
$form->addHtml('<div id="doc_form" class="col-md-12 row">');
if (!empty($message)) {
$form->addHtml(Display::return_message($message));
Session::erase('message');
}
if (!empty($messageError)) {
$form->addHtml(Display::return_message($messageError, 'warning'));
Session::erase('messageError');
}
$extraFieldValue = new ExtraFieldValue('lp_item');
$form->addHtml('<h1 class="col-md-12 text-center">'.get_lang('LpByAuthor').'</h1>');
$default = [];
$form->addHtml('<div class="col-xs-12 row" >');
$defaultAuthor = [];
foreach ($_SESSION['oLP']->items as $item) {
$itemName = $item->name;
$itemId = $item->iId;
$extraFieldValues = $extraFieldValue->get_values_by_handler_and_field_variable(
$itemId,
strtolower('AuthorLPItem')
);
$authorName = [];
if (!empty($extraFieldValues)) {
if ($extraFieldValues != false) {
$authors = explode(';', $extraFieldValues['value']);
if (!empty($authors)) {
foreach ($authors as $author) {
if ($author != 0) {
$defaultAuthor[$author] = $author;
// $default["itemSelected[$itemId]"] = true;
$teacher = api_get_user_info($author);
$authorName[] = $teacher['complete_name'];
}
}
}
}
}
if (count($authorName) != 0) {
$authorName = " (".implode(', ', $authorName).")";
} else {
$authorName = '';
}
$form->addCheckBox("itemSelected[$itemId]", null, Display::return_icon('lp_document.png', $itemName).$itemName.$authorName);
$default["itemSelected"][$itemId] = false;
}
$options = [0 => get_lang('RemoveSelected')];
$default["authorItemSelect"] = [];
$form->addHtml('</div>');
/* Authors*/
$teachers = [];
$field = new ExtraField('user');
$authorLp = $field->get_handler_field_info_by_field_variable('authorlp');
$idExtraField = (int) (isset($authorLp['id']) ? $authorLp['id'] : 0);
if ($idExtraField != 0) {
$extraFieldValueUser = new ExtraFieldValue('user');
$arrayExtraFieldValueUser = $extraFieldValueUser->get_item_id_from_field_variable_and_field_value(
$authorLp['variable'],
1,
true,
false,
true);
foreach ($arrayExtraFieldValueUser as $item) {
$teacher = api_get_user_info($item['item_id']);
$teachers[] = $teacher;
}
}
/* Authors*/
foreach ($teachers as $key => $value) {
$authorId = $value['id'];
$authorName = $value['complete_name'];
if (!empty($authorName)) {
$options[$authorId] = $authorName;
if (isset($defaultAuthor[$authorId])) {
// $default["authorItemSelect"][$authorId] = $authorId;
}
}
}
$form->addSelect('authorItemSelect', get_lang('Authors'), $options, [
'multiple' => 'multiple',
]);
$form->addHtml('</div>');
$form->addButtonCreate(get_lang('Send'));
$form->setDefaults($default);
$form->display();
echo '</div>';
echo '</div>';
if ($form->validate()) {
if (isset($_GET['sub_action']) && ($_GET['sub_action'] === 'author_view')) {
$authors = $_POST['authorItemSelect'];
$items = $_POST['itemSelected'];
unset($author);
$saveExtraFieldItem = [];
$saveAuthor = [];
$removeExist = 0;
foreach ($_SESSION['oLP']->items as $item) {
$itemName = $item->name;
$itemId = $item->iId;
if (isset($items[$itemId])) {
if (count($authors) == 0) {
$saveExtraFieldItem[$itemId][0] = 0;
}
foreach ($authors as $author) {
if ($author == 0 || $removeExist == 1) {
$saveExtraFieldItem[$itemId][0] = 0;
$removeExist = 1;
} else {
$saveExtraFieldItem[$itemId][$author] = $author;
}
}
}
}
if (count($saveExtraFieldItem) > 0) {
$messages = '';
$lastEdited = [];
foreach ($saveExtraFieldItem as $saveItemId => $values) {
$extraFieldValues = $extraFieldValue->get_values_by_handler_and_field_variable(
$saveItemId,
'AuthorLPItem'
);
$extraFieldValue->save([
'variable' => 'AuthorLPItem',
'value' => $values,
'item_id' => $saveItemId,
]);
$lastEdited = $values;
$saveAuthor[] = $options[$author];
}
$saveAuthor = array_unique($saveAuthor);
$messages .= implode(' / ', $saveAuthor);
$currentUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http")."://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if (!empty($messages)) {
if ($removeExist) {
Session::write('messageError', get_lang('DeletedAuthors'));
//header("Location: $currentUrl");
echo "<script>window.location.replace(\"$currentUrl\");</script>";
die();
}
Session::write('message', get_lang('RegisteredAuthors')." ".$messages);
//header("Location: $currentUrl");
echo "<script>window.location.replace(\"$currentUrl\");</script>";
die();
}
}
}
}
Display::display_footer();

@ -50,7 +50,7 @@ function load_cbo(id, previousId) {
if (!id) {
return false;
}
previousId = previousId || 'previous';
var cbo = document.getElementById(previousId);
@ -193,8 +193,19 @@ $(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
})
</script>
<?php
$extraField = [];
$field = new ExtraField('user');
$authorLpField = $field->get_handler_field_info_by_field_variable('authorlp');
if ($authorLpField != null) {
$extraField['authorlp'] = $authorLpField;
}
echo $learnPath->build_action_menu();
echo $learnPath->build_action_menu(false,
true,
false,
true,
'',
$extraField);
echo '<div class="row">';
echo '<div id="lp_sidebar" class="col-md-4">';
echo $learnPath->return_new_tree(null, true);

@ -503,6 +503,40 @@ if ($debug > 0) {
}
switch ($action) {
case 'author_view':
/* Authors*/
$teachers = [];
$field = new ExtraField('user');
$authorLp = $field->get_handler_field_info_by_field_variable('authorlp');
$idExtraField = (int) (isset($authorLp['id']) ? $authorLp['id'] : 0);
if ($idExtraField != 0) {
$extraFieldValueUser = new ExtraFieldValue('user');
$arrayExtraFieldValueUser = $extraFieldValueUser->get_item_id_from_field_variable_and_field_value(
$authorLp['variable'],
1,
true,
false,
true);
foreach ($arrayExtraFieldValueUser as $item) {
$teacher = api_get_user_info($item['item_id']);
$teachers[] = $teacher;
}
}
/* Authors*/
$_SESSION['oLP']->authorsAvaible = $teachers;
Session::write('oLP', $_SESSION['oLP']);
if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
if (!$lp_found) {
// Check if the learnpath ID was defined, otherwise send back to list
require 'lp_list.php';
} else {
require 'lp_add_author.php';
}
break;
case 'send_notify_teacher':
// Send notification to the teacher
$studentInfo = api_get_user_info();

@ -119,7 +119,18 @@ $(function() {
</script>
<?php
echo $learnPath->build_action_menu();
$extraField = [];
$field = new ExtraField('lp_item');
$authorLpField = $field->get_handler_field_info_by_field_variable('authorlpitem');
if ($authorLpField != null) {
$extraField['authorlp'] = $authorLpField;
}
echo $learnPath->build_action_menu(false,
true,
false,
true,
'',
$extraField);
echo '<div class="row">';
echo '<div id="lp_sidebar" class="col-md-4">';

@ -34,6 +34,19 @@ function showHideStudent(el){
$("#"+el+"_").find(".icon_remove").addClass("hidden");
}
}
function ShowMoreAuthor(el){
if($(".author_"+el).hasClass("hidden")){
$(".author_"+el).removeClass("hidden");
$(".icon_remove_author_"+el).removeClass("hidden");
$(".icon_add_author_"+el).addClass("hidden");
}else{
$(".author_"+el).addClass("hidden")
$(".icon_remove_author_"+el).addClass("hidden");
$(".icon_add_author_"+el).removeClass("hidden");
}
}
</script>';
// the section (for the tabs)
@ -63,6 +76,9 @@ if ($exportCSV) {
} elseif ('learningPath' === $display) {
MySpace::displayResumeLP($startDate, $endDate, true);
exit;
} elseif ('learningPathByItem' === $display) {
MySpace::displayResumeLpByItem($startDate, $endDate, true);
exit;
}
}
@ -91,6 +107,9 @@ switch ($display) {
case 'learningPath':
MySpace::displayResumeLP($startDate, $endDate);
break;
case 'learningPathByItem':
MySpace::displayResumeLpByItem($startDate, $endDate);
break;
case 'accessoverview':
$courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0;
$sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0;

@ -43,40 +43,45 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
);
$this->tblExtraField = Database::get_main_table(TABLE_EXTRA_FIELD);
$this->tblExtraFieldOption = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS);
$companyField = ExtraField::getDisplayNameByVariable('company');
$field = new ExtraField('user');
$companyField = $field->get_handler_field_info_by_field_variable('company');
$this->companyExist = false;
if (!empty($companyField)) {
if (empty($companyField)) {
$this->companyExist = true;
$this->companyField = $companyField;
} else {
$this->companyField = [
'field_type' => ExtraField::FIELD_TYPE_RADIO,
'variable' => 'company',
'display_text' => 'Company',
'default_value' => '',
'field_order' => 0,
'visible_to_self' => 0,
'visible_to_others' => 0,
'changeable' => 1,
'filter' => 1,
];
}
$authorsField = ExtraField::getDisplayNameByVariable('authors');
$field = new ExtraField('lp');
$authorsField = $field->get_handler_field_info_by_field_variable('authors');
$this->authorsExist = false;
if (!empty($authorsField)) {
$this->authorsExist = false;
if (empty($authorsField)) {
$this->authorsExist = true;
$this->authorsField = $authorsField;
} else {
$this->authorsField = [
'field_type' => ExtraField::FIELD_TYPE_SELECT_MULTIPLE,
'variable' => 'authors',
'display_text' => 'Authors',
'default_value' => '',
'field_order' => 0,
'visible_to_self' => 1,
'visible_to_others' => 0,
'changeable' => 1,
'filter' => 1,
];
}
$this->authorsField = [
'extra_field_type' => ExtraField::FIELD_TYPE_DATE,
'field_type' => ExtraField::FIELD_TYPE_SELECT_MULTIPLE,
'variable' => 'authors',
'display_text' => 'Authors',
'default_value' => '',
'field_order' => 0,
'visible_to_self' => 1,
'visible_to_others' => 0,
'changeable' => 1,
'filter' => 1,
];
$this->companyField = [
'extra_field_type' => ExtraField::FIELD_TYPE_TEXT,
'field_type' => ExtraField::FIELD_TYPE_RADIO,
'variable' => 'company',
'display_text' => 'Company',
'default_value' => '',
'field_order' => 0,
'visible_to_self' => 0,
'visible_to_others' => 0,
'changeable' => 1,
'filter' => 1,
];
}
/**
@ -96,15 +101,12 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
*/
public function install()
{
$companyExist = $this->CompanyFieldExist();
if ($companyExist == false) {
$this->SaveCompanyField();
$this->setCompanyExtrafieldData();
}
$authorsExist = $this->AuthorsFieldExist();
if ($authorsExist == false) {
$this->SaveAuthorsField();
}
$this->SaveCompanyField();
$this->setCompanyExtrafieldData();
$this->SaveAuthorsField();
$this->SavePrice();
$this->SaveAuthorLPItem();
$this->SaveAuthorLp();
}
/**
@ -144,7 +146,6 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
public function SaveCompanyField()
{
$data = $this->companyField;
$data['extra_field_type'] = (int) $data['extra_field_type'];
$data['field_type'] = (int) $data['field_type'];
$data['field_order'] = (int) $data['field_order'];
$data['visible_to_self'] = (int) $data['visible_to_self'];
@ -156,7 +157,7 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
$data['visible'] = 1;
$data['display_text'] = strtolower(Database::escape_string(Security::remove_XSS($data['display_text'])));
$schedule = new ExtraField('user');
$schedule->save($data);
$this->companyField['id'] = $schedule->save($data);
}
/**
@ -180,9 +181,10 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
*/
public function getAuthorsField()
{
$authorsField = $this->getInfoExtrafield('authors');
if (count($authorsField) > 1) {
$this->authorsField = $authorsField;
$schedule = new ExtraField('lp');
$data = $schedule->get_handler_field_info_by_field_variable('authors');
if (empty($data)) {
$this->authorsField = $data;
} else {
$authorsField = $this->authorsField;
}
@ -190,13 +192,75 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
return $authorsField;
}
/**
* Save the arrangement for price, it is adjusted internally so that the values match the necessary ones.
*/
public function SavePrice()
{
$data = $this->authorsField;
$schedule = new ExtraField('lp_item');
$data['visible_to_self'] = 1;
$data['visible_to_others'] = 1;
$data['changeable'] = 1;
$data['filter'] = 0;
$data['variable'] = 'price';
$data['display_text'] = 'SalePrice';
$data['field_type'] = ExtraField::FIELD_TYPE_INTEGER;
$schedule->save($data);
}
/**
* Save the arrangement for AuthorLPItem, it is adjusted internally so that the values match the necessary ones.
*/
public function SaveAuthorLPItem()
{
$data = $this->authorsField;
$schedule = new ExtraField('lp_item');
$data['visible_to_self'] = 0;
$data['visible_to_others'] = 0;
$data['changeable'] = 1;
$data['filter'] = 0;
$data['variable'] = 'authorlpitem';
$data['display_text'] = 'LearningPathItemByAuthor';
$data['field_type'] = ExtraField::FIELD_TYPE_SELECT_MULTIPLE;
$this->authorsField['id'] = $schedule->save($data);
}
/**
* Save the arrangement for authorlp, it is adjusted internally so that the values match the necessary ones.
*/
public function SaveAuthorLp()
{
$schedule = new ExtraField('user');
$data = $schedule->get_handler_field_info_by_field_variable('authorlp');
if (empty($data)) {
$data = $this->authorsField;
}
if (!isset($data['id']) || (int) $data['id'] == 0) {
$data['variable'] = 'authorlp';
$data['display_text'] = 'authors';
$data['changeable'] = 1;
$data['visible_to_self'] = 1;
$data['visible_to_others'] = 0;
$data['filter'] = 0;
$data['field_type'] = ExtraField::FIELD_TYPE_RADIO;
$id = $schedule->save($data);
} else {
$this->authorsField = $data;
$id = $data['id'];
}
$this->setYesNoToAuthor($id);
}
/**
* Save the arrangement for authors, it is adjusted internally so that the values match the necessary ones.
*/
public function SaveAuthorsField()
{
$data = $this->authorsField;
$data['extra_field_type'] = (int) $data['extra_field_type'];
$data['field_type'] = (int) $data['field_type'];
$data['field_order'] = (int) $data['field_order'];
$data['visible_to_self'] = (int) $data['visible_to_self'];
@ -206,11 +270,48 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
$data['default_value'] = null;
$data['variable'] = 'authors';
$data['visible'] = 1;
$data['display_text'] = strtolower(Database::escape_string(Security::remove_XSS($data['display_text'])));
$data['display_text'] = strtolower($data['display_text']);
$schedule = new ExtraField('lp');
$schedule->save($data);
}
/**
* Set Yes or Not selector for authorlp field.
*
* @param $authorLpId
*/
public function setYesNoToAuthor($authorLpId)
{
$options = [
0 => 'No',
1 => 'Yes',
];
$order = 0;
$authorId = (int) $authorLpId;
if ($authorId != 0) {
$extraFieldValueUser = new ExtraFieldOption('user');
$items = $extraFieldValueUser->get_field_options_by_field($authorLpId);
foreach ($items as $item) {
if (isset($options[0]) && (isset($item['option_value']) == $options[0] || isset($item['option_value']) == $options[1])) {
unset($options[$item['option_value']]);
$order++;
}
}
for ($i = 0; $i < count($options); $i++) {
$extraFieldOptionValue = $options[$i];
$fieldOption = new ExtraFieldOption('user');
$fieldOption->saveOptions([
'field_id' => $authorLpId,
'option_value' => $order,
'display_text' => $extraFieldOptionValue,
'option_order' => $order,
]);
$order++;
}
}
}
/**
* Remove the extra fields set by the plugin.
*/
@ -218,11 +319,11 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
{
$companyExist = $this->CompanyFieldExist();
if ($companyExist == true) {
$this->removeCompanyField();
// $this->removeCompanyField();
}
$authorsExist = $this->AuthorsFieldExist();
if ($authorsExist == true) {
$this->removeAuthorsField();
// $this->removeAuthorsField();
}
}
@ -232,7 +333,7 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
public function removeCompanyField()
{
$data = $this->getCompanyField();
$this->deleteQuery($data);
// $this->deleteQuery($data);
}
/**
@ -241,7 +342,7 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
public function removeAuthorsField()
{
$data = $this->getAuthorsField();
$this->deleteQuery($data);
// $this->deleteQuery($data);
}
/**
@ -254,31 +355,25 @@ class CheckExtraFieldAuthorsCompanyPlugin extends Plugin
1 => 'Company 2',
2 => 'Company 3',
];
$order = 0;
$query = "SELECT
id
FROM
".$this->tblExtraField."
WHERE
variable = 'company'";
$companyId = Database::fetch_assoc(Database::query($query));
$companyId = isset($companyId['id']) ? $companyId['id'] : null;
for ($i = 0; $i < count($companys); $i++) {
$order = $i + 1;
$extraFieldOptionValue = $companys[$i];
if ($companyId != null) {
$query = "SELECT * from ".$this->tblExtraFieldOption." where option_value = '$extraFieldOptionValue'";
$extraFieldOption = Database::fetch_assoc(Database::query($query));
if (isset($extraFieldOption['id']) && $extraFieldOption['id'] && $extraFieldOption['field_id'] == $companyId) {
// Update?
} else {
$query = "
$companyId = (int) $this->companyField['id'];
if ($companyId != 0) {
for ($i = 0; $i < count($companys); $i++) {
$order = $i + 1;
$extraFieldOptionValue = $companys[$i];
if ($companyId != null) {
$query = "SELECT * from ".$this->tblExtraFieldOption." where option_value = '$extraFieldOptionValue' and field_id = $companyId";
$extraFieldOption = Database::fetch_assoc(Database::query($query));
if (isset($extraFieldOption['id']) && $extraFieldOption['id'] && $extraFieldOption['field_id'] == $companyId) {
// Update?
} else {
$query = "
INSERT INTO ".$this->tblExtraFieldOption."
(`field_id`, `option_value`, `display_text`, `priority`, `priority_message`, `option_order`) VALUES
( '$companyId', '$extraFieldOptionValue', '$extraFieldOptionValue', NULL, NULL, '$order');
";
$data = Database::query($query);
$data = Database::query($query);
}
}
}
}

@ -15,6 +15,8 @@
* Plugin details (must be present).
*/
$plugin_info['title'] = 'Reports: "Distribution by entity" and "Distribution by author"';
$plugin_info['comment'] = 'Adjust the variables to display the "Distribution by entity" and "Distribution by author" reports.';
$plugin_info['version'] = '1.0'; // o la versión que corresponda
$plugin_info['comment'] = 'To enable report, You must activate the user subscription to the learning path through the '.
'"Course settings" -> "Subscribe users to learning path" <br>'.
'Then you can go to /main/mySpace/ to see the reports.';
$plugin_info['version'] = '1.1'; // o la versión que corresponda
$plugin_info['author'] = 'Carlos Alvarado';

Loading…
Cancel
Save