Verified Commit bb72bf05 authored by Alexandre Morin's avatar Alexandre Morin
Browse files

feat (11670) : add the dataTable on the organization list

parent 5ce1baaa
Pipeline #6090 failed with stages
......@@ -517,6 +517,13 @@ chainJournalByOrganization = false;
chainWithTimestamp = false;
[organization]
; Displaying the organization as a tree
; true = organization tree
; false = organization list
; WARNING : Above 40 services, we advise you not to activate this option.
isOrgTree = true;
; Roles of organization unit
; if 'transaction' parameter disable, uncomment the block 'orgUnitRoles' below
; if 'transaction' parameter enable, comment the block 'orgUnitRoles' below
......
......@@ -111,6 +111,108 @@ class organization
return $orgList;
}
public function search($term = null, $enabled = "all")
{
$authController = \laabs::newController("auth/userAccount");
$user = $authController->get(\laabs::getToken('AUTH')->accountId);
$currentOrg = \laabs::getToken("ORGANIZATION");
$owner = true;
if (isset($currentOrg)) {
if (!$currentOrg->orgRoleCodes) {
$owner = false;
} elseif (is_array($currentOrg->orgRoleCodes) && !in_array('owner', $currentOrg->orgRoleCodes)) {
$owner = false;
}
}
$queryParts = array();
$queryParams = array();
$securityLevel = $user->getSecurityLevel();
if ($securityLevel == $user::SECLEVEL_GENADMIN) {
$queryParams['isOrgUnit'] = 'false';
$queryParts['isOrgUnit'] = "isOrgUnit=:isOrgUnit";
}
if ($term) {
$queryParts['term'] = "(registrationNumber ='*".$term."*'
OR orgName = '*".$term."*'
OR displayName = '*".$term."*'
OR parentOrgId = '*".$term."*')";
}
if($enabled !== 'all') {
$queryParams['enabled'] = $enabled;
$queryParts['enabled'] = "enabled=:enabled";
}
$queryString = "";
if (count($queryParts)) {
$queryString = implode(' AND ', $queryParts );
}
$length = \laabs::configuration('presentation.maarchRM')['maxResults'];;
$organizationList = $this->sdoFactory->find("organization/organization", $queryString, $queryParams, null, 0, $length);
$organizationList = \laabs::castMessageCollection($organizationList, "organization/organizationList");
if ($term || $enabled !== 'all') {
$organizations = [];
foreach ($organizationList as $organization) {
if ($user->ownerOrgId && $organization->ownerOrgId != $user->ownerOrgId) {
if (empty($parentOrgId) && $organization->orgId != $user->ownerOrgId) {
continue;
}
}
if ($organization->parentOrgId) {
$organization->parentOrgName = $this->sdoFactory->index(
'organization/organization',
['displayName'],
"orgId='". $organization->parentOrgId . "'"
)[$organization->parentOrgId];
}
$organizations[] = $organization;
}
return $organizations;
}
$tree = array();
$organizationByParent = array();
foreach ($organizationList as $organization) {
$parentOrgId = (string)$organization->parentOrgId;
if ($user->ownerOrgId && $organization->ownerOrgId != $user->ownerOrgId) {
if (empty($parentOrgId) && $organization->orgId != $user->ownerOrgId) {
continue;
}
}
if (empty($parentOrgId) && $owner) {
$tree[] = $organization;
continue;
} elseif (!$owner && (string)$organization->orgId == (string)$currentOrg->ownerOrgId) {
$tree[] = $organization;
continue;
}
if (!isset($organizationByParent[$parentOrgId])) {
$organizationByParent[$parentOrgId] = array();
}
$organization->parentOrgName = $this->sdoFactory->index(
'organization/organization',
['displayName'],
"orgId='". $organization->parentOrgId . "'"
)[$organization->parentOrgId];
$organizationByParent[$parentOrgId][] = $organization;
}
return $this->buildTree($tree, $organizationByParent);
}
/**
* Get organizations tree
*
......@@ -202,59 +304,6 @@ class organization
return $roots;
}
/**
* Search organizations
* @param string $name
* @param string $businessType
* @param string $orgRoleCode
* @param string $orgTypeCode
* @param string $registrationNumber
* @param string $taxIdentifier
*
* @return organization/organization[] An array of organizations
*/
public function search($name = null, $businessType = null, $orgRoleCode = null, $orgTypeCode = null, $registrationNumber = null, $taxIdentifier = null)
{
$queryParts = array();
$variables = array();
$query = null;
if ($name) {
$variables['name'] = "*$name*";
$queryParts[] = "(orgName~:name OR otherOrgName~:name OR displayName~:name)";
}
if ($businessType) {
$variables['businessType'] = "*$businessType*";
$queryParts[] = "(businessType~:businessType)";
}
if ($orgRoleCode) {
$variables['orgRoleCodes'] = "*$orgRoleCode*";
$queryParts[] = "(orgRoleCodes~:orgRoleCodes)";
}
if ($orgTypeCode) {
$variables['orgTypeCode'] = "*$orgTypeCode*";
$queryParts[] = "(orgTypeCode='$orgTypeCode')";
}
if ($registrationNumber) {
$variables['registrationNumber'] = $registrationNumber;
$queryParts[] = "(registrationNumber='$registrationNumber')";
}
if ($taxIdentifier) {
$variables['taxIdentifier'] = $taxIdentifier;
$queryParts[] = "(taxIdentifier='$taxIdentifier')";
}
if (count($queryParts)) {
$query = implode(" AND ", $queryParts);
}
return $this->sdoFactory->find("organization/organization", $query, $variables);
}
/**
* Create an organization
* @param organization/organization $organization The organization object to create
......
<?php
/*
* Copyright (C) 2015 Maarch
*
* This file is part of bundle organization.
*
* Bundle organization is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Bundle organization is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bundle organization. If not, see <http://www.gnu.org/licenses/>.
*/
namespace bundle\organization\Message;
/**
* Organization list
*
* @package Organization
* @author Alexandre Morin <alexandre.morin@maarch.org>
*/
class organizationList
{
/**
* The organization's identifier
*
* @var id
*/
public $orgId;
/**
* The displayed name of the object
*
* @var string
* @notempty
*/
public $displayName;
/**
* The registration number
*
* @var string
* @notempty
*/
public $registrationNumber;
/**
* The organization's parent orgId
*
* @var string
*/
public $parentOrgId;
/**
* The organization's parent orgName
*
* @var string
*/
public $parentOrgName;
/**
* The organization owner orgId
*
* @var string
*/
public $ownerOrgId;
/**
* The organization is a service
*
* @var bool
*/
public $isOrgUnit;
/**
* The children organizations
*
* @var organization/organization[]
*/
public $organization;
/**
* Status of organization
*
* @var bool
*/
public $enabled = true;
}
\ No newline at end of file
......@@ -45,18 +45,14 @@ interface organizationInterface
/**
* Search organization
* @param string $name
* @param string $businessType
* @param string $orgRoleCode
* @param string $orgTypeCode
* @param string $registrationNumber
* @param string $taxIdentifier
* @param string $term
* @param string $enabled
*
* @return organization/organization[] An array of organizations
*
* @action organization/organization/search
*/
public function readSearch($name = null, $businessType = null, $orgRoleCode = null, $orgTypeCode = null, $registrationNumber = null, $taxIdentifier = null);
public function readSearch($term = null, $enabled = "all");
/**
* Create an organization
......
......@@ -65,6 +65,7 @@ class orgTree
public function index($organizations, $orgType)
{
$orgRole = \laabs::configuration('organization')['orgUnitRoles'];
$isOrgTree = \laabs::configuration('organization')['isOrgTree'];
$this->view->addContentFile("organization/organizationIndex.html");
$communicationMeans = \laabs::callService("contact/communicationMean/readIndex");
......@@ -108,6 +109,7 @@ class orgTree
$this->view->setSource("adminContact", $adminContact);
$this->view->setSource("orgType", $orgType);
$this->view->setSource("orgRole", $orgRole);
$this->view->setSource("isOrgTree", $isOrgTree);
$this->view->setSource("communicationMeans", $communicationMeans);
$this->view->setSource("countriesCodes", $countriesCodes);
$this->view->setSource("archivalProfile", $archivalProfile);
......@@ -125,15 +127,6 @@ class orgTree
$this->view->merge();
$this->view->translate();
/*if (sizeof($organizations) != 0) {
$tree = $this->contructTree($organizations);
if ($tree != null) {
$orgList = $this->view->getElementsByClass('dataTree')->item(0);
$orgList->appendChild($tree);
}
}*/
return $this->view->saveHtml();
}
......@@ -146,20 +139,8 @@ class orgTree
public function getTree($organizations)
{
$adminOrg = \laabs::callService('auth/userAccount/readHasprivilege', "adminFunc/adminOrganization");
/*
$html = '';
if (sizeof($organizations) > 0) {
$tree = $this->contructTree($organizations);
//$this->view->appendChild($tree);
foreach ($tree->childNodes as $branch) {
$html .= $this->view->saveHtml($branch);
}
}
return $html;
*/
$this->view->addContentFile("organization/orgTree.html");
$this->view->addContentFile("organization/orgTree/orgTree.html");
$this->view->setSource("adminOrg", $adminOrg);
$this->view->setSource("organizations", $organizations);
$this->view->merge();
......@@ -168,77 +149,6 @@ class orgTree
return $this->view->saveHtml();
}
/**
* contructTree
* @param array $organizations The tree representing the orgs
*
* @return view View with the tree
*/
protected function contructTree($organizations)
{
$orgTree = $this->view->createDocumentFragment();
// Organization fragment
$orgFragmentTemplate = $this->view->createDocumentFragment();
$orgFragmentTemplate->appendHtmlFile("organization/organizationItem.html");
$this->view->translate($orgFragmentTemplate);
// OrgUnit fragment
$orgUnitFragmentTemplate = $this->view->createDocumentFragment();
$orgUnitFragmentTemplate->appendHtmlFile("organization/orgUnitItem.html");
$this->view->translate($orgUnitFragmentTemplate);
// Person fragment
$personFragmentTemplate = $this->view->createDocumentFragment();
$personFragmentTemplate->appendHtmlFile("organization/personItem.html");
$this->view->translate($personFragmentTemplate);
// Service fragment
$serviceFragmentTemplate = $this->view->createDocumentFragment();
$serviceFragmentTemplate->appendHtmlFile("organization/serviceItem.html");
$this->view->translate($serviceFragmentTemplate);
// Contact fragment
$contactFragmentTemplate = $this->view->createDocumentFragment();
$contactFragmentTemplate->appendHtmlFile("organization/contactItem.html");
$this->view->translate($contactFragmentTemplate);
//Organization
foreach ($organizations as $organization) {
$treeNode = $this->view->createElement('ul');
$orgFragment = $orgFragmentTemplate->cloneNode(true);
$orgItem = $orgTree->appendChild($treeNode);
$treeNode->appendChild($orgFragment);
$this->view->merge($orgItem, $organization);
// Creation of the children container
if (!empty($organization->organization) || !empty($organization->userPosition) || !empty($organization->servicePosition) || !empty($organization->orgContact)) {
$orgElement = $orgItem->getElementsByTagName('li')->item(0);
$childrenContainer = $this->view->createElement('ul');
$orgElement->appendChild($childrenContainer);
if (!empty($organization->organization)) {
$this->mergeOrgUnits($organization, $childrenContainer, $orgFragmentTemplate, $orgUnitFragmentTemplate, $personFragmentTemplate, $serviceFragmentTemplate, $contactFragmentTemplate);
}
if (!empty($organization->userPosition)) {
$this->mergeUserPosition($organization, $childrenContainer, $personFragmentTemplate);
}
if (!empty($organization->servicePosition)) {
$this->mergeServicePosition($organization, $childrenContainer, $serviceFragmentTemplate);
}
if (!empty($organization->orgContact)) {
$this->mergeContactPosition($organization, $childrenContainer, $contactFragmentTemplate);
}
}
}
return $orgTree;
}
protected function mergeOrgUnits($parent, $container, $orgFragmentTemplate, $orgUnitFragmentTemplate, $personFragmentTemplate, $serviceFragmentTemplate, $contactFragmentTemplate)
{
$orgs = array();
......
......@@ -29,13 +29,16 @@ class organization
{
use \presentation\maarchRM\Presenter\exceptions\exceptionTrait;
protected $json;
public $view;
/**
* __construct
* @param \dependency\json\JsonObject $json
* @param \dependency\html\Document $view
*/
public function __construct(\dependency\json\JsonObject $json)
public function __construct(\dependency\json\JsonObject $json, \dependency\html\Document $view)
{
$this->view = $view;
$this->json = $json;
$this->json->status = true;
}
......@@ -52,4 +55,25 @@ class organization
}
return json_encode($res);
}
public function search($organizations) {
$adminOrg = \laabs::callService('auth/userAccount/readHasprivilege', "adminFunc/adminOrganization");
$this->view->addContentFile("organization/orgList/orgList.html");
$dataTable = $this->view->getElementsByClass("dataTable")->item(0)->plugin['dataTable'];
$dataTable->setPaginationType("full_numbers");
$dataTable->setUnsortableColumns(0);
$dataTable->setUnsearchableColumns(0);
$dataTable->setUnsortableColumns(3);
$dataTable->setUnsearchableColumns(3);
$dataTable->setUnsortableColumns(4);
$dataTable->setUnsearchableColumns(4);
$this->view->setSource("adminOrg", $adminOrg);
$this->view->setSource("organizations", $organizations);
$this->view->merge();
$this->view->translate();
return $this->view->saveHtml();
}
}
\ No newline at end of file
......@@ -159,6 +159,12 @@ msgstr "Déplacer vers :"
msgid "Select a new position for the organization"
msgstr "Sélectionnez une nouvelle position pour l'organisation"
msgid "New position"
msgstr "Nouvelle position"
msgid "Organization or activity"
msgstr "Organisation ou activité"
msgid "Move"
msgstr "Déplacer"
......@@ -171,6 +177,9 @@ msgstr "Gérer les contacts"
msgid "Owner Organization Id"
msgstr "Identifiant de l'organisation parente"
msgid "Parent name"
msgstr "Nom du parent"
msgid "Organization contacts"
msgstr "Contacts de l'organisation"
......@@ -372,3 +381,6 @@ msgstr "Selectionnez un profil"
msgid "Status changed"
msgstr "Statut de l'activité modifié"
msgid "Identifier or name"
msgstr "Identifiant ou nom de l'organisation"
<br>
<div class="col-md-12" data-translate-catalog="organization/messages">
<div class="panel panel-default">
<div class="panel-body" id="orgSearch">
<div class="form-group">
<label class="col-md-2 control-label">Search</label>
<div class="col-md-5">
<div class="form-group">
<input type="text" class="form-control input-sm" name="term" id="term" placeholder="Identifier or name"/>
</div>
</div>
<div class="col-md-5">
<label class="col-lg-4 control-label">Enabled</label>
<div class="btn-group" data-toggle="buttons" >
<label class="btn btn-info active enabled" title="All">
<input type="radio" id="all" name="enabled" value="all" checked>All
</label>
<label class="btn btn-default enabled" title="Yes">
<input type="radio" id="true" name="enabled" value="1">Yes
</label>
<label class="btn btn-default enabled" title="No">
<input type="radio" id="false" name="enabled" value="0">No
</label>
</div>
</div>
</div>
<hr/>
<div class="clearfix">
<div class="col-md-12">
<button type="button" class="btn btn-primary pull-right" id="search" title="Search"><i class="fa fa-search">&nbsp;</i> Search</button>
</div>
</div>
</div>
</div>
</div>
<script>
$("#orgSearch").on('click', '.enabled', function () {
$('#orgSearch').find('.enabled').removeClass('btn-info active').addClass('btn-default');
$(this).addClass('btn-info active').removeClass('btn-default');
});
$("#orgSearch").on('click', '#search', function () {
Forms.clear();
Filter.search();
});
$("#organization_org").on('click', '.addChildOrganization', function() {
var span = $(this).closest('span');
var orgId = span.attr("id");
var parentName = span.data('orgname');
Forms.clear();
Org.select(span);
OrganizationForm.newOrg(parentName, orgId);
});
$("#organization_org").on('click', '.addChildOrgUnit', function() {
var span = $(this).closest('span');
var orgId = span.attr("id");
var parentName = span.data('orgname');
var ownerOrgId = span.data('ownerorgid');
Forms.clear();
Org.select(span);
OrganizationForm.newOrg(parentName, orgId, ownerOrgId);
});
$("#organization_org").on('click', '.moveOrganization', function() {
var span = $(this).closest('span')
Forms.clear();
Org.select(span);
OrganizationShifting.show(span);
});
var Filter = {
search : function() {
const enabled = 'enabled=' + $("#orgSearch").find('[name="enabled"]:checked').val();
let term = '';
if ($("#term").val()) {
term = '&term=' + encodeURI($("#term").val());