From 0470d8f76001977bb99df30703c052afa1232d8f Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Fri, 29 Sep 2017 11:32:26 +0200
Subject: [PATCH] dev #59187 add attachment view

---
 library/Class/WebService/Redmine/Issue.php    | 16 ++++++++--
 .../View/Helper/Redmine/IssueAttachments.php  | 32 +++++++++++++++++++
 .../View/Helper/Redmine/IssueJournal.php      |  4 +++
 3 files changed, 49 insertions(+), 3 deletions(-)
 create mode 100644 library/ZendAfi/View/Helper/Redmine/IssueAttachments.php

diff --git a/library/Class/WebService/Redmine/Issue.php b/library/Class/WebService/Redmine/Issue.php
index 15df5150f6a..a2a6819bc7d 100644
--- a/library/Class/WebService/Redmine/Issue.php
+++ b/library/Class/WebService/Redmine/Issue.php
@@ -25,9 +25,7 @@ class Class_WebService_Redmine_Issue extends Class_Entity {
 
   public static function newWith($data) {
     $instance = new static();
-    $instance->updateAttributes($data);
-
-    return $instance;
+    return $instance->updateAttributes($data);
   }
 
 
@@ -136,6 +134,18 @@ class Class_WebService_Redmine_Issue extends Class_Entity {
   }
 
 
+  public function renderAttachment($view, $key, $filename) {
+    if(!$filename)
+      return $view->tag('span', $this->_('Suppression de pièce jointe'));
+
+    $url = sprintf('%s/attachments/download/%s/%s',
+                   Class_AdminVar::get('REDMINE_SERVER_URL'),
+                   $key,
+                   $filename);
+    return $view->tagAnchor($url, $this->_('Pièce jointe : %s', $filename), ['target' => '_blank']);
+  }
+
+
   protected function withServiceDo($closure) {
     return ($service = $this->getService()) ? $closure($service) : null;
   }
diff --git a/library/ZendAfi/View/Helper/Redmine/IssueAttachments.php b/library/ZendAfi/View/Helper/Redmine/IssueAttachments.php
new file mode 100644
index 00000000000..3dd1e72ebbe
--- /dev/null
+++ b/library/ZendAfi/View/Helper/Redmine/IssueAttachments.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+
+class ZendAfi_View_Helper_Redmine_IssueAttachments extends ZendAfi_View_Helper_BaseHelper {
+  protected $_issue;
+
+  public function Redmine_IssueAttachments($issue) {
+    if (!$issue || (!$attachements = $issue->getAttachments()))
+      return $this->_('Aucune pièce jointe');
+
+    return '';
+  }
+}
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/Redmine/IssueJournal.php b/library/ZendAfi/View/Helper/Redmine/IssueJournal.php
index 2b1a65b6fcf..239a72d690e 100644
--- a/library/ZendAfi/View/Helper/Redmine/IssueJournal.php
+++ b/library/ZendAfi/View/Helper/Redmine/IssueJournal.php
@@ -95,6 +95,10 @@ class ZendAfi_View_Helper_Redmine_IssueJournal extends ZendAfi_View_Helper_BaseH
 
 
   protected function renderDetail($detail) {
+    if('attachment' == $detail['property'])
+      return $this->_tag('li', $this->_issue->renderAttachment($this->view,
+                                                               $detail['name'],
+                                                               $detail['new_value']));
     if ('relation' == $detail['property'])
       return $this->_tag('li', $this->labelFromCode($detail['name'],
                                                     isset($detail['old_value']) ? $detail['old_value'] : null,
-- 
GitLab