osb/app/Models/Site.php

304 lines
10 KiB
PHP
Raw Normal View History

2017-12-07 23:04:02 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
2020-01-11 02:36:11 +00:00
use Illuminate\Support\Arr;
2018-07-31 04:11:00 +00:00
use Illuminate\Support\Facades\Log;
2017-12-07 23:04:02 +00:00
class Site extends Model
{
2018-05-20 12:53:14 +00:00
protected $table = 'ab_setup';
2018-07-06 06:57:49 +00:00
public $timestamps = FALSE;
2018-05-20 12:53:14 +00:00
protected $with = ['details','language'];
2018-07-31 04:11:00 +00:00
2017-12-07 23:04:02 +00:00
protected $casts = [
'address'=>'array',
];
2018-07-31 04:11:00 +00:00
public function details()
{
return $this->hasMany(SiteDetails::class);
}
2018-08-01 07:09:38 +00:00
public function language()
{
return $this->belongsTo(Language::class);
}
2018-07-31 04:11:00 +00:00
public function __get($key)
{
// @todo Not sure if this is functioning correctly?
if ($parent = parent::__get($key))
return $parent;
// Deprecated Items
if (! in_array($key,array_keys($this->_sampledata())))
{
Log::alert('No sample data for Key:',['key'=>$key]);
return NULL;
}
2018-08-07 04:26:33 +00:00
$detail = $this->getSiteDetailValue($key);
2018-07-31 04:11:00 +00:00
2018-08-07 04:26:33 +00:00
return $detail->exists ? $detail->value : $this->getDefaultValue($key);
}
2018-07-31 04:11:00 +00:00
2018-08-07 04:26:33 +00:00
private function getDefaultValue($key)
{
$okblank = [
2018-07-31 04:11:00 +00:00
'site_address2',
2018-08-07 04:26:33 +00:00
'site_fax',
'social',
'top_menu'
2018-07-31 04:11:00 +00:00
];
2018-08-07 04:26:33 +00:00
if (! in_array($key,$okblank))
Log::alert('Returning Default Value for Key:',['key'=>$key]);
2018-07-31 04:11:00 +00:00
2018-08-07 04:26:33 +00:00
// Suppress some default values
$default = [
'block_quotes' => '',
'clients' => '',
'page_tabs' => '',
'services' => '',
'site_description' => '',
'site_fax' => '',
'site_address2' => '',
'site_slider' => '',
'social' => [],
'steps' => '',
'testimonials' => '',
'top_menu' => [],
];
2020-01-11 02:36:11 +00:00
return Arr::get($default,$key);
2018-08-07 04:26:33 +00:00
}
public function getSiteLogoAttribute()
{
$return = $this->getSiteDetailValue('site_logo')->value;
return $return ? 'storage/'.$return : '/image/generic/150/20/fff';
}
private function getSiteDetailValue($key)
{
$return = $this->details->where('key',$key)->first();
return $return ?: (new SiteDetails);
2018-07-31 04:11:00 +00:00
}
2017-12-07 23:04:02 +00:00
/**
* Pre-load this model with Sample Data, if there is no database record
*/
private function _sampledata()
{
return [
'aboutus'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
'activity'=>[
['title'=>'Project 1','description'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.','subtitle'=>'Lorem ipsum dolor sit amet','image_small'=>'/image/generic/150/75/a00','image_large'=>'/image/generic/500/400/700'],
['title'=>'Project 2','description'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.','subtitle'=>'Lorem ipsum dolor sit amet','image_small'=>'/image/generic/150/75/b00','image_large'=>'/image/generic/500/400/800'],
['title'=>'Project 3','description'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.','subtitle'=>'Lorem ipsum dolor sit amet','image_small'=>'/image/generic/150/75/c00','image_large'=>'/image/generic/500/400/900'],
['title'=>'Project 4','description'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.','subtitle'=>'Lorem ipsum dolor sit amet','image_small'=>'/image/generic/150/75/d00','image_large'=>'/image/generic/500/400/a00'],
],
'activity_intro'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
2018-05-20 12:53:14 +00:00
'block_quotes'=>[
[
'title'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
'image'=>'/image/generic/150/75/1A3AAA'
],
],
'clients'=>[
[
'image'=>'/image/generic/200/100/999',
'hover'=>'/image/generic/200/100/399',
],
[
'image'=>'/image/generic/200/100/999',
'hover'=>'/image/generic/200/100/499',
],
[
'image'=>'/image/generic/200/100/999',
'hover'=>'/image/generic/200/100/599',
],
[
'image'=>'/image/generic/200/100/999',
'hover'=>'/image/generic/200/100/699',
],
[
'image'=>'/image/generic/200/100/999',
'hover'=>'/image/generic/200/100/689',
],
[
'image'=>'/image/generic/200/100/999',
'hover'=>'/image/generic/200/100/679',
],
[
'image'=>'/image/generic/200/100/999',
'hover'=>'/image/generic/200/100/669',
],
[
'image'=>'/image/generic/200/100/999',
'hover'=>'/image/generic/200/100/659',
],
[
'image'=>'/image/generic/200/100/999',
'hover'=>'/image/generic/200/100/649',
],
],
'clients_intro'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore',
'language_id'=>1,
2018-07-31 04:11:00 +00:00
'page_tabs'=>[
[
'title'=>'Title 1',
'image'=>'/image/generic/200/100/999',
'text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
],
[
'title'=>'Title 2',
'image'=>'/image/generic/200/100/799',
'text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
],
[
'title'=>'Title 3',
'image'=>'/image/generic/200/100/979',
'text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
],
],
'site_slider'=>[
2018-05-20 12:53:14 +00:00
[
'title'=>'Header <br/><span class="carousel-title-normal">and Title</span>',
'text'=>'This is what you were looking for',
'style'=>1,
'image'=>'url(/image/generic/300/300/eee)',
'button'=>['text'=>'Purchase Now','url'=>'#'],
],
[
'title'=>'Header and Title',
'text'=>'This is what you were looking for',
'text2'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/>Sed est nunc, sagittis at consectetur id.',
'style'=>2,
'image'=>'url(/image/generic/400/400/ddd)',
'button'=>['text'=>'Purchase Now','url'=>'#'],
],
[
'title'=>'Header and Title',
'text'=>'This is what you were looking for',
'text2'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/>Sed est nunc, sagittis at consectetur id.',
'style'=>2,
'image'=>'url(/image/generic/500/500/eee)',
//'button'=>['text'=>'Purchase Now','url'=>'#'],
],
],
2018-08-07 04:26:33 +00:00
'site_logo'=>route('image',['width'=>128,'height'=>32,'color'=>'eee']),
2018-07-31 04:11:00 +00:00
'site_address1'=>'Building Name',
'site_address2'=>NULL,
'site_city'=>'City',
'site_description'=>'Example Site',
'site_email'=>'nobody@example.com',
'site_fax'=>'+0 1 2345 6789',
'site_name'=>'Example',
'site_phone'=>'+0 1 2345 6789',
'site_postcode'=>'123 456',
'site_state'=>'State',
'site_tax'=>'12 123 123 123',
2017-12-07 23:04:02 +00:00
'services'=>[
['title'=>'Title 1','text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.','icon'=>'fa fa-location-arrow blue','image'=>NULL],
['title'=>'Title 2','text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.','icon'=>'fa fa-compress green','image'=>NULL],
['title'=>'Title 3','text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.','icon'=>'fa fa-check red','image'=>'/image/generic/200/100/999'],
],
2018-05-20 12:53:14 +00:00
'social'=>[
[
'name'=>'facebook',
'url'=>'http://www.facebook.com',
],
[
'name'=>'linkedin',
'url'=>'http://www.linkedin.com',
],
[ 'name'=>'twitter',
'url'=>'http://www.twitter.com',
],
],
2017-12-07 23:04:02 +00:00
'steps'=>[
['title'=>'Title 1','description'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud'],
['title'=>'Title 2','description'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud'],
['title'=>'Title 3','description'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud'],
],
2018-05-20 12:53:14 +00:00
'testimonials'=>[
[
'title'=>'Title 1',
'name'=>'Bart Simpson',
'quote'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud',
'photo'=>'/image/generic/200/100/999',
],
[
'title'=>'Title 2',
'name'=>'Lisa Simpson',
'quote'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud',
'photo'=>'/image/generic/200/100/499',
],
],
2017-12-07 23:04:02 +00:00
'top_menu'=>[
'Home'=>['name'=>'Home','url'=>'/','children'=>[
['name'=>'Link 1','url'=>'#/l2', 'children'=>[]],
['name'=>'Link 2','url'=>'#/l2', 'children'=>[]],
]],
'Option1'=>['name'=>'Option 1','url'=>'/o1','children'=>[]],
'Option2'=>['name'=>'Option 2','url'=>'/o2','children'=>[
['name'=>'O2 Link 1','url'=>'#/o2l1', 'children'=>[]],
['name'=>'O2 Link 1','url'=>'#/o2l2', 'children'=>[]],
]],
],
];
}
public function sample()
{
2018-08-07 04:26:33 +00:00
return $this->forceFill($this->_sampledata());
2017-12-07 23:04:02 +00:00
}
public function aboutus()
{
// @todo To be implemented
2020-01-11 02:36:11 +00:00
return Arr::get($this->_sampledata(),'aboutus');
2017-12-07 23:04:02 +00:00
}
private function _address()
{
$return = [];
2018-07-31 04:11:00 +00:00
if ($this->site_address1)
array_push($return,$this->site_address1);
if ($this->site_address2)
array_push($return,$this->site_address2);
if ($this->site_city)
array_push($return,sprintf('%s %s %s',$this->site_city.(($this->site_state OR $this->site_postcode) ? ',' : ''),$this->site_state,$this->site_postcode));
2017-12-07 23:04:02 +00:00
if (! $return)
$return = ['No Address'];
return $return;
}
2018-07-31 04:11:00 +00:00
public function allowed_keys(array $keys=[])
{
return $keys ? array_diff($keys,array_keys($this->_sampledata())) : array_keys($this->_sampledata());
}
2017-12-07 23:04:02 +00:00
public function address($type='plain')
{
switch ($type)
{
case 'html' : return join('<br>',$this->_address());
case 'newline': return join("\m",$this->_address());
default:
return join("\n",$this->_address());
}
}
2018-08-07 04:26:33 +00:00
}