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; ...@@ -11,7 +11,6 @@ use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
* *
* @author Dainis Abols <dainis.abols@lu.lv> * @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia * @owner University of Latvia
* @version 3.0.0
* @since 29.06.2018 * @since 29.06.2018
* *
* @package Lu\LuContacts\Models * @package Lu\LuContacts\Models
...@@ -110,7 +109,7 @@ class Person ...@@ -110,7 +109,7 @@ class Person
// Add position and phone info // Add position and phone info
if ($item['_childDocuments_']) { if ($item['_childDocuments_']) {
$k=0; $k = 0;
foreach ($item['_childDocuments_'] as $children) { foreach ($item['_childDocuments_'] as $children) {
$k++; $k++;
...@@ -119,9 +118,8 @@ class Person ...@@ -119,9 +118,8 @@ class Person
$tmp['position'][$k] = $children['name']; $tmp['position'][$k] = $children['name'];
} }
// dd($children);
if ($children['unit_ids']) { 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'])) { if (key_exists($keyUnitId, $tmp['unitNames']) && !key_exists($keyUnitId, $tmp['unit'])) {
$tmp['unit'][$k][] = $tmp['unitNames'][$keyUnitId]; $tmp['unit'][$k][] = $tmp['unitNames'][$keyUnitId];
} }
...@@ -134,9 +132,6 @@ class Person ...@@ -134,9 +132,6 @@ class Person
$tmp['phone'][$k] = $this->implode($children['phone']); $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']); $tmp['unit'] = $this->implode($tmp['unit']);
...@@ -353,15 +348,20 @@ class Person ...@@ -353,15 +348,20 @@ class Person
} }
// Fetch unit IDs foe person // Fetch unit IDs foe person
foreach($details['unit_ids'] as $userUnitId) { foreach ($details['unit_ids'] as $userUnitId) {
if ($recursive) { if ($recursive) {
$UnitModel = new Unit(); $UnitModel = new Unit();
$userUnits = array_reverse($UnitModel->getRecursiveUnitIds($userUnitId)); $userUnits[] = array_reverse($UnitModel->getRecursiveUnitIds($userUnitId));
} else { } else {
$userUnits[] = $userUnitId; $userUnits[] = $userUnitId;
} }
} }
// Flatten into onel evel array
if (!empty($userUnits)) {
$userUnits = $this->array_flatten($userUnits);
}
// Return result // Return result
return in_array($unitId, $userUnits); return in_array($unitId, $userUnits);
} }
...@@ -377,4 +377,30 @@ class Person ...@@ -377,4 +377,30 @@ class Person
{ {
return '<img src="'.$image.'" />'; return '<img src="'.$image.'" />';
} }
/**
* 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", "name": "luitd/lu-contacts",
"version": "3.3.1", "version": "3.3.2",
"description": "University of Latvia contact list render", "description": "University of Latvia contact list render",
"type": "typo3-cms-extension", "type": "typo3-cms-extension",
"keywords": [ "keywords": [
......
...@@ -9,7 +9,7 @@ $EM_CONF[$_EXTKEY] = [ ...@@ -9,7 +9,7 @@ $EM_CONF[$_EXTKEY] = [
'author_email' => 'dainis.abols@lu.lv', 'author_email' => 'dainis.abols@lu.lv',
'state' => 'stable', 'state' => 'stable',
'clearCacheOnLoad' => true, 'clearCacheOnLoad' => true,
'version' => '3.3.1', 'version' => '3.3.2',
'dependencies' => 'typo3,lu_api', 'dependencies' => 'typo3,lu_api',
'constraints' => [ 'constraints' => [
'depends' => [ 'depends' => [
......
...@@ -4,7 +4,7 @@ Extension to render list of contacts for University of Latvia ...@@ -4,7 +4,7 @@ Extension to render list of contacts for University of Latvia
## Version ## Version
3.3.1 3.3.2
## Dependencies ## 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