Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,66 +12,87 @@
|
||||
namespace IPS\nexus\Package;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use IPS\Db;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Stack;
|
||||
use IPS\Helpers\Form\Translatable;
|
||||
use IPS\Helpers\Form\Upload;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Request;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function get_called_class;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Package Group
|
||||
*/
|
||||
class _Group extends \IPS\Node\Model
|
||||
class Group extends Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_package_groups';
|
||||
public static ?string $databaseTable = 'nexus_package_groups';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'pg_';
|
||||
public static string $databasePrefix = 'pg_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent ID Database Column
|
||||
*/
|
||||
public static $databaseColumnParent = 'parent';
|
||||
public static ?string $databaseColumnParent = 'parent';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
public static ?string $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'product_groups';
|
||||
public static string $nodeTitle = 'product_groups';
|
||||
|
||||
/**
|
||||
* @brief [Node] Subnode class
|
||||
*/
|
||||
public static $subnodeClass = 'IPS\nexus\Package';
|
||||
public static ?string $subnodeClass = 'IPS\nexus\Package';
|
||||
|
||||
/**
|
||||
* @brief Content Item Class
|
||||
*/
|
||||
public static $contentItemClass = 'IPS\nexus\Package\Item';
|
||||
public static ?string $contentItemClass = 'IPS\nexus\Package\Item';
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'nexus_pgroup_';
|
||||
public static ?string $titleLangPrefix = 'nexus_pgroup_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Description suffix. If specified, will look for a language key with "{$titleLangPrefix}_{$id}_{$descriptionLangSuffix}" as the key
|
||||
*/
|
||||
public static $descriptionLangSuffix = '_desc';
|
||||
public static ?string $descriptionLangSuffix = '_desc';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
@@ -89,7 +110,7 @@ class _Group extends \IPS\Node\Model
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
protected static ?array $restrictions = array(
|
||||
'app' => 'nexus',
|
||||
'module' => 'store',
|
||||
'prefix' => 'packages_',
|
||||
@@ -99,17 +120,17 @@ class _Group extends \IPS\Node\Model
|
||||
* Return only the root groups that have packages OR subcategories/groups
|
||||
*
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param mixed $where Additional WHERE clause
|
||||
* @param Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param array $where Additional WHERE clause
|
||||
* @return array
|
||||
*/
|
||||
public static function rootsWithViewablePackages( $permissionCheck='view', $member=NULL, $where=array() )
|
||||
public static function rootsWithViewablePackages( ?string $permissionCheck='view', ?Member $member=NULL, array $where=array() ) : array
|
||||
{
|
||||
$roots = static::roots( $permissionCheck, $member, $where );
|
||||
|
||||
foreach( $roots as $index => $group )
|
||||
{
|
||||
if( !$group->hasSubgroups() AND !$group->hasPackages( NULL, array( array( "p_store=1 AND ( p_member_groups='*' OR " . \IPS\Db::i()->findInSet( 'p_member_groups', \IPS\Member::loggedIn()->groups ) . ' )' ) ) ) )
|
||||
if( !$group->hasSubgroups() AND !$group->hasPackages( NULL, array( array( "p_store=1 AND ( p_member_groups='*' OR " . Db::i()->findInSet( 'p_member_groups', Member::loggedIn()->groups ) . ' )' ) ) ) )
|
||||
{
|
||||
unset( $roots[ $index ] );
|
||||
}
|
||||
@@ -121,12 +142,12 @@ class _Group extends \IPS\Node\Model
|
||||
/**
|
||||
* Load record based on a URL
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL to load from
|
||||
* @param Url $url URL to load from
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \OutOfRangeException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws OutOfRangeException
|
||||
*/
|
||||
public static function loadFromUrl( \IPS\Http\Url $url )
|
||||
public static function loadFromUrl( Url $url ): static
|
||||
{
|
||||
$qs = array_merge( $url->queryString, $url->hiddenQueryString );
|
||||
|
||||
@@ -135,20 +156,20 @@ class _Group extends \IPS\Node\Model
|
||||
return static::load( $qs['cat'] );
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException;
|
||||
throw new InvalidArgumentException;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @param Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
public function form( Form &$form ) : void
|
||||
{
|
||||
$form->addHeader('pg_basic_settings');
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'pg_name', NULL, TRUE, array( 'app' => 'nexus', 'key' => $this->id ? "nexus_pgroup_{$this->id}" : NULL ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'pg_desc', NULL, FALSE, array(
|
||||
$form->add( new Translatable( 'pg_name', NULL, TRUE, array( 'app' => 'nexus', 'key' => $this->id ? "nexus_pgroup_{$this->id}" : NULL ) ) );
|
||||
$form->add( new Translatable( 'pg_desc', NULL, FALSE, array(
|
||||
'app' => 'nexus',
|
||||
'key' => ( $this->id ? "nexus_pgroup_{$this->id}_desc" : NULL ),
|
||||
'editor' => array(
|
||||
@@ -159,18 +180,18 @@ class _Group extends \IPS\Node\Model
|
||||
)
|
||||
) ) );
|
||||
|
||||
$class = \get_called_class();
|
||||
$class = get_called_class();
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'pg_parent', $this->id ? $this->parent : 0, TRUE, array( 'class' => 'IPS\nexus\Package\Group', 'subnodes' => FALSE, 'zeroVal' => 'no_parent', 'permissionCheck' => function( $node ) use ( $class )
|
||||
$form->add( new Node( 'pg_parent', $this->id ? $this->parent : 0, TRUE, array( 'class' => 'IPS\nexus\Package\Group', 'subnodes' => FALSE, 'zeroVal' => 'no_parent', 'permissionCheck' => function( $node ) use ( $class )
|
||||
{
|
||||
if( isset( $class::$subnodeClass ) AND $class::$subnodeClass AND $node instanceof $class::$subnodeClass )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return !isset( \IPS\Request::i()->id ) or ( $node->id != \IPS\Request::i()->id and !$node->isChildOf( $node::load( \IPS\Request::i()->id ) ) );
|
||||
return !isset( Request::i()->id ) or ( $node->id != Request::i()->id and !$node->isChildOf( $node::load( Request::i()->id ) ) );
|
||||
} ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'pg_image', $this->image ? \IPS\File::get( 'nexus_PackageGroups', $this->image ) : NULL, FALSE, array( 'storageExtension' => 'nexus_PackageGroups', 'image' => TRUE, 'allowStockPhotos' => TRUE ) ) );
|
||||
$form->add( new Upload( 'pg_image', $this->image ? File::get( 'nexus_PackageGroups', $this->image ) : NULL, FALSE, array( 'storageExtension' => 'nexus_PackageGroups', 'image' => TRUE, 'allowStockPhotos' => TRUE ) ) );
|
||||
|
||||
$priceFilters = array();
|
||||
if ( $this->price_filters )
|
||||
@@ -185,8 +206,8 @@ class _Group extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
$form->addHeader('pg_filters_header');
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'pg_filters', explode( ',', $this->filters ), FALSE, array( 'class' => 'IPS\nexus\Package\Filter', 'multiple' => TRUE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'pg_price_filters', $priceFilters, FALSE, array( 'stackFieldType' => 'IPS\nexus\Form\Money' ) ) );
|
||||
$form->add( new Node( 'pg_filters', $this->filters ? explode( ',', $this->filters ) : [], FALSE, array( 'class' => 'IPS\nexus\Package\Filter', 'multiple' => TRUE ) ) );
|
||||
$form->add( new Stack( 'pg_price_filters', $priceFilters, FALSE, array( 'stackFieldType' => 'IPS\nexus\Form\Money' ) ) );
|
||||
|
||||
}
|
||||
|
||||
@@ -196,7 +217,7 @@ class _Group extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
if( isset( $values['pg_parent'] ) )
|
||||
{
|
||||
@@ -211,7 +232,7 @@ class _Group extends \IPS\Node\Model
|
||||
if ( !$this->id )
|
||||
{
|
||||
$this->save();
|
||||
\IPS\File::claimAttachments( 'nexus-new-group', $this->id, NULL, 'pgroup', TRUE );
|
||||
File::claimAttachments( 'nexus-new-group', $this->id, NULL, 'pgroup', TRUE );
|
||||
}
|
||||
elseif( isset( $values['pg_name'] ) OR isset( $values['pg_desc'] ) )
|
||||
{
|
||||
@@ -220,13 +241,13 @@ class _Group extends \IPS\Node\Model
|
||||
|
||||
if( isset( $values['pg_name'] ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'nexus', "nexus_pgroup_{$this->id}", $values['pg_name'] );
|
||||
Lang::saveCustom( 'nexus', "nexus_pgroup_{$this->id}", $values['pg_name'] );
|
||||
unset( $values['pg_name'] );
|
||||
}
|
||||
|
||||
if( isset( $values['pg_desc'] ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'nexus', "nexus_pgroup_{$this->id}_desc", $values['pg_desc'] );
|
||||
Lang::saveCustom( 'nexus', "nexus_pgroup_{$this->id}_desc", $values['pg_desc'] );
|
||||
unset( $values['pg_desc'] );
|
||||
}
|
||||
|
||||
@@ -240,7 +261,7 @@ class _Group extends \IPS\Node\Model
|
||||
$priceFilters[ $currency ][] = $amount->amount->jsonSerialize();
|
||||
}
|
||||
}
|
||||
$values['pg_price_filters'] = \count( $priceFilters ) ? json_encode( $priceFilters ) : NULL;
|
||||
$values['pg_price_filters'] = count( $priceFilters ) ? json_encode( $priceFilters ) : NULL;
|
||||
|
||||
return $values;
|
||||
}
|
||||
@@ -248,18 +269,18 @@ class _Group extends \IPS\Node\Model
|
||||
/**
|
||||
* @brief Cached URL
|
||||
*/
|
||||
protected $_url = NULL;
|
||||
protected mixed $_url = NULL;
|
||||
|
||||
/**
|
||||
* Get URL
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
* @return Url\Internal|string|null
|
||||
*/
|
||||
public function url()
|
||||
public function url(): Url\Internal|string|null
|
||||
{
|
||||
if( $this->_url === NULL )
|
||||
{
|
||||
$this->_url = \IPS\Http\Url::internal( "app=nexus&module=store&controller=store&cat={$this->id}", 'front', 'store_group', \IPS\Http\Url\Friendly::seoTitle( \IPS\Member::loggedIn()->language()->get( 'nexus_pgroup_' . $this->id ) ) );
|
||||
$this->_url = Url::internal( "app=nexus&module=store&controller=store&cat={$this->id}", 'front', 'store_group', Friendly::seoTitle( Member::loggedIn()->language()->get( 'nexus_pgroup_' . $this->id ) ) );
|
||||
}
|
||||
|
||||
return $this->_url;
|
||||
@@ -271,30 +292,30 @@ class _Group extends \IPS\Node\Model
|
||||
* @param array $indexData Data from the search index
|
||||
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
|
||||
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
|
||||
* @return \IPS\Http\Url
|
||||
* @return Url
|
||||
*/
|
||||
public static function urlFromIndexData( $indexData, $itemData, $containerData )
|
||||
public static function urlFromIndexData( array $indexData, array $itemData, ?array $containerData ): Url
|
||||
{
|
||||
return \IPS\Http\Url::internal( "app=nexus&module=store&controller=store&cat={$indexData['index_container_id']}", 'front', 'store_group', \IPS\Member::loggedIn()->language()->addToStack( 'nexus_pgroup_' . $indexData['index_container_id'], FALSE, array( 'seotitle' => TRUE ) ) );
|
||||
return Url::internal( "app=nexus&module=store&controller=store&cat={$indexData['index_container_id']}", 'front', 'store_group', Member::loggedIn()->language()->addToStack( 'nexus_pgroup_' . $indexData['index_container_id'], FALSE, array( 'seotitle' => TRUE ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get full image URL
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_image()
|
||||
public function get_image() : string|null
|
||||
{
|
||||
return ( isset( $this->_data['image'] ) ) ? (string) \IPS\File::get( 'nexus_PackageGroups', $this->_data['image'] )->url : NULL;
|
||||
return ( isset( $this->_data['image'] ) ) ? (string) File::get( 'nexus_PackageGroups', $this->_data['image'] )->url : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this group have subgroups?
|
||||
*
|
||||
* @param mixed $_where Additional WHERE clause
|
||||
* @param array $_where Additional WHERE clause
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSubgroups( $_where=array() )
|
||||
public function hasSubgroups( array $_where=array() ) : bool
|
||||
{
|
||||
return ( $this->childrenCount( NULL, NULL, FALSE, $_where ) > 0 );
|
||||
}
|
||||
@@ -302,18 +323,18 @@ class _Group extends \IPS\Node\Model
|
||||
/**
|
||||
* Does this group have packages?
|
||||
*
|
||||
* @param \IPS\Member|NULL|FALSE $member The member to perform the permission check for, or NULL for currently logged in member, or FALSE for no permission check
|
||||
* @param mixed $_where Additional WHERE clause
|
||||
* @param Member|NULL|FALSE $member The member to perform the permission check for, or NULL for currently logged in member, or FALSE for no permission check
|
||||
* @param array $_where Additional WHERE clause
|
||||
* @param bool $viewableOnly Only check packages the member can view
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPackages( $member=NULL, $_where=array(), $viewableOnly=FALSE )
|
||||
public function hasPackages( Member|null|bool $member=NULL, array $_where=array(), bool $viewableOnly=FALSE ) : bool
|
||||
{
|
||||
if( $viewableOnly === TRUE )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
$_where[] = array( "p_store=1 AND ( p_member_groups='*' OR " . \IPS\Db::i()->findInSet( 'p_member_groups', $member->groups ) . ' )' );
|
||||
$_where[] = array( "p_store=1 AND ( p_member_groups='*' OR " . Db::i()->findInSet( 'p_member_groups', $member->groups ) . ' )' );
|
||||
}
|
||||
|
||||
return ( $this->childrenCount( $member === FALSE ? FALSE : 'view', $member, NULL, $_where ) > 0 );
|
||||
@@ -322,21 +343,21 @@ class _Group extends \IPS\Node\Model
|
||||
/**
|
||||
* Get Filter Options
|
||||
*
|
||||
* @param \IPS\Lang $language The language to return options in
|
||||
* @param Lang $language The language to return options in
|
||||
* @return array
|
||||
*/
|
||||
public function filters( \IPS\Lang $language )
|
||||
public function filters( Lang $language ) : array
|
||||
{
|
||||
$return = array();
|
||||
|
||||
if ( $this->filters )
|
||||
{
|
||||
foreach ( \IPS\Db::i()->select( 'pfilter_id', 'nexus_package_filters', array( \IPS\Db::i()->in( 'pfilter_id', explode( ',', $this->filters ) ) ), 'pfilter_order' ) as $filterId )
|
||||
foreach ( Db::i()->select( 'pfilter_id', 'nexus_package_filters', array( Db::i()->in( 'pfilter_id', explode( ',', $this->filters ) ) ), 'pfilter_order' ) as $filterId )
|
||||
{
|
||||
$return[ $filterId ] = array();
|
||||
}
|
||||
|
||||
foreach ( \IPS\Db::i()->select( '*', 'nexus_package_filters_values', array( array( \IPS\Db::i()->in( 'pfv_filter', array_keys( $return ) ) ), array( 'pfv_lang=?', $language->id ) ), 'pfv_order' ) as $value )
|
||||
foreach ( Db::i()->select( '*', 'nexus_package_filters_values', array( array( Db::i()->in( 'pfv_filter', array_keys( $return ) ) ), array( 'pfv_lang=?', $language->id ) ), 'pfv_order' ) as $value )
|
||||
{
|
||||
$return[ $value['pfv_filter'] ][ $value['pfv_value'] ] = $value['pfv_text'];
|
||||
}
|
||||
@@ -350,7 +371,7 @@ class _Group extends \IPS\Node\Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
public function __clone() : void
|
||||
{
|
||||
if ( $this->skipCloneDuplication === TRUE )
|
||||
{
|
||||
@@ -365,11 +386,11 @@ class _Group extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
$icon = \IPS\File::get( 'nexus_PackageGroups', $oldImage );
|
||||
$newIcon = \IPS\File::create( 'nexus_PackageGroups', $icon->originalFilename, $icon->contents() );
|
||||
$icon = File::get( 'nexus_PackageGroups', $oldImage );
|
||||
$newIcon = File::create( 'nexus_PackageGroups', $icon->originalFilename, $icon->contents() );
|
||||
$this->image = (string) $newIcon;
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception )
|
||||
{
|
||||
$this->pg_image = NULL;
|
||||
}
|
||||
@@ -383,7 +404,7 @@ class _Group extends \IPS\Node\Model
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteOrMoveQueued()
|
||||
public function deleteOrMoveQueued(): bool
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -393,21 +414,21 @@ class _Group extends \IPS\Node\Model
|
||||
* Example code explains return value
|
||||
*
|
||||
* @code
|
||||
array(
|
||||
array(
|
||||
'icon' => 'plus-circle', // Name of FontAwesome icon to use
|
||||
'title' => 'foo', // Language key to use for button's title parameter
|
||||
'link' => \IPS\Http\Url::internal( 'app=foo...' ) // URI to link to
|
||||
'class' => 'modalLink' // CSS Class to use on link (Optional)
|
||||
),
|
||||
... // Additional buttons
|
||||
);
|
||||
* array(
|
||||
* array(
|
||||
* 'icon' => 'plus-circle', // Name of FontAwesome icon to use
|
||||
* 'title' => 'foo', // Language key to use for button's title parameter
|
||||
* 'link' => \IPS\Http\Url::internal( 'app=foo...' ) // URI to link to
|
||||
* 'class' => 'modalLink' // CSS Class to use on link (Optional)
|
||||
* ),
|
||||
* ... // Additional buttons
|
||||
* );
|
||||
* @endcode
|
||||
* @param string $url Base URL
|
||||
* @param Url $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
*/
|
||||
public function getButtons( $url, $subnode=FALSE )
|
||||
public function getButtons( Url $url, bool $subnode=FALSE ):array
|
||||
{
|
||||
$buttons = parent::getButtons( $url, $subnode );
|
||||
|
||||
|
||||
Reference in new issue
Block a user