diff --git a/include/class.dept.php b/include/class.dept.php index 8131be44fda8db7147d65c5c22ee41fade6396fc..d06bef503bf0447b92ec74c61d251a7f4f4182a5 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -87,6 +87,13 @@ implements TemplateVariable { ); } + function getVar($tag) { + switch ($tag) { + case 'members': + return new UserList($this->getMembers()->all()); + } + } + function getId() { return $this->id; } @@ -187,7 +194,7 @@ implements TemplateVariable { $this->_members = $members; } - return new UserList($this->_members->all()); + return $this->_members; } function getAvailableMembers() { diff --git a/include/class.format.php b/include/class.format.php index 903256a6f52e983ceda3a93b7395953587f113e3..85b1fd9aeefccd11387d4d93f3c26999de6b20ba 100644 --- a/include/class.format.php +++ b/include/class.format.php @@ -893,9 +893,6 @@ implements TemplateVariable { function getVar($what) { global $cfg; - if (method_exists($this, 'get' . ucfirst($what))) - return call_user_func(array($this, 'get'.ucfirst($what))); - // TODO: Rebase date format so that locale is discovered HERE. switch ($what) { diff --git a/include/class.organization.php b/include/class.organization.php index 6d3ceaeb143471d6eccb237253c0cb1dac11f200..e1514f19d0c6859477340067a966d601a9dba6fa 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -293,9 +293,6 @@ implements TemplateVariable { } function getVar($tag) { - if($tag && is_callable(array($this, 'get'.ucfirst($tag)))) - return call_user_func(array($this, 'get'.ucfirst($tag))); - $tag = mb_strtolower($tag); foreach ($this->getDynamicData() as $e) if ($a = $e->getAnswer($tag)) diff --git a/include/class.team.php b/include/class.team.php index 0d5e7013f2864eccd13d8fcec7450d3e09d0cd66..1165ecc8a104c06e09ba2badd92006c452d8a6ce 100644 --- a/include/class.team.php +++ b/include/class.team.php @@ -26,7 +26,6 @@ implements TemplateVariable { 'constraint' => array('lead_id' => 'Staff.staff_id'), ), 'members' => array( - 'null' => true, 'list' => true, 'reverse' => 'TeamMember.team', ), @@ -58,6 +57,13 @@ implements TemplateVariable { ); } + function getVar($tag) { + switch ($tag) { + case 'members': + return new UserList($this->getMembers()->all()); + } + } + function getId() { return $this->team_id; } @@ -74,14 +80,12 @@ implements TemplateVariable { } function getMembers() { - if (!isset($this->_members)) { $this->_members = array(); foreach ($this->members as $m) $this->_members[] = $m->staff; } - - return new UserList($this->_members); + return $this->_members; } function hasMember($staff) { @@ -148,9 +152,6 @@ implements TemplateVariable { $errors['name']=__('Team name already exists'); } - if ($errors) - return false; - // Reset team lead if they're getting removed if (isset($this->lead_id) && $this->lead_id == $vars['lead_id'] diff --git a/include/class.thread.php b/include/class.thread.php index 7e84d5baa643d4c3118558101f1caba8db706584..4d45e5f95e7ab86a3c0241f9de68142d5f76b4c1 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -1049,9 +1049,6 @@ implements TemplateVariable { } function getVar($tag) { - if ($tag && is_callable(array($this, 'get'.ucfirst($tag)))) - return call_user_func(array($this, 'get'.ucfirst($tag))); - switch(strtolower($tag)) { case 'create_date': return new FormattedDate($this->getCreateDate()); @@ -1060,8 +1057,6 @@ implements TemplateVariable { case 'files': throw new OOBContent(OOBContent::FILES, $this->attachments->all()); } - - return false; } static function getVarScope() { diff --git a/include/class.ticket.php b/include/class.ticket.php index bcacc0dd3c7363b12ce202acf9caee4df18fe460..b19fc6e9f4f17f5bbebc1d94b3fb5f340d17086c 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1663,9 +1663,6 @@ implements RestrictedAccess, Threadable { function getVar($tag) { global $cfg; - if ($tag && is_callable(array($this, 'get'.ucfirst($tag)))) - return call_user_func(array($this, 'get'.ucfirst($tag))); - switch(mb_strtolower($tag)) { case 'phone': case 'phone_number': @@ -1703,7 +1700,6 @@ implements RestrictedAccess, Threadable { // answer is coerced into text return $this->_answers[$tag]; } - return false; } static function getVarScope() { diff --git a/include/class.user.php b/include/class.user.php index ad3302a2c3b95c3442abefb95faf53b7768a0324..d9a7328616065df3be453037ee676b1af0902c8a 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -360,9 +360,6 @@ implements TemplateVariable { } function getVar($tag) { - if($tag && is_callable(array($this, 'get'.ucfirst($tag)))) - return call_user_func(array($this, 'get'.ucfirst($tag))); - $tag = mb_strtolower($tag); foreach ($this->getDynamicData() as $e) if ($a = $e->getAnswer($tag)) diff --git a/include/class.variable.php b/include/class.variable.php index 869c87f9b4a6f6f38f458d02bf725abef01165ba..0efd70d71b422a5d262931b50085d8c264eca2d5 100644 --- a/include/class.variable.php +++ b/include/class.variable.php @@ -59,37 +59,44 @@ class VariableReplacer { function getVar($obj, $var) { - if(!$obj) return ""; + if (!$obj) + return ""; - if (!$var) { - if (method_exists($obj, 'asVar')) - return call_user_func(array($obj, 'asVar'), $this); - elseif (method_exists($obj, '__toString')) - return (string) $obj; + // Order or resolving %{... .tag.remainder} + // 1. $obj[$tag] + // 2. $obj->tag + // 3. $obj->getVar(tag) + // 4. $obj->getTag() + @list($tag, $remainder) = explode('.', $var ?: '', 2); + $tag = mb_strtolower($tag); + $rv = null; + + if (!is_object($obj)) { + if ($tag && is_array($obj) && array_key_exists($tag, $obj)) + $rv = $obj[$tag]; + else + // Not able to continue the lookup + return ''; } - - list($v, $part) = explode('.', $var, 2); - if ($v && is_callable(array($obj, 'get'.ucfirst($v)))) { - $rv = call_user_func(array($obj, 'get'.ucfirst($v))); - if(!$rv || !is_object($rv)) - return $rv; - - return $this->getVar($rv, $part); + else { + if (!$var) { + if (method_exists($obj, 'asVar')) + return call_user_func(array($obj, 'asVar'), $this); + elseif (method_exists($obj, '__toString')) + return (string) $obj; + } + if (method_exists($obj, 'getVar')) { + $rv = $obj->getVar($tag, $this); + } + if (!isset($rv) && property_exists($obj, $tag)) { + $rv = $obj->{$tag}; + } + if (!isset($rv) && is_callable(array($obj, 'get'.ucfirst($tag)))) { + $rv = call_user_func(array($obj, 'get'.ucfirst($tag))); + } } - if (is_array($obj) && isset($obj[$v])) - return $obj[$v]; - - if (!$var || !method_exists($obj, 'getVar')) - return ""; - - list($tag, $remainder) = explode('.', $var, 2); - if(($rv = call_user_func(array($obj, 'getVar'), $tag, $this))===false) - return ""; - - if(!is_object($rv)) - return $rv; - + // Recurse with $rv return $this->getVar($rv, $remainder); }