From 4572b811a26e72196e6c90048a5a44cbbaae8a16 Mon Sep 17 00:00:00 2001
From: Damien Burel <damien.burel@maarch.org>
Date: Wed, 22 Feb 2017 17:07:33 +0100
Subject: [PATCH] =?UTF-8?q?FEAT=20#5233=20R=C3=A9cup=C3=A9ration=20de=20l'?=
 =?UTF-8?q?historique=20du=20courrier=20+=20cr=C3=A9ation=20filtre=20date?=
 =?UTF-8?q?=20angular?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../maarch_entreprise/Models/HistoryModel.php | 26 +++++++++++
 .../Models/HistoryModelAbstract.php           | 43 +++++++++++++++++++
 apps/maarch_entreprise/js/app.module.js       | 12 ++++++
 modules/visa/Controllers/VisaController.php   |  8 ++++
 modules/visa/Views/signatureBook.html         | 28 ++++++------
 5 files changed, 103 insertions(+), 14 deletions(-)
 create mode 100644 apps/maarch_entreprise/Models/HistoryModel.php
 create mode 100644 apps/maarch_entreprise/Models/HistoryModelAbstract.php

diff --git a/apps/maarch_entreprise/Models/HistoryModel.php b/apps/maarch_entreprise/Models/HistoryModel.php
new file mode 100644
index 00000000000..d69789e3987
--- /dev/null
+++ b/apps/maarch_entreprise/Models/HistoryModel.php
@@ -0,0 +1,26 @@
+<?php
+
+/*
+*    Copyright 2015 Maarch
+*
+*  This file is part of Maarch Framework.
+*
+*   Maarch Framework 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.
+*
+*   Maarch Framework 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 Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+require_once 'apps/maarch_entreprise/Models/HistoryModelAbstract.php';
+
+class HistoryModel extends HistoryModelAbstract {
+    // Do your stuff in this class
+}
\ No newline at end of file
diff --git a/apps/maarch_entreprise/Models/HistoryModelAbstract.php b/apps/maarch_entreprise/Models/HistoryModelAbstract.php
new file mode 100644
index 00000000000..a991bf697ed
--- /dev/null
+++ b/apps/maarch_entreprise/Models/HistoryModelAbstract.php
@@ -0,0 +1,43 @@
+<?php
+
+/*
+*    Copyright 2015 Maarch
+*
+*  This file is part of Maarch Framework.
+*
+*   Maarch Framework 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.
+*
+*   Maarch Framework 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 Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+require_once 'apps/maarch_entreprise/services/Table.php';
+
+class HistoryModelAbstract extends Apps_Table_Service {
+
+    public static function getByIdForActions(array $aArgs = []) {
+        static::checkRequired($aArgs, ['id']);
+        static::checkNumeric($aArgs, ['id']);
+
+
+        $aReturn = static::select([
+            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
+            'table'     => ['history', 'users'],
+            'left_join' => ['history.user_id = users.user_id'],
+            'where'     => ['history.record_id = ?', 'history.event_type like ?', 'history.event_id ~ ?'],
+            'data'      => [$aArgs['id'], 'ACTION#%', '^[0-9]+$'],
+            'order_by'  => empty($aArgs['orderBy']) ? ['event_date'] : $aArgs['orderBy']
+        ]);
+
+        return $aReturn;
+    }
+
+}
\ No newline at end of file
diff --git a/apps/maarch_entreprise/js/app.module.js b/apps/maarch_entreprise/js/app.module.js
index 6b67c18c67c..403e72a1278 100644
--- a/apps/maarch_entreprise/js/app.module.js
+++ b/apps/maarch_entreprise/js/app.module.js
@@ -9,3 +9,15 @@ mainApp.config(['$routeProvider', '$locationProvider', function($routeProvider,
 
   $locationProvider.hashPrefix('');
 }]);
+
+mainApp.filter('datetimeFormat', function($filter)
+{
+  return function(input)
+  {
+    if(input == null) {
+      return "";
+    }
+
+    return $filter('date')(new Date(input), 'dd/MM/yyyy HH:mm');
+  };
+});
diff --git a/modules/visa/Controllers/VisaController.php b/modules/visa/Controllers/VisaController.php
index 29f96266884..614ca931641 100644
--- a/modules/visa/Controllers/VisaController.php
+++ b/modules/visa/Controllers/VisaController.php
@@ -7,6 +7,7 @@ use Psr\Http\Message\ResponseInterface;
 
 require_once 'modules/basket/class/class_modules_tools.php';
 require_once 'apps/maarch_entreprise/Models/ResModel.php';
+require_once 'apps/maarch_entreprise/Models/HistoryModel.php';
 
 
 class VisaController {
@@ -95,6 +96,12 @@ class VisaController {
 			];
 		}
 
+		$history = \HistoryModel::getByIdForActions([
+			'id'      => $resId,
+			'select'  => ['event_date', 'info', 'firstname', 'lastname'],
+			'orderBy' => ['event_date DESC']
+		]);
+
 
 		$datas = [];
 		$datas['actions'] = $actionsData;
@@ -102,6 +109,7 @@ class VisaController {
 		$datas['documents'] = $documents;
 		$datas['currentAction'] = $_SESSION['current_basket']['default_action']; //TODO Aller chercher l'id de la basket sans passer par la session
 		$datas['linkNotes'] = 'index.php?display=true&module=notes&page=notes&identifier=' .$resId. '&origin=document&coll_id=letterbox_coll&load&size=medium';
+		$datas['history'] = $history;
 
 		return $response->withJson($datas);
 	}
diff --git a/modules/visa/Views/signatureBook.html b/modules/visa/Views/signatureBook.html
index d5a0964bff9..252b7a9a9f9 100644
--- a/modules/visa/Views/signatureBook.html
+++ b/modules/visa/Views/signatureBook.html
@@ -1,30 +1,30 @@
 <div class="visaResList">
-        
+        {{signatureBook.history[0].event_date | datetimeFormat}}
         
 </div>
 <div class='visaContent'>
     <div class="headerSignatureBook">
         <div class="item" ng-class="{'activeTabSignatureBook': signatureBook.headerTab == 1}" ng-click="changeSignatureBookLeftContent(1)">
             <i class="fa fa-dashboard fa-2x"></i>
-          </div>
-          <div class="item" ng-class="{'activeTabSignatureBook': signatureBook.headerTab == 2}" ng-click="changeSignatureBookLeftContent(2)">
+        </div>
+        <div class="item" ng-class="{'activeTabSignatureBook': signatureBook.headerTab == 2}" ng-click="changeSignatureBookLeftContent(2)">
             <i class="fa fa-pencil fa-2x"></i>
-          </div>
-          <div class="item" ng-class="{'activeTabSignatureBook': signatureBook.headerTab == 3}" ng-click="changeSignatureBookLeftContent(3)">
+        </div>
+        <div class="item" ng-class="{'activeTabSignatureBook': signatureBook.headerTab == 3}" ng-click="changeSignatureBookLeftContent(3)">
             <i class="fa fa-certificate fa-2x"></i>
-          </div>
-            <div class="item" ng-class="{'activeTabSignatureBook': signatureBook.headerTab == 4}" ng-click="changeSignatureBookLeftContent(4)">
+        </div>
+        <div class="item" ng-class="{'activeTabSignatureBook': signatureBook.headerTab == 4}" ng-click="changeSignatureBookLeftContent(4)">
             <i class="fa fa-line-chart fa-2x"></i>
-          </div>
-            <div class="others">
+        </div>
+        <div class="others">
             
-          </div>
-          <div class="actions">
+        </div>
+        <div class="actions">
             <select id="signatureBookActions">
                 <option ng-repeat="option in signatureBook.actions" value="{{option.value}}">{{option.label}}</option>
             </select>
             <input name="send" id="send" value="Valider" class="button" type="button" ng-click="validForm()">
-          </div>
+        </div>
     </div>
     <div class="contentSignatureBook">
         <div class="contentLeft">
@@ -49,8 +49,8 @@
         <div class="contentRight">
             <div class="contentShow">
                 <div class="pjDetails">
-                    <div class="infoPj"><label>Type : </label><span>Projet de réponse</span></div>
-                    <div class="infoPj"><label>Objet : </label><span>Réponse délicate</span></div>
+                    <div class="infoPj"><label>Type : </label><span>{{signatureBook.attachments[signatureBook.rightSelectedThumbnail].attachment_type}}</span></div>
+                    <div class="infoPj"><label>Objet : </label><span>{{signatureBook.attachments[signatureBook.rightSelectedThumbnail].title}}</span></div>
                     <div class="infoPj"><label>Contact : </label><span>Laurent GIOVANONNI - 11 boulevard du sud est</span></div>
                 </div>
                 <div class="pjDetailsMore">
-- 
GitLab