Career: Add 'career_hierarchy_enable' extra field and allow to hierarchy careers - refs BT#20711
pull/4737/head
Nicolas Ducoulombier 2 years ago committed by GitHub
commit ed8517e9b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 72
      main/admin/career_dashboard.php
  2. 22
      main/admin/careers.php
  3. 2
      main/inc/ajax/model.ajax.php
  4. 60
      main/inc/lib/career.lib.php
  5. 10
      main/install/configuration.dist.php
  6. 6
      main/template/default/admin/career_dashboard_hierarchy.tpl
  7. 45
      main/template/default/macro/macro.tpl
  8. 7
      src/Chamilo/CoreBundle/Entity/Career.php

@ -9,6 +9,7 @@ $cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
$useCareerHierarchy = api_get_configuration_value('career_hierarchy_enable');
api_protect_admin_script($allowCareer);
@ -29,6 +30,12 @@ $interbreadcrumb[] = [
$tpl = new Template(get_lang('CareersAndPromotions'));
$html = null;
$showHierarchy = $_GET['showHierarchy'] ?? null;
if ($useCareerHierarchy && is_null($showHierarchy)) {
$showHierarchy = 1;
} elseif (!$useCareerHierarchy) {
$showHierarchy = 0;
}
$form = new FormValidator('filter_form', 'GET', api_get_self());
$career = new Career();
@ -37,7 +44,7 @@ $condition = ['status = ?' => 1];
if ($form->validate()) {
$data = $form->getSubmitValues();
$filter = (int) $data['filter'];
if (!empty($filter)) {
if (!empty($filter) && $showHierarchy == 0) {
$condition = ['status = ? AND id = ? ' => [1, $filter]];
}
}
@ -57,6 +64,11 @@ $form->addSelect(
);
$form->addButtonSearch(get_lang('Filter'));
if ($useCareerHierarchy && $showHierarchy == 1) {
$form->addHidden('showHierarchy', '1');
} else {
$form->addHidden('showHierarchy', '0');
}
// action links
$actionLeft = Display::url(
Display::return_icon(
@ -76,7 +88,29 @@ $actionLeft .= Display::url(
),
'careers.php'
);
if ($useCareerHierarchy) {
if ($showHierarchy) {
$actionLeft .= Display::url(
Display::return_icon(
'forum_listview.png',
get_lang('HideCareersHierarchy'),
null,
ICON_SIZE_MEDIUM
),
'career_dashboard.php?showHierarchy=0'
);
} else {
$actionLeft .= Display::url(
Display::return_icon(
'forum_nestedview.png',
get_lang('ShowCareersHierarchy'),
null,
ICON_SIZE_MEDIUM
),
'career_dashboard.php?showHierarchy=1'
);
}
}
if (api_is_platform_admin()) {
$actionLeft .= Display::url(
Display::return_icon(
@ -114,17 +148,19 @@ if (!empty($careers)) {
continue; //avoid status = 0
}
// Getting all sessions from this promotion
$sessions = SessionManager::get_all_sessions_by_promotion(
$promotion_item['id']
);
$session_list = [];
foreach ($sessions as $session_item) {
$course_list = SessionManager::get_course_list_by_session_id($session_item['id']);
$session_list[] = [
'data' => $session_item,
'courses' => $course_list,
];
// Getting all sessions from this promotion
if (!$useCareerHierarchy || 0 == $showHierarchy) {
$sessions = SessionManager::get_all_sessions_by_promotion(
$promotion_item['id']
);
foreach ($sessions as $session_item) {
$course_list = SessionManager::get_course_list_by_session_id($session_item['id']);
$session_list[] = [
'data' => $session_item,
'courses' => $course_list,
];
}
}
$promotion_array[$promotion_item['id']] = [
'id' => $promotion_item['id'],
@ -143,9 +179,17 @@ if (!empty($careers)) {
$careers[$career_item['id']]['career'] = $careerList;
}
}
if ($useCareerHierarchy && 1 == $showHierarchy) {
$filter = $filter ?? 0;
$careers = $career->orderCareersByHierarchy($careers, $filter);
}
$tpl->assign('actions', $actions);
$tpl->assign('form_filter', $html);
$tpl->assign('data', $careers);
$layout = $tpl->get_template('admin/career_dashboard.tpl');
if ($useCareerHierarchy && 1 == $showHierarchy) {
$layout = $tpl->get_template('admin/career_dashboard_hierarchy.tpl');
} else {
$layout = $tpl->get_template('admin/career_dashboard.tpl');
}
$tpl->display($layout);

@ -9,6 +9,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
$allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
$useCareerHierarchy = api_get_configuration_value('career_hierarchy_enable');
api_protect_admin_script($allowCareer);
// Add the JS needed to use the jqgrid
@ -43,7 +44,7 @@ if ($action === 'add') {
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_careers';
//The order is important you need to check the the $column variable in the model.ajax.php file
//The order is important you need to check the $column variable in the model.ajax.php file
$columns = [get_lang('Name'), get_lang('Description'), get_lang('Actions')];
// Column config
@ -122,6 +123,9 @@ switch ($action) {
// The validation or display
if ($form->validate()) {
$values = $form->exportValues();
if (isset($values['parent_id']) && '0' === $values['parent_id']) {
$values['parent_id'] = null;
}
$res = $career->save($values);
if ($res) {
Display::addFlash(
@ -155,6 +159,9 @@ switch ($action) {
$values = $form->exportValues();
$career->update_all_promotion_status_by_career_id($values['id'], $values['status']);
$old_status = $career->get_status($values['id']);
if (isset($values['parent_id']) && '0' === $values['parent_id']) {
$values['parent_id'] = null;
}
$res = $career->update($values);
$values['item_id'] = $values['id'];
@ -197,11 +204,18 @@ switch ($action) {
api_protect_admin_script();
// Action handling: delete
if ($check) {
$res = $career->delete($_GET['id']);
if ($res) {
$childCareers = $career->get_all(['parent_id' => $_GET['id']]);
if (!empty($childCareers)) {
Display::addFlash(
Display::return_message(get_lang('ItemDeleted'), 'confirmation')
Display::return_message(get_lang('CareerCannotBeDeletedAsItHasChildren'), 'warning')
);
} else {
$res = $career->delete($_GET['id']);
if ($res) {
Display::addFlash(
Display::return_message(get_lang('ItemDeleted'), 'confirmation')
);
}
}
}
header('Location: '.$listUrl);

@ -2347,7 +2347,7 @@ switch ($action) {
$result = $new_result;
break;
case 'get_careers':
$columns = ['name', 'description', 'actions', 'external_career_id'];
$columns = ['name', 'description', 'parent_id', 'actions', 'external_career_id'];
if (!in_array($sidx, $columns)) {
$sidx = 'name';
}

@ -16,6 +16,7 @@ class Career extends Model
'name',
'description',
'status',
'parent_id',
'created_at',
'updated_at',
];
@ -99,6 +100,38 @@ class Career extends Model
);
}
/**
* Order the careers by its hierarchy.
*
* @param $careers
*/
public function orderCareersByHierarchy($careers, int $filterId = 0): array
{
$orderedCareers = [];
$filterAux = [];
foreach ($careers as &$career) {
if (is_null($career['parent_id'])) {
$orderedCareers[] = &$career;
} else {
$pid = $career['parent_id'];
if (!isset($careers[$pid])) {
// Orphan child
break;
} else {
if (!isset($careers[$pid]['children'])) {
$careers[$pid]['children'] = [];
}
$careers[$pid]['children'][] = &$career;
}
}
if (!empty($filterId) && $career['id'] == $filterId) {
$filterAux[0] = &$career;
}
}
return !empty($filterId) ? $filterAux : $orderedCareers;
}
/**
* Update all promotion status by career.
*
@ -150,6 +183,28 @@ class Career extends Model
];
}
/**
* Return the name of the careers that can be parents of others.
*/
public function getHierarchies(int $selfCareer = 0): array
{
$return = [];
$result = Database::select(
'name, id',
$this->table,
[
'where' => ['id != ?' => $selfCareer],
'order' => 'id ASC',
]
);
foreach ($result as $item) {
$return[$item['id']] = $item['name'];
}
array_unshift($return, '--');
return $return;
}
/**
* Returns a Form validator Obj.
*
@ -187,6 +242,11 @@ class Career extends Model
$status_list = $this->get_status_list();
$form->addElement('select', 'status', get_lang('Status'), $status_list);
if (api_get_configuration_value('career_hierarchy_enable')) {
$hierarchyList = $this->getHierarchies((int) $id ?? 0);
$form->addElement('select', 'parent_id', get_lang('ParentCareer'), $hierarchyList);
}
if ($action == 'edit') {
$extraField = new ExtraField('career');
$extraField->addElements($form, $id);

@ -2428,6 +2428,16 @@ INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, d
// external authentication system rather than user.id.
// $_configuration['webservice_return_user_field'] = 'oauth2_id';
// Add support for careers hierarchy - refs BT#20711
// 1. This requires the following DB change:
// ALTER TABLE career add parent_id INT
// ALTER TABLE career add constraint career_career_id_fk foreign key (parent_id) references career (id);
// 2. Add an "@" before "var int" and "ORM\Column..." in the "Career::$parentId" property definition (in src/Chamilo/CoreBundle/Entity/Career.php)
// 3. Uncomment $parentId var in src/Chamilo/CoreBundle/Entity/Career.php
// $_configuration['career_hierarchy_enable'] = false;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Set to true to hide settings completely in a sub-URL if the setting is disabled in the
// main URL (where the access_url_changeable field = 0)
// $_configuration['multiple_url_hide_disabled_settings'] = false;

@ -0,0 +1,6 @@
{% extends 'layout/layout_1_col.tpl'|get_template %}
{% block content %}
{{ form_filter }}
{% import 'default/macro/macro.tpl' as display %}
{{ display.careers_panel(data, _u.is_admin) }}
{% endblock %}

@ -117,6 +117,51 @@
</div>
{% endmacro %}
{% macro careers_panel(content, admin, macro_iteration = 0) %}
{% import _self as display %}
{% for item in content %}
<div id="career-{{ item.id }}" class="career panel panel-default" {% if item.parent_id is not empty and macro_iteration != 0 %} style="margin-left: 45px"{% endif %}>
<div class="panel-heading">
<h4>
{% if admin %}
<a href="{{ _p.web }}main/admin/careers.php?action=edit&id={{ item.id }}">
{{ item.name }}
</a>
{% else %}
{{ item.name }}
{% endif %}
</h4>
</div>
<div class="panel-body">
{{ item.description }}
{% if item.career.promotions is not empty %}
<table class="table promotions">
<thead class="title">
<th>{{ 'Promotions' | get_lang }}</th>
</thead>
{% for promotions in item.career %}
{% for prom in promotions %}
<tr>
<td class="promo" rowspan="{{ line }}">
<h4 id="promotion-id-{{ prom.id }}">
<a title="{{ prom.name }}" href="{{ _p.web }}main/admin/promotions.php?action=edit&id={{ prom.id }}">
{{ prom.name }}
</a>
</h4>
</td>
</tr>
{% endfor %}
{% endfor %}
</table>
{% endif %}
</div>
{% if item.children is defined %}
{{ display.careers_panel(item.children, admin, macro_iteration + 1) }}
{% endif %}
</div>
{% endfor %}
{% endmacro %}
{% macro box_widget(name, content, icon) %}
<div class="card box-widget">
<div class="card-body">

@ -57,6 +57,13 @@ class Career
*/
protected $updatedAt;
/**
* var int.
*
* ORM\Column(name="parent_id", type="integer", nullable=true)
*/
//protected $parentId;
/**
* Get id.
*

Loading…
Cancel
Save