FEATURE: change directory structure

This commit is contained in:
Michal Kváček
2016-10-17 00:07:21 +02:00
parent 87f1920373
commit 2ded2924a1
242 changed files with 742 additions and 1171 deletions
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\ActionLogType;
class ActionLogTypes extends BaseEnumeration
{
/**
* Init list of all action log types
*
* @throws Exceptions\EnumerationExistsException
*/
protected static function init()
{
$types = ActionLogType::all(['id', 'name']);
foreach ($types as $type) {
self::push($type->id, $type->name);
}
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\ActionLog\ActionLogType;
class ActionLogTypesForLogger extends BaseEnumeration
{
protected static function init()
{
$types = ActionLogType::all(['string_id', 'id']);
foreach ($types as $type) {
self::push($type->string_id, $type->id);
}
}
}
+120
View File
@@ -0,0 +1,120 @@
<?php
namespace App\CMS\Enumerations;
use App\CMS\Exceptions\Enumerations\EnumerationExistsException;
abstract class BaseEnumeration
{
protected static $initiliazed = [];
public static $items = [];
const ORDER_BY_KEY = 1;
const ORDER_BY_KEY_DESC = 2;
const ORDER_BY_TEXT = 4;
const ORDER_BY_TEXT_DESC = 8;
/**
* Init enumerations
*/
protected static function init()
{
$className = get_called_class();
if (!in_array($className, self::$initiliazed)) {
// try to call init() method
if (method_exists($className, 'init')) {
$className::init();
}
// it can happen that even after init no enumerations are available
if (empty(self::$items[$className])) {
self::$items[$className] = [];
}
self::$initiliazed[] = $className;
}
}
/**
* Add new item into enumeration
*
* @param $key
* @param $translation
* @param bool|false $overwrite
*
* @throws EnumerationExistsException
*/
public static function push($key, $translation, $overwrite = false)
{
// item exists and we do not want to overwrite items
if (!$overwrite && !is_null($key) && isset(self::$items[get_called_class()][$key])) {
throw new EnumerationExistsException(get_called_class() . ': ' . $key . ' already in ' . $translation);
}
// if given collection does not exists, create empty one
if (!isset(self::$items[get_called_class()])) {
self::$items[get_called_class()] = [];
}
// add to collection
self::$items[get_called_class()][$key] = trans($translation);
}
/**
* Return count of all items in collection
*
* @return int
*/
public static function getCount()
{
return count(self::getWithTranslations());
}
/**
* Getter for all enumeration items in iven collection.
*
* Return value is associative array indexed by item "name". Value of each field is its translation (translation
* string, e.g. admin/mainMenu.something)
*
* @param string $orderBy
*
* @return array
*/
public static function getWithTranslations($orderBy = self::ORDER_BY_KEY)
{
// if not initialized yet, init this enumerration
if (!in_array(get_called_class(), self::$initiliazed)) {
self::init();
}
$items = self::$items[get_called_class()];
// order results
switch ($orderBy) {
case self::ORDER_BY_KEY:
ksort($items);
break;
case self::ORDER_BY_KEY_DESC:
krsort($items);
break;
case self::ORDER_BY_TEXT:
sort($items);
break;
case self::ORDER_BY_TEXT_DESC:
rsort($items);
break;
}
return $items;
}
/**
* Getter for list of all enumeration items.
*
* @return array
*/
public static function getSimple()
{
return array_keys(self::getWithTranslations());
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\Content\Content;
class ContentStatuses extends BaseEnumeration
{
protected static function init()
{
$roles = [
Content::STATUS_DRAFT => 'admin/contents.status_' . Content::STATUS_DRAFT,
Content::STATUS_PROTECTED => 'admin/contents.status_' . Content::STATUS_PROTECTED,
Content::STATUS_PUBLIC => 'admin/contents.status_' . Content::STATUS_PUBLIC
];
foreach ($roles as $role => $translation) {
self::push($role, $translation);
}
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\CustomFieldResource;
class CustomFieldResources extends BaseEnumeration
{
public static $items = [];
public static function init()
{
// load items from database
$types = CustomFieldResource::all(['id', 'name']);
// push items into collection
foreach ($types as $type) {
self::push($type->id, $type->name);
}
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\CustomFieldType;
class CustomFieldTypes extends BaseEnumeration
{
public static $items = [];
public static function init()
{
// load items from database
$types = CustomFieldType::all(['id', 'name']);
// push items into collection
foreach ($types as $type) {
self::push($type->id, $type->name);
}
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\Module;
class ModuleNamesWithIds extends BaseEnumeration
{
/**
* Init list of all installed modules
*
* @throws Exceptions\EnumerationExistsException
*/
protected static function init()
{
$modules = Module::all(['id', 'name']);
foreach ($modules as $module) {
self::push($module->id, $module->name);
}
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\Module;
class Modules extends BaseEnumeration
{
/**
* Init list of all installed modules
*
* @throws Exceptions\EnumerationExistsException
*/
protected static function init()
{
$modules = Module::all(['handler', 'name']);
foreach ($modules as $module) {
self::push($module->handler, $module->name);
}
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\Module;
class ModulesHandlerToId extends BaseEnumeration
{
/**
* Init list of all installed modules
*
* @throws Exceptions\EnumerationExistsException
*/
protected static function init()
{
$modules = Module::all(['handler', 'id']);
foreach ($modules as $module) {
self::push($module->handler, $module->id);
}
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: michal
* Date: 18.2.16
* Time: 10:33
*/
namespace App\CMS\Enumerations;
use App\Models\TemplatePath;
class TemplatePaths extends BaseEnumeration
{
protected static function init()
{
$paths = TemplatePath::all(['id', 'path']);
foreach ($paths as $path) {
self::push($path->id, $path->path);
}
}
}
@@ -0,0 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: michal
* Date: 18.2.16
* Time: 10:33
*/
namespace App\CMS\Enumerations;
use App\Models\TemplatePath;
class TemplatePathsHumanReadable extends BaseEnumeration
{
protected static function init()
{
$paths = TemplatePath::all(['id', 'name']);
foreach ($paths as $path) {
self::push($path->id, $path->name);
}
}
}
@@ -0,0 +1,25 @@
<?php
/**
* Created by PhpStorm.
* User: michal
* Date: 18.2.16
* Time: 10:33
*/
namespace App\CMS\Enumerations;
use App\Models\TemplatePath;
class TemplatePathsHumanReadableRootOnly extends BaseEnumeration
{
protected static function init()
{
$paths = TemplatePath::where('parent_id', null)
->select(['id', 'name'])
->get();
foreach ($paths as $path) {
self::push($path->id, $path->name);
}
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: michal
* Date: 18.2.16
* Time: 15:50
*/
namespace App\CMS\Enumerations;
use App\Models\Template;
class Templates extends BaseEnumeration
{
protected static function init()
{
$templates = Template::all(['id', 'template_name']);
foreach ($templates as $template) {
self::push($template->id, $template->template_name);
}
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\User;
class UserRoles extends BaseEnumeration
{
public static function init()
{
$roles = [
User::ROLE_ADMIN => 'admin/userManagement.role_' . User::ROLE_ADMIN,
User::ROLE_EDITOR => 'admin/userManagement.role_' . User::ROLE_EDITOR,
User::ROLE_VISITOR => 'admin/userManagement.role_' . User::ROLE_VISITOR
];
foreach ($roles as $role => $translation) {
self::push($role, $translation);
}
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* User: michal
* Date: 24.1.16
* Time: 23:20
*/
namespace App\CMS\Enumerations;
use App\Models\User;
class UserStates extends BaseEnumeration
{
public static function init()
{
$items = [
User::STATE_BLOCKED => 'admin/userManagement.status_' . User::STATE_BLOCKED,
User::STATE_ACTIVE => 'admin/userManagement.status_' . User::STATE_ACTIVE
];
foreach ($items as $state => $translation) {
self::push($state, $translation);
}
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\Widgets\WidgetType;
class WidgetTypes extends BaseEnumeration
{
/**
* Init list of all installed modules
*
* @throws Exceptions\EnumerationExistsException
*/
protected static function init()
{
$widgets = WidgetType::all(['id', 'name']);
foreach ($widgets as $widget) {
self::push($widget->id, $widget->name);
}
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\CMS\Enumerations;
use App\Models\Widgets\WidgetType;
class WidgetTypesWithHandlers extends BaseEnumeration
{
/**
* Init list of all installed modules
*
* @throws Exceptions\EnumerationExistsException
*/
protected static function init()
{
$modules = WidgetType::all(['handler', 'name']);
foreach ($modules as $module) {
self::push($module->handler, $module->name);
}
}
}