Skip to content
Snippets Groups Projects
ListInstanceController.php 3.32 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?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 List Instance Controller
    
    namespace Entity\controllers;
    
    use Entity\models\ListInstanceModel;
    
    use Slim\Http\Request;
    use Slim\Http\Response;
    
    use Respect\Validation\Validator;
    use Resource\controllers\ResController;
    use Entity\models\EntityModel;
    
    class ListInstanceController
    
        public function getById(Request $request, Response $response, array $aArgs)
    
            $listinstance = ListInstanceModel::getById(['id' => $aArgs['id']]);
    
    
            return $response->withJson($listinstance);
        }
    
    
        public function getListByResId(Request $request, Response $response, array $aArgs)
        {
            if (!Validator::intVal()->validate($aArgs['resId']) || !ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) {
                return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
            }
            $listinstances = ListInstanceModel::getListByResId(['select' => ['listinstance_id', 'sequence', 'CASE WHEN item_mode=\'cc\' THEN \'copy\' ELSE item_mode END', 'item_id', 'item_type', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment', 'signatory', 'requested_signature'], 'id' => $aArgs['resId']]);
            
            $roles = EntityModel::getRoles();
            
            foreach ($listinstances as $key2 => $listinstance) {
                foreach ($roles as $key => $role) {
                    if ($role['id'] == $listinstance['item_mode']) {
                        $listinstancesFormat[$role['label']][] = $listinstance;
                    }
                }
            }
            return $response->withJson($listinstancesFormat);
        }
    
        public function getVisaCircuitByResId(Request $request, Response $response, array $aArgs)
        {
            if (!Validator::intVal()->validate($aArgs['resId']) || !ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) {
                return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
            }
            $listinstances = ListInstanceModel::getVisaCircuitByResId(['select' => ['listinstance_id', 'sequence', 'item_id', 'item_type', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment', 'signatory', 'requested_signature'], 'id' => $aArgs['resId']]);
            
            return $response->withJson($listinstances);
        }
    
        public function getAvisCircuitByResId(Request $request, Response $response, array $aArgs)
        {
            if (!Validator::intVal()->validate($aArgs['resId']) || !ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) {
                return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
            }
            $listinstances = ListInstanceModel::getAvisCircuitByResId(['select' => ['listinstance_id', 'sequence', 'item_id', 'item_type', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment'], 'id' => $aArgs['resId']]);
            
            return $response->withJson($listinstances);
        }