Career: Add 'career_hierarchy_enable' extra field and allow to hierarchy careers - refs BT#20711

pull/4720/head
Borja Sánchez 2 years ago
parent 4b4c955ca0
commit 564f15c51b
  1. 45
      main/admin/career_dashboard.php
  2. 16
      main/admin/careers.php
  3. 2
      main/inc/ajax/model.ajax.php
  4. 50
      main/inc/lib/career.lib.php
  5. 8
      main/install/configuration.dist.php
  6. 6
      main/template/default/admin/career_dashboard_hierarchy.tpl
  7. 44
      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,10 @@ $interbreadcrumb[] = [
$tpl = new Template(get_lang('CareersAndPromotions'));
$html = null;
$showHierarchy = $_GET['showHierarchy'] ?? null;
if ($useCareerHierarchy && is_null($showHierarchy)) {
$showHierarchy = 1;
}
$form = new FormValidator('filter_form', 'GET', api_get_self());
$career = new Career();
@ -57,6 +62,9 @@ $form->addSelect(
);
$form->addButtonSearch(get_lang('Filter'));
if ($useCareerHierarchy && $showHierarchy == 1) {
$form->addHidden('showHierarchy', '0');
}
// action links
$actionLeft = Display::url(
Display::return_icon(
@ -76,7 +84,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,11 +144,12 @@ if (!empty($careers)) {
continue; //avoid status = 0
}
$session_list = [];
// Getting all sessions from this promotion
if (!$useCareerHierarchy || 0 == $showHierarchy) {
$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[] = [
@ -126,6 +157,7 @@ if (!empty($careers)) {
'courses' => $course_list,
];
}
}
$promotion_array[$promotion_item['id']] = [
'id' => $promotion_item['id'],
'name' => $promotion_item['name'],
@ -143,9 +175,16 @@ if (!empty($careers)) {
$careers[$career_item['id']]['career'] = $careerList;
}
}
if ($useCareerHierarchy && 1 == $showHierarchy) {
$careers = $career->orderCareersByHierarchy($careers);
}
$tpl->assign('actions', $actions);
$tpl->assign('form_filter', $html);
$tpl->assign('data', $careers);
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,6 +204,12 @@ switch ($action) {
api_protect_admin_script();
// Action handling: delete
if ($check) {
$childCareers = $career->get_all(['parent_id' => $_GET['id']]);
if (!empty($childCareers)) {
Display::addFlash(
Display::return_message(get_lang('CareerCannotBeDeletedAsItHasChildren'), 'warning')
);
} else {
$res = $career->delete($_GET['id']);
if ($res) {
Display::addFlash(
@ -204,6 +217,7 @@ switch ($action) {
);
}
}
}
header('Location: '.$listUrl);
exit;
break;

@ -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,34 @@ class Career extends Model
);
}
/**
* Order the careers by its hierarchy
*
* @param $careers
* @return array
*/
public function orderCareersByHierarchy($careers): array
{
$orderedCareers = array();
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'] = array();
}
$careers[$pid]['children'][] = &$career;
}
}
}
return $orderedCareers;
}
/**
* Update all promotion status by career.
*
@ -150,6 +179,22 @@ class Career extends Model
];
}
/**
* Return the name of the careers that are parents of others
*/
public function getHierarchies(): array
{
$return = [];
$result = Database::select('name, id', $this->table, [ 'order' => 'id ASC']);
foreach ($result as $item) {
$return[$item['id']] = $item['name'];
}
array_unshift($return, '--');
return $return;
}
/**
* Returns a Form validator Obj.
*
@ -187,6 +232,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();
$form->addElement('select', 'parent_id', get_lang('ParentCareer'), $hierarchyList);
}
if ($action == 'edit') {
$extraField = new ExtraField('career');
$extraField->addElements($form, $id);

@ -2384,6 +2384,14 @@ ALTER TABLE c_wiki_category ADD CONSTRAINT FK_17F1099A727ACA70 FOREIGN KEY (pare
// 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
// Add user activation by confirmation email

@ -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,50 @@
</div>
{% endmacro %}
{% macro careers_panel(content, admin) %}
{% import _self as display %}
{% for item in content %}
<div id="career-{{ item.id }}" class="career panel panel-default" style="padding: 20px">
<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 }}
<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>
</div>
{% if item.children is defined %}
{{ display.careers_panel(item.children, admin) }}
{% 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