Block select own career as parent and improve hierarchy view

pull/4720/head
Borja Sánchez 2 years ago
parent d183d021a2
commit 425dc17eaf
  1. 15
      main/inc/lib/career.lib.php
  2. 38
      main/template/default/macro/macro.tpl

@ -180,12 +180,19 @@ class Career extends Model
}
/**
* Return the name of the careers that are parents of others.
* Return the name of the careers that can be parents of others.
*/
public function getHierarchies(): array
public function getHierarchies(int $selfCareer = 0): array
{
$return = [];
$result = Database::select('name, id', $this->table, ['order' => 'id ASC']);
$result = Database::select(
'name, id',
$this->table,
[
'where' => ['id != ?' => $selfCareer],
'order' => 'id ASC'
]
);
foreach ($result as $item) {
$return[$item['id']] = $item['name'];
}
@ -232,7 +239,7 @@ class Career extends Model
$form->addElement('select', 'status', get_lang('Status'), $status_list);
if (api_get_configuration_value('career_hierarchy_enable')) {
$hierarchyList = $this->getHierarchies();
$hierarchyList = $this->getHierarchies((int) $id ?? 0);
$form->addElement('select', 'parent_id', get_lang('ParentCareer'), $hierarchyList);
}

@ -121,7 +121,7 @@
{% import _self as display %}
{% for item in content %}
<div id="career-{{ item.id }}" class="career panel panel-default" style="padding: 20px">
<div id="career-{{ item.id }}" class="career panel panel-default" {% if item.parent_id is not empty %} style="margin-left: 45px"{% endif %}>
<div class="panel-heading">
<h4>
{% if admin %}
@ -135,24 +135,26 @@
</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>
{% 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 %}
{% endfor %}
</table>
</table>
{% endif %}
</div>
{% if item.children is defined %}
{{ display.careers_panel(item.children, admin) }}

Loading…
Cancel
Save