Initial Release

This commit is contained in:
Deon George
2018-04-23 17:45:21 +10:00
commit 2987e622de
16 changed files with 786 additions and 0 deletions

56
src/Carbon.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
namespace Leenooks;
use Carbon\Carbon as CarbonBase;
/**
* This overrides the default Carbon\Carbon class so that we can enable
* additional Date functions, like Half Years
*/
class Carbon extends CarbonBase
{
const MONTHS_PER_HALF = 6;
public function __get($name)
{
switch (true) {
case $name === 'half':
return (int) ceil($this->month / static::MONTHS_PER_HALF);
default:
return parent::__get($name);
}
}
/**
* Modify to the first occurrence of a given day of the week
* in the current quarter. If no dayOfWeek is provided, modify to the
* first day of the current quarter. Use the supplied constants
* to indicate the desired dayOfWeek, ex. static::MONDAY.
*
* @param int|null $dayOfWeek
*
* @return static
*/
public function firstOfHalf($dayOfWeek = null)
{
return $this->setDate($this->year, $this->half * static::MONTHS_PER_HALF - 5, 1)->firstOfMonth($dayOfWeek);
}
/**
* Modify to the last occurrence of a given day of the week
* in the current quarter. If no dayOfWeek is provided, modify to the
* last day of the current quarter. Use the supplied constants
* to indicate the desired dayOfWeek, ex. static::MONDAY.
*
* @param int|null $dayOfWeek
*
* @return static
*/
public function lastOfHalf($dayOfWeek = null)
{
return $this->setDate($this->year, $this->half * static::MONTHS_PER_HALF, 1)->lastOfMonth($dayOfWeek);
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Leenooks\Providers;
#use Acacha\User\Http\Middleware\GuestUser;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
/**
* Class GuestUserServiceProvider.
*
* @package Acacha\User\Providers
*/
class LeenooksServiceProvider extends ServiceProvider
{
private $_path = '';
/**
* Bootstrap the application services.
*
* @param Router $router
*/
public function boot(Router $router)
{
$this->loadViewsFrom($this->_path.'/resources/themes/adminlte/views/', 'adminlte');
# $this->loadViewsFrom($this->_path.'/resources/views/', 'adminlte');
$this->loadTranslationsFrom($this->_path.'/resources/themes/adminlte/lang/', 'adminlte_lang');
//dd($this->views());
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
if (! $this->_path) {
$this->_path = realpath(__DIR__.'/../../');
define('LEENOOKS',realpath(__DIR__.'/../../'));
}
//$this->publishes($this->views());
}
/**
* Views copy path.
*
* @return array
*/
public function views()
{
return [
LEENOOKS.'/resources/views/auth' =>
resource_path('views/vendor/adminlte/auth'),
$this->_path.'/resources/views/errors' =>
resource_path('views/vendor/adminlte/errors'),
$this->_path.'/resources/views/layouts' =>
resource_path('views/vendor/adminlte/layouts'),
$this->_path.'/resources/views/home.blade.php' =>
resource_path('views/vendor/adminlte/home.blade.php'),
$this->_path.'/resources/views/welcome.blade.php' =>
resource_path('views/welcome.blade.php'),
];
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* Collapse a collection, by summing up fields.
*/
namespace Leenooks\Traits;
use Illuminate\Support\Collection;
trait CollectionCollapse {
/**
* Collapse a collection by summing up records according to a given key
*
* @param Collection $c Collection to collapse
* @param array $id To use as the group by key
* @param array $consolidateKeys Keys that should be summed up during the process
* @return Collection
*/
protected function collapse(Collection $c,array $id,array $consolidateKeys=[])
{
return $c->groupBy(function ($item,$key) use ($id) {
$string = '';
foreach ($id as $key) {
if ($string AND array_get($item,$key))
$string .= '.';
$string .= $item[$key];
}
return $string;
})->transform(function ($items,$key) use ($consolidateKeys) {
$newitem = [];
if ($items->count()) {
$c = 0;
foreach ($items as $item) {
if (! $c++) {
$newitem = $item;
continue;
}
foreach ($item as $k => $v) {
// Add these values to the existing ones
if (in_array($k, $consolidateKeys)) {
if (!isset($newitem[$k]))
$newitem[$k] = 0;
$newitem[$k] += $v;
}
}
}
} else {
$newitem = $items;
}
return $newitem;
});
}
}

19
src/Traits/ModelCache.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
/**
* Traits adds our standing cache functions
*/
namespace Leenooks\Traits;
trait ModelCache
{
// Time to cache calculations for
private $cachetime = 10080; // a week
/**
* Auto calculate a cache key
*/
private function cachekey($method,$one,$two=NULL) {
return md5(sprintf('%s:%s:%s',$method,$one,$two ? $two : $this->id));
}
}