From 99046d49e5950a85287de5b308610c5421541fc2 Mon Sep 17 00:00:00 2001 From: Michael Calcinai Date: Sat, 20 Jun 2015 12:46:43 +1200 Subject: [PATCH] Updated generator to parse out attachment and PDF capable models --- generator/generate | 5 +++++ generator/objects/Model.php | 38 +++++++++++++++++++++++++++++++++- generator/templates/model.twig | 14 +++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/generator/generate b/generator/generate index 2889f134..7b5d9e7b 100755 --- a/generator/generate +++ b/generator/generate @@ -439,6 +439,11 @@ foreach($scrape_apis as $scrape_api) { //Debug $model->printPropertyTable(); } + + if(strpos($primary_model->rawHTML, 'returned as PDF') !== false){ + //Assume that it does support it. + $primary_model->setSupportsPDF(true); + } } }); diff --git a/generator/objects/Model.php b/generator/objects/Model.php index 5f788b90..67533afa 100644 --- a/generator/objects/Model.php +++ b/generator/objects/Model.php @@ -14,7 +14,9 @@ class Model { private $api; /** - * @var The parent model of the object. This is if it's defined as a secondary model on a doc page + * The parent model of the object. This is if it's defined as a secondary model on a doc page + * + * @var Model $parent_model */ private $parent_model; @@ -23,6 +25,14 @@ class Model { */ private $guid_property; + /** + * @var bool $supports_pdf + */ + private $supports_pdf; + + + public $rawHTML; + /** * No args in constructor. Most things are not known when it's built */ @@ -31,6 +41,7 @@ public function __construct(){ $this->properties = array(); $this->methods = array(); $this->sub_models = array(); + $this->supports_pdf = false; } /** @@ -250,6 +261,31 @@ public function setUrl($url) { $this->url = $url; } + + /** + * This should be enough to tell if it supports them + * + * @return boolean + */ + public function getSupportsAttachments() { + return $this->hasProperty('HasAttachments'); + } + + /** + * @return boolean + */ + public function getSupportsPDF() { + return $this->supports_pdf; + } + + /** + * @param boolean $supports_pdf + */ + public function setSupportsPDF($supports_pdf) { + $this->supports_pdf = $supports_pdf; + } + + /** * Shortcut for getting them from $api where the group is the same as this name * diff --git a/generator/templates/model.twig b/generator/templates/model.twig index 77b4d30d..4b857f4c 100644 --- a/generator/templates/model.twig +++ b/generator/templates/model.twig @@ -4,12 +4,26 @@ namespace XeroPHP\Models\{{ model.Namespace }}; use XeroPHP\Remote; +{% if model.SupportsPDF %} +use XeroPHP\Traits\PDFTrait; +{% endif %} +{% if model.SupportsAttachments %} +use XeroPHP\Traits\AttachmentTrait; + +{% endif %} {% for class in model.UsedClasses %} use XeroPHP\Models\{{ class }}; {% endfor %} class {{ model.ClassName }} extends Remote\Object { +{% if model.SupportsPDF %} + use PDFTrait; +{% endif %} +{% if model.SupportsAttachments %} + use AttachmentTrait; + +{% endif %} {% for property in model.Properties %} /** * {{ property.Description|wordwrap(100, "\n * ")|raw }}