Commit df0678c9 authored by Dainis Abols's avatar Dainis Abols
Browse files

Fixed multiple departments bug

v3.3.2
parent f74940f7
......@@ -11,7 +11,6 @@ use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @version 3.0.0
* @since 29.06.2018
*
* @package Lu\LuContacts\Models
......@@ -110,7 +109,7 @@ class Person
// Add position and phone info
if ($item['_childDocuments_']) {
$k=0;
$k = 0;
foreach ($item['_childDocuments_'] as $children) {
$k++;
......@@ -119,9 +118,8 @@ class Person
$tmp['position'][$k] = $children['name'];
}
// dd($children);
if ($children['unit_ids']) {
foreach($children['unit_ids'] as $keyUnitId) {
foreach ($children['unit_ids'] as $keyUnitId) {
if (key_exists($keyUnitId, $tmp['unitNames']) && !key_exists($keyUnitId, $tmp['unit'])) {
$tmp['unit'][$k][] = $tmp['unitNames'][$keyUnitId];
}
......@@ -134,9 +132,6 @@ class Person
$tmp['phone'][$k] = $this->implode($children['phone']);
}
}
// Reverse workplace position results [Why was this needed?? [Dainis]]
// $tmp['position'] = array_reverse($tmp['position']);
}
$tmp['unit'] = $this->implode($tmp['unit']);
......@@ -353,15 +348,20 @@ class Person
}
// Fetch unit IDs foe person
foreach($details['unit_ids'] as $userUnitId) {
foreach ($details['unit_ids'] as $userUnitId) {
if ($recursive) {
$UnitModel = new Unit();
$userUnits = array_reverse($UnitModel->getRecursiveUnitIds($userUnitId));
$UnitModel = new Unit();
$userUnits[] = array_reverse($UnitModel->getRecursiveUnitIds($userUnitId));
} else {
$userUnits[] = $userUnitId;
}
}
// Flatten into onel evel array
if (!empty($userUnits)) {
$userUnits = $this->array_flatten($userUnits);
}
// Return result
return in_array($unitId, $userUnits);
}
......@@ -377,4 +377,30 @@ class Person
{
return '<img src="'.$image.'" />';
}
}
\ No newline at end of file
/**
* Flattens array.
*
* @param array $array
*
* @return array
*/
private function array_flatten(array $array)
{
$flat = []; // initialize return array
$stack = array_values($array); // initialize stack
while ($stack) // process stack until done
{
$value = array_shift($stack);
if (is_array($value)) // a value to further process
{
array_unshift($stack, ...$value);
} else // a value to take
{
$flat[] = $value;
}
}
return $flat;
}
}
{
"name": "luitd/lu-contacts",
"version": "3.3.1",
"version": "3.3.2",
"description": "University of Latvia contact list render",
"type": "typo3-cms-extension",
"keywords": [
......
......@@ -9,7 +9,7 @@ $EM_CONF[$_EXTKEY] = [
'author_email' => 'dainis.abols@lu.lv',
'state' => 'stable',
'clearCacheOnLoad' => true,
'version' => '3.3.1',
'version' => '3.3.2',
'dependencies' => 'typo3,lu_api',
'constraints' => [
'depends' => [
......
......@@ -4,7 +4,7 @@ Extension to render list of contacts for University of Latvia
## Version
3.3.1
3.3.2
## Dependencies
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment