From 6d735ab8eb4a2165efed95c11835cc6c092c162d Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 14 Oct 2013 22:08:12 +0000
Subject: [PATCH] Add %{ticket.user} to ticket template variables

---
 include/class.ticket.php |  3 +++
 include/class.user.php   | 30 +++++++++++++++++++++++-------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index 82cc169a5..c6c1b25dc 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -1093,6 +1093,9 @@ class Ticket {
 
                 return $closedate;
                 break;
+            case 'user':
+                return $this->getOwner();
+                break;
             default:
                 if (isset($this->_answers[$tag]))
                     // The answer object is retrieved here which will
diff --git a/include/class.user.php b/include/class.user.php
index b38ec2528..0b2f30c50 100644
--- a/include/class.user.php
+++ b/include/class.user.php
@@ -107,15 +107,31 @@ class User extends UserModel {
         return new PersonsName($this->name);
     }
 
+    function asVar() {
+        return (string) $this->getName();
+    }
+
+    function getVar($tag) {
+        if($tag && is_callable(array($this, 'get'.ucfirst($tag))))
+            return call_user_func(array($this, 'get'.ucfirst($tag)));
+
+        $tag = strtolower($tag);
+        foreach ($this->getDynamicData() as $e)
+            if ($e->getAnswer($tag))
+                return $e;
+    }
+
     function getDynamicData() {
-        $data = DynamicFormEntry::forClient($this->id);
-        if (!$data[0]) {
-            $data = array();
-            $g = UserForm::getInstance();
-            $g->setClientId($this->id);
-            $data[] = $g;
+        if (!isset($this->_entries)) {
+            $this->_entries = DynamicFormEntry::forClient($this->id);
+            if (!$this->_entries[0]) {
+                $this->_entries = array();
+                $g = UserForm::getInstance();
+                $g->setClientId($this->id);
+                $this->_entries[] = $g;
+            }
         }
-        return $data;
+        return $this->_entries;
     }
 
     function save($refetch=false) {
-- 
GitLab