diff --git a/composer.json b/composer.json index 875bbbd7f88d064f4072b2412924e0474a4bb6fb..3ef1b0d6cdaba255e635ef18cd84f4a5240df09c 100755 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "Basket\\" : "src/app/basket/", "Contact\\" : "src/app/contact/", "Docserver\\" : "src/app/docserver/", + "Doctype\\" : "src/app/doctype/", "Entity\\" : "src/app/entity/", "History\\" : "src/app/history/", "Link\\" : "src/app/link/", diff --git a/core/Test/DoctypeControllerTest.php b/core/Test/DoctypeControllerTest.php new file mode 100755 index 0000000000000000000000000000000000000000..f9fe6629468903d388ef170da66ea1be0c4f8f3f --- /dev/null +++ b/core/Test/DoctypeControllerTest.php @@ -0,0 +1,268 @@ +<?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 DoctypeControllerTest +* @author dev <dev@maarch.org> +* @ingroup core +*/ + +use PHPUnit\Framework\TestCase; + +class DoctypesControllerTest extends TestCase +{ + private static $firstLevelId = null; + private static $secondLevelId = null; + private static $doctypeId = null; + + public function testReadList(){ + // READ LIST + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $doctypeController = new \Doctype\controllers\DoctypeController(); + $response = $doctypeController->get($request, new \Slim\Http\Response()); + $responseBody = json_decode((string)$response->getBody()); + + self::$firstLevelId = $responseBody->structure[0]->doctypes_first_level_id; + self::$secondLevelId = $responseBody->structure[0]->secondeLevels[0]->doctypes_second_level_id; + self::$doctypeId = $responseBody->structure[0]->secondeLevels[0]->doctypes[0]->type_id; + + $this->assertNotNull($responseBody->structure); + $this->assertNotNull($responseBody->structure[0]->doctypes_first_level_id); + $this->assertInternalType('int', $responseBody->structure[0]->doctypes_first_level_id); + $this->assertNotNull($responseBody->structure[0]->doctypes_first_level_label); + $this->assertNotNull($responseBody->structure[0]->enabled); + } + + public function testRead(){ + // READ FIRST LEVEL + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $doctypeController = new \Doctype\controllers\DoctypeController(); + $response = $doctypeController->getFirstLevelById($request, new \Slim\Http\Response(), ["id" => self::$firstLevelId]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(self::$firstLevelId, $responseBody->doctypes_first_level_id); + $this->assertNotNull($responseBody->doctypes_first_level_label); + $this->assertNotNull($responseBody->enabled); + + // READ SECOND LEVEL + $response = $doctypeController->getSecondLevelById($request, new \Slim\Http\Response(), ["id" => self::$secondLevelId]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(self::$secondLevelId, $responseBody->doctypes_second_level_id); + $this->assertNotNull($responseBody->doctypes_second_level_label); + $this->assertNotNull($responseBody->doctypes_first_level_id); + $this->assertNotNull($responseBody->enabled); + + // READ DOCTYPE + $response = $doctypeController->getDoctypeById($request, new \Slim\Http\Response(), ["id" => self::$doctypeId]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(self::$doctypeId, $responseBody->type_id); + $this->assertNotNull($responseBody->coll_id); + $this->assertInternalType('int', $responseBody->type_id); + $this->assertNotNull($responseBody->type_id); + $this->assertNotNull($responseBody->description); + $this->assertNotNull($responseBody->enabled); + $this->assertInternalType('int', $responseBody->doctypes_first_level_id); + $this->assertNotNull($responseBody->doctypes_first_level_id); + $this->assertInternalType('int', $responseBody->doctypes_second_level_id); + $this->assertNotNull($responseBody->doctypes_second_level_id); + $this->assertInternalType('int', $responseBody->duration_current_use); + } + + + // public function testCreate() + // { + // $actionController = new \Action\controllers\ActionController(); + + // // CREATE + // $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); + // $request = \Slim\Http\Request::createFromEnvironment($environment); + + // $aArgs = [ + // 'keyword' => 'indexing', + // 'label_action' => 'TEST-LABEL', + // 'id_status' => '_NOSTATUS_', + // 'is_folder_action' => false, + // 'action_page' => 'index_mlb', + // 'history' => true, + // 'origin' => 'apps', + // ]; + // $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + + // $response = $actionController->create($fullRequest, new \Slim\Http\Response()); + // $responseBody = json_decode((string)$response->getBody()); + + // self::$id = $responseBody->action->id; + + // $this->assertInternalType('int', self::$id); + // $this->assertSame('indexing', $responseBody->action->keyword); + // $this->assertSame('TEST-LABEL', $responseBody->action->label_action); + // $this->assertSame('_NOSTATUS_', $responseBody->action->id_status); + // $this->assertSame('N', $responseBody->action->is_system); + // $this->assertSame('N', $responseBody->action->is_folder_action); + // $this->assertSame('Y', $responseBody->action->enabled); + // $this->assertSame('index_mlb', $responseBody->action->action_page); + // $this->assertSame('Y', $responseBody->action->history); + // $this->assertSame('apps', $responseBody->action->origin); + // $this->assertSame('N', $responseBody->action->create_id); + + + // // FAIL CREATE + // $aArgs = [ + // 'keyword' => 'indexing', + // 'label_action' => '', + // 'id_status' => '', + // 'is_folder_action' => false, + // 'action_page' => 'index_mlb', + // 'history' => true, + // 'origin' => 'apps', + // ]; + // $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + + // $response = $actionController->create($fullRequest, new \Slim\Http\Response()); + // $responseBody = json_decode((string)$response->getBody()); + + // $this->assertSame('Invalid Status', $responseBody->errors[0]); + // $this->assertSame('Invalid label action', $responseBody->errors[1]); + // $this->assertSame('id_status is empty', $responseBody->errors[2]); + + // } + + // public function testRead(){ + // // READ + // $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + // $request = \Slim\Http\Request::createFromEnvironment($environment); + + // $actionController = new \Action\controllers\ActionController(); + // $response = $actionController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); + // $responseBody = json_decode((string)$response->getBody()); + + // $this->assertInternalType('int', self::$id); + // $this->assertSame(self::$id, $responseBody->action->id); + // $this->assertSame('indexing', $responseBody->action->keyword); + // $this->assertSame('TEST-LABEL', $responseBody->action->label_action); + // $this->assertSame('_NOSTATUS_', $responseBody->action->id_status); + // $this->assertSame(false, $responseBody->action->is_system); + // $this->assertSame(false, $responseBody->action->is_folder_action); + // $this->assertSame('Y', $responseBody->action->enabled); + // $this->assertSame('index_mlb', $responseBody->action->action_page); + // $this->assertSame(true, $responseBody->action->history); + // $this->assertSame('apps', $responseBody->action->origin); + // $this->assertSame(false, $responseBody->action->create_id); + + // // FAIL READ + // $actionController = new \Action\controllers\ActionController(); + // $response = $actionController->getById($request, new \Slim\Http\Response(), ['id' => 'gaz']); + // $responseBody = json_decode((string)$response->getBody()); + // $this->assertSame('Id is not a numeric', $responseBody->errors); + + // } + + + + // public function testUpdate() + // { + // // UPDATE + // $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); + // $request = \Slim\Http\Request::createFromEnvironment($environment); + // $aArgs = [ + // 'keyword' => '', + // 'label_action' => 'TEST-LABEL_UPDATED', + // 'id_status' => 'COU', + // 'is_folder_action' => true, + // 'action_page' => 'process', + // 'history' => false, + // 'origin' => 'apps', + // ]; + // $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + + // $actionController = new \Action\controllers\ActionController(); + // $response = $actionController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); + // $responseBody = json_decode((string)$response->getBody()); + + // $this->assertSame(self::$id, $responseBody->action->id); + // $this->assertSame('', $responseBody->action->keyword); + // $this->assertSame('TEST-LABEL_UPDATED', $responseBody->action->label_action); + // $this->assertSame('COU', $responseBody->action->id_status); + // $this->assertSame('N', $responseBody->action->is_system); + // $this->assertSame('Y', $responseBody->action->is_folder_action); + // $this->assertSame('Y', $responseBody->action->enabled); + // $this->assertSame('process', $responseBody->action->action_page); + // $this->assertSame('N', $responseBody->action->history); + // $this->assertSame('apps', $responseBody->action->origin); + // $this->assertSame('N', $responseBody->action->create_id); + + // // UPDATE FAIL + // $aArgs = [ + // 'keyword' => '', + // 'label_action' => 'TEST-LABEL_UPDATED', + // 'id_status' => 'COU', + // 'is_folder_action' => true, + // 'action_page' => 'process', + // 'history' => false, + // 'origin' => 'apps', + // ]; + // $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + + // $actionController = new \Action\controllers\ActionController(); + // $response = $actionController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'gaz']); + // $responseBody = json_decode((string)$response->getBody()); + // $this->assertSame('Id is not a numeric', $responseBody->errors[0]); + + // } + + // public function testDelete() + // { + // // DELETE + // $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); + // $request = \Slim\Http\Request::createFromEnvironment($environment); + + // $actionController = new \Action\controllers\ActionController(); + // $response = $actionController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); + // $responseBody = json_decode((string)$response->getBody()); + + // $this->assertNotNull($responseBody->action); + + // $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + // $request = \Slim\Http\Request::createFromEnvironment($environment); + // $actionController = new \Action\controllers\ActionController(); + // $response = $actionController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); + // $responseBody = json_decode((string)$response->getBody()); + + // $this->assertNull($responseBody->action[0]); + + // // FAIL DELETE + // $actionController = new \Action\controllers\ActionController(); + // $response = $actionController->delete($request, new \Slim\Http\Response(), ['id' => 'gaz']); + // $responseBody = json_decode((string)$response->getBody()); + + // $this->assertSame('Id is not a numeric', $responseBody->errors); + + // } + + // public function testGetInitAction() + // { + // // InitAction + // $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + // $request = \Slim\Http\Request::createFromEnvironment($environment); + + // $actionController = new \Action\controllers\ActionController(); + // $response = $actionController->initAction($request, new \Slim\Http\Response()); + // $responseBody = json_decode((string)$response->getBody()); + + // $this->assertNotNull($responseBody->action); + // $this->assertNotNull($responseBody->categoriesList); + // $this->assertNotNull($responseBody->statuses); + // $this->assertNotNull($responseBody->action_pagesList); + // $this->assertNotNull($responseBody->keywordsList); + + // } + +} diff --git a/src/app/doctype/controllers/DoctypeController.php b/src/app/doctype/controllers/DoctypeController.php new file mode 100644 index 0000000000000000000000000000000000000000..9e2f03cb59cffac94b533bbf4583d14e00b7bf83 --- /dev/null +++ b/src/app/doctype/controllers/DoctypeController.php @@ -0,0 +1,306 @@ +<?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 DoctypeController +* @author dev <dev@maarch.org> +* @ingroup core +*/ + +namespace Doctype\controllers; + +use History\controllers\HistoryController; +use Respect\Validation\Validator; +use SrcCore\models\CoreConfigModel; +use Doctype\models\FirstLevelModel; +use Doctype\models\SecondLevelModel; +use Doctype\models\DoctypeModel; +use Core\Models\ServiceModel; +use Slim\Http\Request; +use Slim\Http\Response; + +class DoctypeController +{ + public function get(Request $request, Response $response) + { + + $firstLevels = FirstLevelModel::get(); + $secondLevels = SecondLevelModel::get(); + $docTypes = DoctypeModel::get(); + + $structure = []; + foreach($firstLevels as $firstLevelValue){ + foreach ($secondLevels as $secondLevelValue) { + if($firstLevelValue['doctypes_first_level_id'] == $secondLevelValue['doctypes_first_level_id']){ + foreach ($docTypes as $doctypeValue) { + if($secondLevelValue['doctypes_second_level_id'] == $doctypeValue['doctypes_second_level_id']){ + $secondLevelValue['doctypes'][] = $doctypeValue; + } + } + $firstLevelValue['secondeLevels'][] = $secondLevelValue; + } + } + array_push($structure, $firstLevelValue); + } + + return $response->withJson([ + 'structure' => $structure, + ]); + } + + public function getFirstLevelById(Request $request, Response $response, $aArgs) + { + + if (!Validator::intVal()->validate($aArgs['id']) || !Validator::notEmpty()->validate($aArgs['id'])) { + return $response + ->withStatus(500) + ->withJson(['errors' => 'wrong format for id'.$aArgs['id']]); + } + + $obj = FirstLevelModel::getById(['id' => $aArgs['id']]); + + if(!empty($obj)){ + if ($obj['enabled'] == 'Y') { + $obj['enabled'] = true; + } else { + $obj['enabled'] = false; + } + } + + return $response->withJson($obj); + } + + public function getSecondLevelById(Request $request, Response $response, $aArgs) + { + + if (!Validator::intVal()->validate($aArgs['id']) || !Validator::notEmpty()->validate($aArgs['id'])) { + return $response + ->withStatus(500) + ->withJson(['errors' => 'wrong format for id']); + } + + $obj = SecondLevelModel::getById(['id' => $aArgs['id']]); + + if(!empty($obj)){ + if ($obj['enabled'] == 'Y') { + $obj['enabled'] = true; + } else { + $obj['enabled'] = false; + } + } + + return $response->withJson($obj); + } + + public function getDoctypeById(Request $request, Response $response, $aArgs) + { + + if (!Validator::intVal()->validate($aArgs['id']) || !Validator::notEmpty()->validate($aArgs['id'])) { + return $response + ->withStatus(500) + ->withJson(['errors' => 'wrong format for id']); + } + + $obj = DoctypeModel::getById(['id' => $aArgs['id']]); + + if(!empty($obj)){ + if ($obj['enabled'] == 'Y') { + $obj['enabled'] = true; + } else { + $obj['enabled'] = false; + } + } + + return $response->withJson($obj); + } + + + + + + + public function create(Request $request, Response $response) + { + if (!ServiceModel::hasService(['id' => 'admin_actions', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { + return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); + } + + $data = $request->getParams(); + $data = $this->manageValue($data); + + $errors = $this->control($data, 'create'); + if (!empty($errors)) { + return $response->withStatus(500)->withJson(['errors' => $errors]); + } + + ActionModel::create($data); + + $obj = max(ActionModel::get()); + + HistoryController::add([ + 'tableName' => 'actions', + 'recordId' => $obj['id'], + 'eventType' => 'ADD', + 'eventId' => 'actionadd', + 'info' => _ACTION_ADDED . ' : ' . $obj['label_action'] + ]); + + return $response->withJson( + [ + 'action' => $obj + ] + ); + } + + public function update(Request $request, Response $response, $aArgs) + { + if (!ServiceModel::hasService(['id' => 'admin_actions', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { + return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); + } + + $obj = $request->getParams(); + $obj['id'] = $aArgs['id']; + + $obj = $this->manageValue($obj); + $errors = $this->control($obj, 'update'); + + if (!empty($errors)) { + return $response + ->withStatus(500) + ->withJson(['errors' => $errors]); + } + + $return = ActionModel::update($obj); + + if ($return) { + $id = $aArgs['id']; + $obj = ActionModel::getById(['id' => $id]); + } else { + return $response + ->withStatus(500) + ->withJson(['errors' => 'Problem during action update']); + } + + HistoryController::add([ + 'tableName' => 'actions', + 'recordId' => $obj['id'], + 'eventType' => 'UP', + 'eventId' => 'actionup', + 'info' => _ACTION_UPDATED. ' : ' . $obj['label_action'] + ]); + + return $response->withJson( + [ + 'action' => $obj + ] + ); + } + + public function delete(Request $request, Response $response, $aArgs) + { + if (!ServiceModel::hasService(['id' => 'admin_actions', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { + return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); + } + + if (!Validator::intVal()->validate($aArgs['id'])) { + return $response + ->withStatus(500) + ->withJson(['errors' => 'Id is not a numeric']); + } + + $action = ActionModel::getById(['id' => $aArgs['id']]); // TODO select label_action + ActionModel::delete(['id' => $aArgs['id']]); + + HistoryController::add([ + 'tableName' => 'actions', + 'recordId' => $aArgs['id'], + 'eventType' => 'DEL', + 'eventId' => 'actiondel', + 'info' => _ACTION_DELETED. ' : ' . $action['label_action'] + ]); + + return $response->withJson(['action' => ActionModel::get()]); + } + + protected function control($aArgs, $mode) + { + $errors = []; + + $objs = StatusModel::get(); + + foreach ($objs as $obj) { + $status[] = $obj['id']; + } + array_unshift($status, '_NOSTATUS_'); + + if (!(in_array($aArgs['id_status'], $status))) { + $errors[]= 'Invalid Status'; + } + + if ($mode == 'update') { + if (!Validator::intVal()->validate($aArgs['id'])) { + $errors[] = 'Id is not a numeric'; + } else { + $obj = ActionModel::getById(['id' => $aArgs['id']]); + } + + if (empty($obj)) { + $errors[] = 'Id ' .$aArgs['id']. ' does not exists'; + } + } + + if (!Validator::notEmpty()->validate($aArgs['label_action']) || + !Validator::length(1, 255)->validate($aArgs['label_action'])) { + $errors[] = 'Invalid label action'; + } + + if (!Validator::notEmpty()->validate($aArgs['id_status'])) { + $errors[] = 'id_status is empty'; + } + + if (!Validator::notEmpty()->validate($aArgs['history']) || ($aArgs['history'] != 'Y' && $aArgs['history'] != 'N')) { + $errors[]= 'Invalid history value'; + } + + return $errors; + } + + public function initAction(Request $request, Response $response) + { + //default data + $obj['action']['history'] = true; + $obj['action']['keyword'] = ''; + $obj['action']['is_folder_action'] = false; + $obj['action']['action_page'] = ''; + $obj['action']['id_status'] = '_NOSTATUS_'; + $obj['categoriesList'] = CoreConfigModel::getLettersBoxCategories(); + + foreach ($obj['categoriesList'] as $key => $value) { + $obj['categoriesList'][$key]['selected'] = true; + } + + $obj['statuses'] = StatusModel::get(); + array_unshift($obj['statuses'], ['id'=>'_NOSTATUS_','label_status'=> _UNCHANGED]); + $obj['action_pagesList'] = ActionModel::getAction_pages(); + array_unshift($obj['action_pagesList']['actionsPageList'], ['id'=>'','label'=> _NO_PAGE, 'name'=>'', 'origin'=>'']); + $obj['keywordsList'] = ActionModel::getKeywords(); + + return $response->withJson($obj); + } + + protected function manageValue($request) + { + foreach ($request as $key => $value) { + if (in_array($key, ['is_folder_action', 'history'])) { + if (empty($value)) { + $request[$key] = 'N'; + } else { + $request[$key] = 'Y'; + } + } + } + return $request; + } +} diff --git a/src/app/doctype/models/DoctypeModel.php b/src/app/doctype/models/DoctypeModel.php new file mode 100644 index 0000000000000000000000000000000000000000..ad571181a133c515b0a65c5c474cc99fb66c9bf9 --- /dev/null +++ b/src/app/doctype/models/DoctypeModel.php @@ -0,0 +1,21 @@ +<?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 Doctype Model +* @author dev@maarch.org +* @ingroup core +*/ + +namespace Doctype\models; + +class DoctypeModel extends DoctypeModelAbstract +{ + // Do your stuff in this class +} diff --git a/src/app/doctype/models/DoctypeModelAbstract.php b/src/app/doctype/models/DoctypeModelAbstract.php new file mode 100644 index 0000000000000000000000000000000000000000..b8d4f941cce8f35fff75611965d38be73994aaa1 --- /dev/null +++ b/src/app/doctype/models/DoctypeModelAbstract.php @@ -0,0 +1,247 @@ +<?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 DoctypeModelAbstract +* @author dev <dev@maarch.org> +* @ingroup core +*/ + +namespace Doctype\models; + +use Core\Models\ValidatorModel; +use SrcCore\models\CoreConfigModel; +use SrcCore\models\DatabaseModel; + +class DoctypeModelAbstract +{ + public static function get(array $aArgs = []) + { + ValidatorModel::arrayType($aArgs, ['select']); + + $firstLevel = DatabaseModel::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['doctypes'], + 'order_by' => ['description asc'] + ]); + + return $firstLevel; + } + + public static function getById(array $aArgs = []) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + $aReturn = DatabaseModel::select( + [ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['doctypes'], + 'where' => ['type_id = ?'], + 'data' => [$aArgs['id']] + ] + ); + + if (empty($aReturn[0])) { + return []; + } + + $aReturn = $aReturn[0]; + + return $aReturn; + } + + public static function create(array $aArgs) + { + $actioncategories = $aArgs['actionCategories']; + unset($aArgs['actionCategories']); + DatabaseModel::insert([ + 'table' => 'actions', + 'columnsValues' => $aArgs + ]); + + $tab['action_id'] = max(ActionModel::get())['id']; + + for ($i=0;$i<count($actioncategories);$i++) { + $tab['category_id'] = $actioncategories[$i]; + DatabaseModel::insert( + [ + 'table' => 'actions_categories', + 'columnsValues' => $tab + ] + ); + } + + return true; + } + + public static function update(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + DatabaseModel::update([ + 'table' => 'actions', + 'set' => [ + 'keyword' => $aArgs['keyword'], + 'label_action' => $aArgs['label_action'], + 'id_status' => $aArgs['id_status'], + 'action_page' => $aArgs['action_page'], + 'history' => $aArgs['history'], + 'is_folder_action' => $aArgs['is_folder_action'] + ], + 'where' => ['id = ?'], + 'data' => [$aArgs['id']] + ]); + + DatabaseModel::delete([ + 'table' => 'actions_categories', + 'where' => ['action_id = ?'], + 'data' => [$aArgs['id']] + ]); + + $tab['action_id'] = $aArgs['id']; + + for ($i=0; $i < count($aArgs['actionCategories']); $i++) { + $tab['category_id'] = $aArgs['actionCategories'][$i]; + DatabaseModel::insert([ + 'table' => 'actions_categories', + 'columnsValues' => $tab + ]); + } + + return true; + } + + public static function delete(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + DatabaseModel::delete([ + 'table' => 'actions', + 'where' => ['id = ?'], + 'data' => [$aArgs['id']] + ]); + DatabaseModel::delete([ + 'table' => 'actions_categories', + 'where' => ['action_id = ?'], + 'data' => [$aArgs['id']] + ]); + DatabaseModel::delete([ + 'table' => 'actions_groupbaskets', + 'where' => ['id_action = ?'], + 'data' => [$aArgs['id']] + ]); + + return true; + } + + public static function getAction_pages() + { + $customId = CoreConfigModel::getCustomId(); + + if (file_exists('custom/' .$customId. '/core/xml/actions_pages.xml')) { + $path = 'custom/' .$customId. '/core/xml/actions_pages.xml'; + } else { + $path = 'core/xml/actions_pages.xml'; + } + + $tabActions_pages = []; + $tabActions_pages['modules'][] = 'Apps'; + + $xmlfile = simplexml_load_file($path); + + if (count($xmlfile) > 0) { + foreach ($xmlfile->ACTIONPAGE as $actionPage) { + if (!defined((string) $actionPage->LABEL)) { + $label = $actionPage->LABEL; + } else { + $label = constant((string) $actionPage->LABEL); + } + if (!empty((string) $actionPage->MODULE)) { + $origin = (string) $actionPage->MODULE; + } else { + $origin = 'apps'; + } + if (!empty((string) $actionPage->DESC)) { + $desc = constant((string) $actionPage->DESC); + } else { + $desc = 'no description'; + } + $tabActions_pages['actionsPageList'][] = array( + 'id' => (string) $actionPage->ID, + 'label' => $label, + 'name' => (string) $actionPage->NAME, + 'desc' => $desc, + 'origin' => ucfirst($origin), + ); + } + } + + array_multisort( + array_map( + function ($element) { + return $element['label']; + }, $tabActions_pages['actionsPageList'] + ), + SORT_ASC, $tabActions_pages['actionsPageList'] + ); + + $tabActions_pages['modules'] = array_unique($tabActions_pages['modules']); + sort($tabActions_pages['modules']); + return $tabActions_pages; + } + + public static function getKeywords() + { + $tabKeyword = []; + $tabKeyword[] = ['value' => '', label => _NO_KEYWORD]; + $tabKeyword[] = ['value' => 'redirect', label => _REDIRECT, desc => _KEYWORD_REDIRECT_DESC]; + //$tabKeyword[] = ['value' => 'to_validate', label => _TO_VALIDATE]; + $tabKeyword[] = ['value' => 'indexing', label => _INDEXING, desc => _KEYWORD_INDEXING_DESC]; + //$tabKeyword[] = ['value' => 'workflow', label => _WF]; + + return $tabKeyword; + } + + public static function getActionPageById(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + $action = DatabaseModel::select([ + 'select' => ['action_page'], + 'table' => ['actions'], + 'where' => ['id = ? AND enabled = ?'], + 'data' => [$aArgs['id'], 'Y'] + ]); + + if (empty($action[0])) { + return ''; + } + + return $action[0]['action_page']; + } + + public static function getDefaultActionByGroupBasketId(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['groupId', 'basketId']); + ValidatorModel::stringType($aArgs, ['groupId', 'basketId']); + + $action = DatabaseModel::select([ + 'select' => ['id_action'], + 'table' => ['actions_groupbaskets'], + 'where' => ['group_id = ?', 'basket_id = ?', 'default_action_list = ?'], + 'data' => [$aArgs['groupId'], $aArgs['basketId'], 'Y'] + ]); + + if (empty($action[0])) { + return ''; + } + + return $action[0]['id_action']; + } +} diff --git a/src/app/doctype/models/FirstLevelModel.php b/src/app/doctype/models/FirstLevelModel.php new file mode 100644 index 0000000000000000000000000000000000000000..5179adafcf3be4bfb1b9fa2fdbd9d259c5bede17 --- /dev/null +++ b/src/app/doctype/models/FirstLevelModel.php @@ -0,0 +1,21 @@ +<?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 FirstLevel Model +* @author dev@maarch.org +* @ingroup core +*/ + +namespace Doctype\models; + +class FirstLevelModel extends FirstLevelModelAbstract +{ + // Do your stuff in this class +} diff --git a/src/app/doctype/models/FirstLevelModelAbstract.php b/src/app/doctype/models/FirstLevelModelAbstract.php new file mode 100644 index 0000000000000000000000000000000000000000..a522e130b9df90670fa10a765975bf7e962b7eee --- /dev/null +++ b/src/app/doctype/models/FirstLevelModelAbstract.php @@ -0,0 +1,247 @@ +<?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 FirstLevelModelAbstract +* @author dev <dev@maarch.org> +* @ingroup core +*/ + +namespace Doctype\models; + +use Core\Models\ValidatorModel; +use SrcCore\models\CoreConfigModel; +use SrcCore\models\DatabaseModel; + +class FirstLevelModelAbstract +{ + public static function get(array $aArgs = []) + { + ValidatorModel::arrayType($aArgs, ['select']); + + $firstLevel = DatabaseModel::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['doctypes_first_level'], + 'order_by' => ['doctypes_first_level_id asc'] + ]); + + return $firstLevel; + } + + public static function getById(array $aArgs = []) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + $aReturn = DatabaseModel::select( + [ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['doctypes_first_level'], + 'where' => ['doctypes_first_level_id = ?'], + 'data' => [$aArgs['id']] + ] + ); + + if (empty($aReturn[0])) { + return []; + } + + $aReturn = $aReturn[0]; + + return $aReturn; + } + + public static function create(array $aArgs) + { + $actioncategories = $aArgs['actionCategories']; + unset($aArgs['actionCategories']); + DatabaseModel::insert([ + 'table' => 'actions', + 'columnsValues' => $aArgs + ]); + + $tab['action_id'] = max(ActionModel::get())['id']; + + for ($i=0;$i<count($actioncategories);$i++) { + $tab['category_id'] = $actioncategories[$i]; + DatabaseModel::insert( + [ + 'table' => 'actions_categories', + 'columnsValues' => $tab + ] + ); + } + + return true; + } + + public static function update(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + DatabaseModel::update([ + 'table' => 'actions', + 'set' => [ + 'keyword' => $aArgs['keyword'], + 'label_action' => $aArgs['label_action'], + 'id_status' => $aArgs['id_status'], + 'action_page' => $aArgs['action_page'], + 'history' => $aArgs['history'], + 'is_folder_action' => $aArgs['is_folder_action'] + ], + 'where' => ['id = ?'], + 'data' => [$aArgs['id']] + ]); + + DatabaseModel::delete([ + 'table' => 'actions_categories', + 'where' => ['action_id = ?'], + 'data' => [$aArgs['id']] + ]); + + $tab['action_id'] = $aArgs['id']; + + for ($i=0; $i < count($aArgs['actionCategories']); $i++) { + $tab['category_id'] = $aArgs['actionCategories'][$i]; + DatabaseModel::insert([ + 'table' => 'actions_categories', + 'columnsValues' => $tab + ]); + } + + return true; + } + + public static function delete(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + DatabaseModel::delete([ + 'table' => 'actions', + 'where' => ['id = ?'], + 'data' => [$aArgs['id']] + ]); + DatabaseModel::delete([ + 'table' => 'actions_categories', + 'where' => ['action_id = ?'], + 'data' => [$aArgs['id']] + ]); + DatabaseModel::delete([ + 'table' => 'actions_groupbaskets', + 'where' => ['id_action = ?'], + 'data' => [$aArgs['id']] + ]); + + return true; + } + + public static function getAction_pages() + { + $customId = CoreConfigModel::getCustomId(); + + if (file_exists('custom/' .$customId. '/core/xml/actions_pages.xml')) { + $path = 'custom/' .$customId. '/core/xml/actions_pages.xml'; + } else { + $path = 'core/xml/actions_pages.xml'; + } + + $tabActions_pages = []; + $tabActions_pages['modules'][] = 'Apps'; + + $xmlfile = simplexml_load_file($path); + + if (count($xmlfile) > 0) { + foreach ($xmlfile->ACTIONPAGE as $actionPage) { + if (!defined((string) $actionPage->LABEL)) { + $label = $actionPage->LABEL; + } else { + $label = constant((string) $actionPage->LABEL); + } + if (!empty((string) $actionPage->MODULE)) { + $origin = (string) $actionPage->MODULE; + } else { + $origin = 'apps'; + } + if (!empty((string) $actionPage->DESC)) { + $desc = constant((string) $actionPage->DESC); + } else { + $desc = 'no description'; + } + $tabActions_pages['actionsPageList'][] = array( + 'id' => (string) $actionPage->ID, + 'label' => $label, + 'name' => (string) $actionPage->NAME, + 'desc' => $desc, + 'origin' => ucfirst($origin), + ); + } + } + + array_multisort( + array_map( + function ($element) { + return $element['label']; + }, $tabActions_pages['actionsPageList'] + ), + SORT_ASC, $tabActions_pages['actionsPageList'] + ); + + $tabActions_pages['modules'] = array_unique($tabActions_pages['modules']); + sort($tabActions_pages['modules']); + return $tabActions_pages; + } + + public static function getKeywords() + { + $tabKeyword = []; + $tabKeyword[] = ['value' => '', label => _NO_KEYWORD]; + $tabKeyword[] = ['value' => 'redirect', label => _REDIRECT, desc => _KEYWORD_REDIRECT_DESC]; + //$tabKeyword[] = ['value' => 'to_validate', label => _TO_VALIDATE]; + $tabKeyword[] = ['value' => 'indexing', label => _INDEXING, desc => _KEYWORD_INDEXING_DESC]; + //$tabKeyword[] = ['value' => 'workflow', label => _WF]; + + return $tabKeyword; + } + + public static function getActionPageById(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + $action = DatabaseModel::select([ + 'select' => ['action_page'], + 'table' => ['actions'], + 'where' => ['id = ? AND enabled = ?'], + 'data' => [$aArgs['id'], 'Y'] + ]); + + if (empty($action[0])) { + return ''; + } + + return $action[0]['action_page']; + } + + public static function getDefaultActionByGroupBasketId(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['groupId', 'basketId']); + ValidatorModel::stringType($aArgs, ['groupId', 'basketId']); + + $action = DatabaseModel::select([ + 'select' => ['id_action'], + 'table' => ['actions_groupbaskets'], + 'where' => ['group_id = ?', 'basket_id = ?', 'default_action_list = ?'], + 'data' => [$aArgs['groupId'], $aArgs['basketId'], 'Y'] + ]); + + if (empty($action[0])) { + return ''; + } + + return $action[0]['id_action']; + } +} diff --git a/src/app/doctype/models/SecondLevelModel.php b/src/app/doctype/models/SecondLevelModel.php new file mode 100644 index 0000000000000000000000000000000000000000..e8430f6ebf2ba6b9a484f2c8d1b97bd0da243a06 --- /dev/null +++ b/src/app/doctype/models/SecondLevelModel.php @@ -0,0 +1,21 @@ +<?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 SecondLevel Model +* @author dev@maarch.org +* @ingroup core +*/ + +namespace Doctype\models; + +class SecondLevelModel extends SecondLevelModelAbstract +{ + // Do your stuff in this class +} diff --git a/src/app/doctype/models/SecondLevelModelAbstract.php b/src/app/doctype/models/SecondLevelModelAbstract.php new file mode 100644 index 0000000000000000000000000000000000000000..cc33545c58526172cbe351a7792f120bd8d365e2 --- /dev/null +++ b/src/app/doctype/models/SecondLevelModelAbstract.php @@ -0,0 +1,247 @@ +<?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 SecondLevelModelAbstract +* @author dev <dev@maarch.org> +* @ingroup core +*/ + +namespace Doctype\models; + +use Core\Models\ValidatorModel; +use SrcCore\models\CoreConfigModel; +use SrcCore\models\DatabaseModel; + +class SecondLevelModelAbstract +{ + public static function get(array $aArgs = []) + { + ValidatorModel::arrayType($aArgs, ['select']); + + $firstLevel = DatabaseModel::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['doctypes_second_level'], + 'order_by' => ['doctypes_second_level_label asc'] + ]); + + return $firstLevel; + } + + public static function getById(array $aArgs = []) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + $aReturn = DatabaseModel::select( + [ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['doctypes_second_level'], + 'where' => ['doctypes_second_level_id = ?'], + 'data' => [$aArgs['id']] + ] + ); + + if (empty($aReturn[0])) { + return []; + } + + $aReturn = $aReturn[0]; + + return $aReturn; + } + + public static function create(array $aArgs) + { + $actioncategories = $aArgs['actionCategories']; + unset($aArgs['actionCategories']); + DatabaseModel::insert([ + 'table' => 'actions', + 'columnsValues' => $aArgs + ]); + + $tab['action_id'] = max(ActionModel::get())['id']; + + for ($i=0;$i<count($actioncategories);$i++) { + $tab['category_id'] = $actioncategories[$i]; + DatabaseModel::insert( + [ + 'table' => 'actions_categories', + 'columnsValues' => $tab + ] + ); + } + + return true; + } + + public static function update(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + DatabaseModel::update([ + 'table' => 'actions', + 'set' => [ + 'keyword' => $aArgs['keyword'], + 'label_action' => $aArgs['label_action'], + 'id_status' => $aArgs['id_status'], + 'action_page' => $aArgs['action_page'], + 'history' => $aArgs['history'], + 'is_folder_action' => $aArgs['is_folder_action'] + ], + 'where' => ['id = ?'], + 'data' => [$aArgs['id']] + ]); + + DatabaseModel::delete([ + 'table' => 'actions_categories', + 'where' => ['action_id = ?'], + 'data' => [$aArgs['id']] + ]); + + $tab['action_id'] = $aArgs['id']; + + for ($i=0; $i < count($aArgs['actionCategories']); $i++) { + $tab['category_id'] = $aArgs['actionCategories'][$i]; + DatabaseModel::insert([ + 'table' => 'actions_categories', + 'columnsValues' => $tab + ]); + } + + return true; + } + + public static function delete(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + DatabaseModel::delete([ + 'table' => 'actions', + 'where' => ['id = ?'], + 'data' => [$aArgs['id']] + ]); + DatabaseModel::delete([ + 'table' => 'actions_categories', + 'where' => ['action_id = ?'], + 'data' => [$aArgs['id']] + ]); + DatabaseModel::delete([ + 'table' => 'actions_groupbaskets', + 'where' => ['id_action = ?'], + 'data' => [$aArgs['id']] + ]); + + return true; + } + + public static function getAction_pages() + { + $customId = CoreConfigModel::getCustomId(); + + if (file_exists('custom/' .$customId. '/core/xml/actions_pages.xml')) { + $path = 'custom/' .$customId. '/core/xml/actions_pages.xml'; + } else { + $path = 'core/xml/actions_pages.xml'; + } + + $tabActions_pages = []; + $tabActions_pages['modules'][] = 'Apps'; + + $xmlfile = simplexml_load_file($path); + + if (count($xmlfile) > 0) { + foreach ($xmlfile->ACTIONPAGE as $actionPage) { + if (!defined((string) $actionPage->LABEL)) { + $label = $actionPage->LABEL; + } else { + $label = constant((string) $actionPage->LABEL); + } + if (!empty((string) $actionPage->MODULE)) { + $origin = (string) $actionPage->MODULE; + } else { + $origin = 'apps'; + } + if (!empty((string) $actionPage->DESC)) { + $desc = constant((string) $actionPage->DESC); + } else { + $desc = 'no description'; + } + $tabActions_pages['actionsPageList'][] = array( + 'id' => (string) $actionPage->ID, + 'label' => $label, + 'name' => (string) $actionPage->NAME, + 'desc' => $desc, + 'origin' => ucfirst($origin), + ); + } + } + + array_multisort( + array_map( + function ($element) { + return $element['label']; + }, $tabActions_pages['actionsPageList'] + ), + SORT_ASC, $tabActions_pages['actionsPageList'] + ); + + $tabActions_pages['modules'] = array_unique($tabActions_pages['modules']); + sort($tabActions_pages['modules']); + return $tabActions_pages; + } + + public static function getKeywords() + { + $tabKeyword = []; + $tabKeyword[] = ['value' => '', label => _NO_KEYWORD]; + $tabKeyword[] = ['value' => 'redirect', label => _REDIRECT, desc => _KEYWORD_REDIRECT_DESC]; + //$tabKeyword[] = ['value' => 'to_validate', label => _TO_VALIDATE]; + $tabKeyword[] = ['value' => 'indexing', label => _INDEXING, desc => _KEYWORD_INDEXING_DESC]; + //$tabKeyword[] = ['value' => 'workflow', label => _WF]; + + return $tabKeyword; + } + + public static function getActionPageById(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + + $action = DatabaseModel::select([ + 'select' => ['action_page'], + 'table' => ['actions'], + 'where' => ['id = ? AND enabled = ?'], + 'data' => [$aArgs['id'], 'Y'] + ]); + + if (empty($action[0])) { + return ''; + } + + return $action[0]['action_page']; + } + + public static function getDefaultActionByGroupBasketId(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['groupId', 'basketId']); + ValidatorModel::stringType($aArgs, ['groupId', 'basketId']); + + $action = DatabaseModel::select([ + 'select' => ['id_action'], + 'table' => ['actions_groupbaskets'], + 'where' => ['group_id = ?', 'basket_id = ?', 'default_action_list = ?'], + 'data' => [$aArgs['groupId'], $aArgs['basketId'], 'Y'] + ]); + + if (empty($action[0])) { + return ''; + } + + return $action[0]['id_action']; + } +}