1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
<?php
namespace hji\construction\models\subdivisions;
use hji\construction\core\DataModel;
use hji\construction\models\Labels;
class SubdivisionModel extends DataModel
{
protected $rawData;
protected $postType = 'nc-subdivision';
function __construct($rawData = null)
{
if ($rawData)
{
$this->setData($rawData);
}
$this->labels = new Labels();
}
function setData($rawData)
{
parent::setData($rawData);
$this->postTitle = $this->name;
if ($builder = $this->getBuilder())
{
$this->postTitle .= ' by ' . $builder->name;
}
$this->pageSlug = sanitize_title($this->id . '-' . $this->name);
}
function getListings()
{
if (!property_exists($this, 'listings'))
{
$request = $this->services()->getRequest();
$listingsModel = $this->di()->create('hji\\construction\\models\\listings\\ListingsModel');
$params = $request->get('hji-params');
$parameters['subdivision'] = $this->id;
$parameters['pageNumber'] = (isset($params['ncpage'])) ? $params['ncpage'] : 1;
$parameters['pageSize'] = 30;
$listingsModel->setSearchParams($parameters);
$listingsModel->getData();
$this->listings = $listingsModel;
}
return $this->listings;
}
function getFeatures()
{
if (!isset($this->features) && !empty($this->rawData->features))
{
$this->features = null;
foreach ($this->rawData->features as $k => $v)
{
if ($v == true)
{
$this->features[$k] = $this->labels->$k;
}
}
}
else
{
$this->features = null;
}
return $this->features;
}
function getBuilder()
{
if (!isset($this->builder) && isset($this->rawData->builder))
{
$this->builder = $this->rawData->builder;
if (property_exists($this->builder, 'url'))
{
$parts = parse_url($this->builder->url);
if (!isset($parts['scheme']))
{
$this->builder->url = 'http://' . $this->builder->url;
}
}
}
return $this->builder;
}
function getCityUrl()
{
if ($this->address->city)
{
$state = strtolower($this->address->state);
$city = strtolower($this->address->city);
$slug = $state . '/' . sanitize_title($city);
$archiveUrl = trailingslashit(get_post_type_archive_link($this->getPostType()));
return trailingslashit($archiveUrl . $slug);
}
}
}