コード例 #1
0
 public function getEvaluationModel($code)
 {
     if (empty($code)) {
         throw new \Exception('Unknown beneficiary\'s evaluation model with these given criteria');
     }
     $data = null;
     try {
         // -- Find data
         $request = $this->client->get('evaluations/model/' . $code);
         $response = $request->send()->json();
         // - Wrong result
         if (StatusConstants::OK != $response['status']) {
             throw new \Exception($response['message'], StatusConstants::toCode($response['status']));
         }
         if (!array_key_exists('data', $response) || empty($response['data']) || !is_array($response['data'])) {
             return null;
         }
         // - Good result
         $data = EvaluationModel::fromJson($response['data']);
     } catch (\Exception $e) {
         throw new \Exception('Erreur lors de la recherche du modèle d\'évaluation.', StatusConstants::toCode($e->getCode()), $e);
     }
     return $data;
 }
コード例 #2
0
 public static function fromJson($data)
 {
     $element = new EvaluationModel(@$data['code'], @$data['label'], @$data['description'], @$data['id']);
     $element->setFolderSectionId(@$data['folderSectionId']);
     $element->setBeneficiaryId(@$data['beneficiaryId']);
     $element->setEvaluatorId(@$data['evaluatorId']);
     $element->setAppId(@$data['appId']);
     $element->setState(@$data['state']);
     $element->setDate(@$data['date']);
     $element->setObject(@$data['object']);
     $element->setLastUpdate(@$data['lastUpdate']);
     if (array_key_exists('categories', $data) && is_array($data['categories']) && !empty($data['categories'])) {
         foreach ($data['categories'] as $cat) {
             $newCategory = new EvaluationModelCategory(@$cat['label'], @$cat['code'], @$cat['categoryId'], @$cat['id']);
             if (array_key_exists('items', $cat) && is_array($cat['items']) && !empty($cat['items'])) {
                 foreach ($cat['items'] as $item) {
                     $newItem = new EvaluationModelItem(@$item['label'], @$item['responseType'], @$item['itemId'], @$item['id']);
                     if (array_key_exists('responses', $item) && is_array($item['responses']) && !empty($item['responses'])) {
                         foreach ($item['responses'] as $response) {
                             $newResponse = new EvaluationModelItemResponse(@$response['value'], @$response['label'], @$response['type'], @$response['responseId'], @$response['id'], @$response['selected']);
                             $newItem->addResponse($newResponse);
                         }
                     }
                     $newCategory->addItem($newItem);
                 }
             }
             $element->addCategory($newCategory);
         }
     }
     return $element;
 }