Merge branch 'enumerations' into custom_fields
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
|
||||
use App\Enumerations\Exceptions\EnumerationExistsException;
|
||||
|
||||
abstract class BaseEnumeration
|
||||
{
|
||||
public static $items = [];
|
||||
|
||||
/**
|
||||
* 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 && isset(self::$items[$key])) {
|
||||
throw new EnumerationExistsException($key);
|
||||
}
|
||||
|
||||
// add to collection
|
||||
self::$items[$key] = $translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return count of all items in collection
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getCount()
|
||||
{
|
||||
return count(self::$items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getWithTranslations()
|
||||
{
|
||||
return self::$items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for list of all enumeration items.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSimple()
|
||||
{
|
||||
return array_keys(self::getWithTranslations());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
|
||||
use App\Models\CustomFieldType;
|
||||
|
||||
class CustomFieldTypes extends BaseEnumeration {
|
||||
public static function getWithTranslations() {
|
||||
|
||||
// load items from database
|
||||
$types = CustomFieldType::all(['id', 'name']);
|
||||
|
||||
// push items into collection
|
||||
foreach ($types as $type) {
|
||||
self::push($type->id, $type->name);
|
||||
}
|
||||
|
||||
return parent::getWithTranslations();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace App\Enumerations\Exceptions;
|
||||
|
||||
class EnumerationExistsException extends \Exception {
|
||||
|
||||
}
|
||||
@@ -3,33 +3,11 @@ namespace App\Enumerations;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserRoles
|
||||
class UserRoles extends BaseEnumeration
|
||||
{
|
||||
/**
|
||||
* Getter for roles
|
||||
*
|
||||
* This method returns only list of roles as inserted into database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSimple()
|
||||
{
|
||||
return array_values(self::getWithTranslations());
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for roles with translations
|
||||
*
|
||||
* This method returns all user roles as keys. Values are strings used for translations.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getWithTranslations()
|
||||
{
|
||||
return [
|
||||
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
|
||||
];
|
||||
}
|
||||
public static $items = [
|
||||
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
|
||||
];
|
||||
}
|
||||
@@ -10,33 +10,11 @@ namespace App\Enumerations;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserStates
|
||||
class UserStates extends BaseEnumeration
|
||||
{
|
||||
/**
|
||||
* Getter for states
|
||||
*
|
||||
* This method returns only list of roles as inserted into database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSimple()
|
||||
{
|
||||
return array_values(self::getWithTranslations());
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for states with translations
|
||||
*
|
||||
* This method returns all user states as keys. Values are strings used for translations.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getWithTranslations()
|
||||
{
|
||||
return [
|
||||
User::STATE_DELETED => 'admin/userManagement.status_' . User::STATE_DELETED,
|
||||
User::STATE_BLOCKED => 'admin/userManagement.status_' . User::STATE_BLOCKED,
|
||||
User::STATE_ACTIVE => 'admin/userManagement.status_' . User::STATE_ACTIVE
|
||||
];
|
||||
}
|
||||
public static $items = [
|
||||
User::STATE_DELETED => 'admin/userManagement.status_' . User::STATE_DELETED,
|
||||
User::STATE_BLOCKED => 'admin/userManagement.status_' . User::STATE_BLOCKED,
|
||||
User::STATE_ACTIVE => 'admin/userManagement.status_' . User::STATE_ACTIVE
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user