Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+139 -8
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Package;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -57,6 +57,11 @@ class _Group extends \IPS\Node\Model
* @brief [Node] Subnode class
*/
public static $subnodeClass = 'IPS\nexus\Package';
/**
* @brief Content Item Class
*/
public static $contentItemClass = 'IPS\nexus\Package\Item';
/**
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
@@ -89,6 +94,29 @@ class _Group extends \IPS\Node\Model
'module' => 'store',
'prefix' => 'packages_',
);
/**
* 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
* @return array
*/
public static function rootsWithViewablePackages( $permissionCheck='view', $member=NULL, $where=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 ) . ' )' ) ) ) )
{
unset( $roots[ $index ] );
}
}
return $roots;
}
/**
* Load record based on a URL
@@ -117,7 +145,8 @@ class _Group extends \IPS\Node\Model
* @return void
*/
public function form( &$form )
{
{
$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(
'app' => 'nexus',
@@ -130,7 +159,7 @@ 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 )
{
@@ -141,7 +170,24 @@ class _Group extends \IPS\Node\Model
return !isset( \IPS\Request::i()->id ) or ( $node->id != \IPS\Request::i()->id and !$node->isChildOf( $node::load( \IPS\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 ) ) );
$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 ) ) );
$priceFilters = array();
if ( $this->price_filters )
{
foreach ( json_decode( $this->price_filters, TRUE ) as $currency => $prices )
{
foreach ( $prices as $i => $price )
{
$priceFilters[ $i ][ $currency ] = $price;
}
}
}
$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' ) ) );
}
/**
@@ -151,7 +197,7 @@ class _Group extends \IPS\Node\Model
* @return array
*/
public function formatFormValues( $values )
{
{
if( isset( $values['pg_parent'] ) )
{
$values['parent'] = $values['pg_parent'] ? $values['pg_parent']->id : 0;
@@ -183,6 +229,18 @@ class _Group extends \IPS\Node\Model
\IPS\Lang::saveCustom( 'nexus', "nexus_pgroup_{$this->id}_desc", $values['pg_desc'] );
unset( $values['pg_desc'] );
}
$values['pg_filters'] = $values['pg_filters'] ? implode( ',', array_keys( $values['pg_filters'] ) ) : NULL;
$priceFilters = array();
foreach ( $values['pg_price_filters'] as $filter )
{
foreach ( $filter as $currency => $amount )
{
$priceFilters[ $currency ][] = $amount->amount->jsonSerialize();
}
}
$values['pg_price_filters'] = \count( $priceFilters ) ? json_encode( $priceFilters ) : NULL;
return $values;
}
@@ -245,13 +303,47 @@ 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 mixed $_where Additional WHERE clause
* @param bool $viewableOnly Only check packages the member can view
* @return bool
*/
public function hasPackages( $member=NULL, $_where=array() )
public function hasPackages( $member=NULL, $_where=array(), $viewableOnly=FALSE )
{
if( $viewableOnly === TRUE )
{
$member = $member ?: \IPS\Member::loggedIn();
$_where[] = array( "p_store=1 AND ( p_member_groups='*' OR " . \IPS\Db::i()->findInSet( 'p_member_groups', $member->groups ) . ' )' );
}
return ( $this->childrenCount( $member === FALSE ? FALSE : 'view', $member, NULL, $_where ) > 0 );
}
/**
* Get Filter Options
*
* @param \IPS\Lang $language The language to return options in
* @return array
*/
public function filters( \IPS\Lang $language )
{
$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 )
{
$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 )
{
$return[ $value['pfv_filter'] ][ $value['pfv_value'] ] = $value['pfv_text'];
}
}
return $return;
}
/**
* [ActiveRecord] Duplicate
@@ -285,6 +377,45 @@ class _Group extends \IPS\Node\Model
$this->save();
}
}
/**
* Is this node currently queued for deleting or moving content?
*
* @return bool
*/
public function deleteOrMoveQueued()
{
return FALSE;
}
/**
* [Node] Get buttons to display in tree
* 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
);
* @endcode
* @param string $url Base URL
* @param bool $subnode Is this a subnode?
* @return array
*/
public function getButtons( $url, $subnode=FALSE )
{
$buttons = parent::getButtons( $url, $subnode );
}
if( isset( $buttons['content'] ) )
{
$buttons['content']['title'] = 'mass_manage_productgroups';
}
return $buttons;
}
}