Skip to content
Snippets Groups Projects
Verified Commit f4853f1f authored by Damien's avatar Damien
Browse files

FEAT After created an entity without parent, become part of this entity

parent 9faac54a
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,6 @@ use Basket\models\BasketModel;
use Entity\models\EntityModel;
use Entity\models\ListInstanceModel;
use Entity\models\ListTemplateModel;
use Entity\models\UserEntityModel;
use Group\models\ServiceModel;
use History\controllers\HistoryController;
use Resource\models\ResModel;
......@@ -26,6 +25,7 @@ use Respect\Validation\Validator;
use Slim\Http\Request;
use Slim\Http\Response;
use Template\models\TemplateModel;
use User\models\UserEntityModel;
use User\models\UserModel;
class EntityController
......@@ -161,7 +161,6 @@ class EntityController
$check = $check && Validator::stringType()->notEmpty()->validate($data['entity_label']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['short_label']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['entity_type']);
if (!empty($data['email'])) {
$check = $check && preg_match("/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/", $data['email']);
}
......@@ -184,6 +183,25 @@ class EntityController
'eventId' => 'entityCreation',
]);
if (empty($data['parent_entity_id']) && $GLOBALS['userId'] != 'superadmin') {
$user = UserModel::getByUserId(['userId' => $GLOBALS['userId'], 'select' => ['id']]);
$primaryEntity = UserModel::getPrimaryEntityByUserId(['userId' => $GLOBALS['userId']]);
$pEntity = 'N';
if (empty($primaryEntity)) {
$pEntity = 'Y';
}
UserEntityModel::addUserEntity(['id' => $user['id'], 'entityId' => $data['entity_id'], 'role' => '', 'primaryEntity' => $pEntity]);
HistoryController::add([
'tableName' => 'users',
'recordId' => $GLOBALS['userId'],
'eventType' => 'UP',
'info' => _USER_ENTITY_CREATION . " : {$GLOBALS['userId']} {$data['entity_id']}",
'moduleId' => 'user',
'eventId' => 'userModification',
]);
}
return $response->withJson(['entities' => EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']])]);
}
......
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief User Entity Model
* @author dev@maarch.org
*/
namespace Entity\models;
class UserEntityModel extends UserEntityModelAbstract
{
}
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief User Entity Model Abstract
* @author dev@maarch.org
*/
namespace Entity\models;
use SrcCore\models\ValidatorModel;
use SrcCore\models\DatabaseModel;
class UserEntityModelAbstract
{
public static function get(array $aArgs = [])
{
ValidatorModel::notEmpty($aArgs, ['select', 'where', 'data']);
ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']);
$users = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['users_entities'],
'where' => $aArgs['where'],
'data' => $aArgs['data']
]);
return $users;
}
public static function update(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']);
ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']);
DatabaseModel::update([
'table' => 'users_entities',
'set' => $aArgs['set'],
'where' => $aArgs['where'],
'data' => $aArgs['data']
]);
return true;
}
public static function delete(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['where', 'data']);
ValidatorModel::arrayType($aArgs, ['where', 'data']);
DatabaseModel::delete([
'table' => 'users_entities',
'where' => $aArgs['where'],
'data' => $aArgs['data']
]);
return true;
}
}
......@@ -160,19 +160,18 @@ class ResController
return $response->withJson(['success' => 'success']);
}
//EXTERNAL INFOS
public function updateExternalInfos(Request $request, Response $response){
public function updateExternalInfos(Request $request, Response $response)
{
$data = $request->getParams();
if(empty($data['externalInfos'])){
if (empty($data['externalInfos'])) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
}
if(empty($data['status'])){
if (empty($data['status'])) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
}
$externalInfos = $data['externalInfos'];
foreach($externalInfos as $mail){
foreach ($data['externalInfos'] as $mail) {
if(!Validator::intType()->validate($mail['res_id'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: invalid res_id']);
}
......@@ -184,7 +183,7 @@ class ResController
}
}
foreach($externalInfos as $mail){
foreach ($data['externalInfos'] as $mail) {
$document = ResModel::getById(['resId' => $mail['res_id'], 'select' => ['res_id']]);
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => _DOCUMENT_NOT_FOUND]);
......@@ -261,26 +260,27 @@ class ResController
public function getList(Request $request, Response $response)
{
$data = $request->getParams();
if(!Validator::stringType()->notEmpty()->validate($data['select'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: select parameter not valid']);
if (!Validator::stringType()->notEmpty()->validate($data['select'])) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: select is not valid']);
}
if(!Validator::stringType()->notEmpty()->validate($data['clause'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: clause parameter not valid']);
if (!Validator::stringType()->notEmpty()->validate($data['clause'])) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: clause is not valid']);
}
if(!empty($data['withFile'])){
if (!empty($data['withFile'])) {
if(!Validator::boolType()->validate($data['withFile'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: withFile parameter is not a boolean']);
}
}
if(!empty($data['orderBy'])){
if(!Validator::arrayType()->notEmpty()->validate($data['orderBy'])){
if (!empty($data['orderBy'])) {
if (!Validator::arrayType()->notEmpty()->validate($data['orderBy'])) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: orderBy parameter not valid']);
}
}
if(!empty($data['limit'])){
if(!Validator::intType()->validate($data['limit'])){
if (!empty($data['limit'])) {
if (!Validator::intType()->validate($data['limit'])) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: limit parameter not valid']);
}
}
......@@ -306,15 +306,14 @@ class ResController
}
$resources = ResModel::getOnView(['select' => $select, 'where' => $where, 'orderBy' => $orderBy, 'limit' => $limit]);
if($data['withFile'] === true){
foreach($resources as &$res){
if ($data['withFile'] === true) {
foreach ($resources as $key => $res) {
$path = ResDocserverModel::getSourceResourcePath(['resId' => $res['res_id'], 'resTable' => 'res_letterbox', 'adrTable' => 'null']);
$file = file_get_contents($path);
$base64Content = base64_encode($file);
$res['fileBase64Content'] = $base64Content;
};
$resources[$key]['fileBase64Content'] = $base64Content;
}
}
unset($res);
return $response->withJson(['resources' => $resources, 'count' => count($resources)]);
}
......
......@@ -20,6 +20,50 @@ use SrcCore\models\ValidatorModel;
class UserEntityModelAbstract
{
public static function get(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['select', 'where', 'data']);
ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']);
$users = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['users_entities'],
'where' => $aArgs['where'],
'data' => $aArgs['data']
]);
return $users;
}
public static function update(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']);
ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']);
DatabaseModel::update([
'table' => 'users_entities',
'set' => $aArgs['set'],
'where' => $aArgs['where'],
'data' => $aArgs['data']
]);
return true;
}
public static function delete(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['where', 'data']);
ValidatorModel::arrayType($aArgs, ['where', 'data']);
DatabaseModel::delete([
'table' => 'users_entities',
'where' => $aArgs['where'],
'data' => $aArgs['data']
]);
return true;
}
public static function getUsersWithoutEntities(array $aArgs)
{
ValidatorModel::arrayType($aArgs, ['select']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment