Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/tabs/apiclient/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,21 @@ public function getCountry()
{
return $this->country;
}

public function quickSet($data)
{
$this->id = $data->id;
$this->line1 = $data->line1;
$this->line2 = $data->line2;
$this->line3 = $data->line3;
$this->town = $data->town;
$this->county = $data->county;
$this->postcode = $data->postcode;
$this->longitude = $data->longitude;
$this->latitude = $data->latitude;
$this->geohash = $data->geohash;
$this->country = Country::factory($data->country);

return $this;
}
}
21 changes: 21 additions & 0 deletions src/tabs/apiclient/Branding.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,25 @@ public function getCurrency()
{
return $this->currency;
}

public function quickSet($data)
{
$this->id = $data->id;
$this->inactive = $data->inactive;
$this->lettingbranding = $data->lettingbranding;
$this->bacsbankaccount = $data->bacsbankaccount;
$this->bacsoutputtype = $data->bacsoutputtype;
$this->bacssettings = $data->bacssettings;
$this->bookingdatesarechangedays = $data->bookingdatesarechangedays;
$this->allowbookingonwebuntil = new \DateTime($data->allowbookingonwebuntil);
$this->showpricingonwebuntil = new \DateTime($data->showpricingonwebuntil);

$this->marketingbrand = MarketingBrand::factory($data->marketingbrand);
$this->brandinggroup = BrandingGroup::factory($data->brandinggroup);
$this->bookingbrand = BookingBrand::factory($data->bookingbrand);
$this->lettingincomevatband = Vatband::factory($data->lettingincomevatband);
//$this->petextrabranding = extra\Branding::factory($data->petextrabranding);

return $this;
}
}
99 changes: 56 additions & 43 deletions src/tabs/apiclient/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,114 +12,113 @@
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version Release: 1
* @link http://www.carltonsoftware.co.uk
*
*
* @method Document setName(string $filename) Set the name
* @method Document setFilename(string $filename) Set the filename
* @method Document setDescription(string $desc) Set the description
* @method Document setWeight(integer $weight) Set the weight
* @method Document setPrivate(boolean $boolean) Set the visibility flag
*
*
*/
class Document extends \tabs\apiclient\FileBuilder
{
/**
* Name
*
*
* @var string
*/
protected $name = '';

/**
* Filename
*
*
* @var string
*/
protected $filename = '';

/**
* Time added
*
*
* @var \DateTime
*/
protected $timeadded;

/**
* Description
*
* @var string
*
* @var string
*/
protected $description = '';

/**
* Weight
*
* @var integer
*
* @var integer
*/
protected $weight = 0;

/**
* Private bool
*
* @var boolean
*
* @var boolean
*/
protected $private = false;

/**
* Mimetype
*
* @var Mimetype
*
* @var Mimetype
*/
protected $mimetype;

/**
* Document tags
*
*
* @var Collection|\tabs\apiclient\document\Tag[]
*/
protected $tags;

// -------------------------- Public Functions -------------------------- //

/**
* Constructor
*
*
* @param integer $id ID
*
* @param object $data Data to populate object
*
* @return void
*/
public function __construct($id = null)
public function __construct($id = null, $data = null)
{
$this->timeadded = new \DateTime();
$this->tags = Collection::factory(
new document\Tag(),
$this
);

parent::__construct($id);
if($data) {
$this->quickSet($data);
} else {
$this->timeadded = new \DateTime();
$this->tags = Collection::factory(
new document\Tag(),
$this
);

parent::__construct($id);
}
}

/**
* Return visibility flag
*
*
* @return boolean
*/
public function isPrivate()
{
return $this->private;
}

/**
* Set the document mimetype
*
*
* @param array|stdClass|Mimetype $mimeType Mimetype
*
*
* @return Document
*/
public function setMimetype($mimeType)
{
$this->mimetype = Mimetype::factory($mimeType);

return $this;
}

Expand Down Expand Up @@ -202,4 +201,18 @@ public function getTags()
{
return $this->tags;
}

public function quickSet($data)
{
$this->name = $data->name;
$this->filename = $data->filename;
$this->description = $data->description;
$this->weight = $data->weight;
$this->timeadded = new \DateTime($data->timeadded);
$this->private = $data->private;
$this->tags = $data->tags;
$this->mimetype = Mimetype::factory($data->mimetype);

return $this;
}
}
29 changes: 17 additions & 12 deletions src/tabs/apiclient/FactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,20 @@ public static function setObjectProperties(&$obj, $node, $exceptions = array())
if (method_exists($obj, 'setDormant')) {
$obj->setDormant(false);
}

foreach ($node as $key => $val) {
// Check/create collections if they exist
$obj->_check_collection_map($key);

$func = 'set' . ucfirst($key);
if (!in_array($key, $exceptions)) {
if (method_exists($obj, $func)) {
$obj->$func($val);
} elseif (property_exists($obj, $key) ) {
$obj->setObjectProperty($obj, $key, $val);
if (\method_exists($obj, 'quickSet')) {
$obj->quickSet($node);
} else {
foreach ($node as $key => $val) {
// Check/create collections if they exist
$obj->_check_collection_map($key);

$func = 'set' . ucfirst($key);
if (!in_array($key, $exceptions)) {
if (method_exists($obj, $func)) {
$obj->$func($val);
} elseif (property_exists($obj, $key) ) {
$obj->setObjectProperty($obj, $key, $val);
}
}
}
}
Expand Down Expand Up @@ -452,6 +455,7 @@ public function __toArray()
*/
protected function setObjectProperty($obj, $property, $value)
{
//echo "<p>".get_class($obj)." ".$property." ".strtolower(gettype($obj->$property))." ". ($value instanceof \DateTime ? $value->format('y-M-d') : $value). "</p>";
switch (strtolower(gettype($obj->$property))) {
case 'array':
case 'integer':
Expand All @@ -461,7 +465,8 @@ protected function setObjectProperty($obj, $property, $value)
if ($obj->$property instanceof \DateTime && (!$value instanceof \DateTime)) {
//Special handling for DateTime fields
$obj->$property = new \DateTime($value);
} else if ($obj->$property instanceof \tabs\apiclient\StaticCollection
//echo "<p>".get_class($obj)." ".$property." ".strtolower(gettype($obj->$property))." ". ($value instanceof \DateTime ? $value->format('y-M-d') : $value). "</p>";
} else if ($obj->$property instanceof \tabs\apiclient\StaticCollection
&& (!$value instanceof \tabs\apiclient\StaticCollection)
&& is_array($value)
) {
Expand Down
Loading