Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
+51
-42
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Member;
|
||||
|
||||
/* 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;
|
||||
@@ -87,41 +87,34 @@ class _Group extends \IPS\Patterns\ActiveRecord
|
||||
);
|
||||
|
||||
/**
|
||||
* Load Record
|
||||
*
|
||||
* @see \IPS\Db::build
|
||||
* @param int|string $id ID
|
||||
* @param string $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details)
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \OutOfRangeException
|
||||
* @brief [ActiveRecord] Attempt to load from cache
|
||||
* @note If this is set to TRUE you MUST define a getStore() method to return the objects from cache
|
||||
*/
|
||||
public static function load( $id, $idField=NULL, $extraWhereClause=NULL )
|
||||
protected static $loadFromCache = TRUE;
|
||||
|
||||
/**
|
||||
* Group datastore
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
protected static function groupStore()
|
||||
{
|
||||
if ( ( $idField === NULL or $idField === 'g_id' ) and $extraWhereClause === NULL )
|
||||
{
|
||||
$groups = static::groupStore();
|
||||
if ( isset( $groups[ $id ] ) )
|
||||
{
|
||||
return parent::constructFromData( $groups[ $id ] );
|
||||
}
|
||||
}
|
||||
|
||||
return parent::load( $id, $idField, $extraWhereClause );
|
||||
return static::getStore();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Group datastore
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function groupStore()
|
||||
public static function getStore()
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->groups ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->groups = iterator_to_array( \IPS\Db::i()->select( 'core_groups.*', 'core_groups', NULL, 'core_sys_lang_words.word_custom' )->join( 'core_sys_lang_words', array( "lang_id=? AND word_app=? AND word_key=CONCAT( 'core_group_', core_groups.g_id )", \IPS\Member::loggedIn()->language()->id, 'core' ) )->setKeyField( 'g_id' ) );
|
||||
\IPS\Data\Store::i()->groups = iterator_to_array( \IPS\Db::i()->select( '*', 'core_groups' )->setKeyField( 'g_id' ) );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->groups;
|
||||
}
|
||||
|
||||
@@ -135,14 +128,14 @@ class _Group extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @param bool $showAdminGroups Show admin groups. Used to restrict admin groups from being available when you cannot add/edit members in them.
|
||||
* @param bool $showGuestGroups Show guest groups. Used to remove the guest group from the available groups returned.
|
||||
* @param bool $hideGroups If the group is set not to not be available to filter by, should we hide them?
|
||||
* @param bool $hideForFiltering If the group is set not to not be available to filter by, should we hide them?
|
||||
* @return array
|
||||
*/
|
||||
public static function groups( $showAdminGroups=TRUE, $showGuestGroups=TRUE, $hideForFiltering=FALSE )
|
||||
{
|
||||
if ( !static::$allGroups )
|
||||
{
|
||||
static::$allGroups = iterator_to_array( new \IPS\Patterns\ActiveRecordIterator( new \ArrayIterator( static::groupStore() ), 'IPS\Member\Group' ) );
|
||||
static::$allGroups = iterator_to_array( new \IPS\Patterns\ActiveRecordIterator( new \ArrayIterator( static::getStore() ), 'IPS\Member\Group' ) );
|
||||
}
|
||||
$groups = static::$allGroups;
|
||||
|
||||
@@ -174,6 +167,30 @@ class _Group extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
}
|
||||
|
||||
/* If we have a dispatcher instance, sort the groups alphabetically */
|
||||
if( \IPS\Dispatcher::hasInstance() )
|
||||
{
|
||||
/* Get all of the group names in one query */
|
||||
$sortedGroupIds = array();
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( 'word_key LIKE ? AND lang_id=?', 'core_group_%', \IPS\Member::loggedIn()->language()->id ), 'word_custom ASC' ) as $lang )
|
||||
{
|
||||
$sortedGroupIds[] = \str_replace( 'core_group_', '', $lang['word_key'] );
|
||||
}
|
||||
|
||||
$finalGroups = array();
|
||||
|
||||
foreach( $sortedGroupIds as $groupId )
|
||||
{
|
||||
if( isset( $groups[ $groupId ] ) )
|
||||
{
|
||||
$finalGroups[ $groupId ] = $groups[ $groupId ];
|
||||
}
|
||||
}
|
||||
|
||||
$groups = $finalGroups;
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
@@ -201,7 +218,7 @@ class _Group extends \IPS\Patterns\ActiveRecord
|
||||
foreach( $perms as $key )
|
||||
{
|
||||
$groups = explode( ",", $index[$key] );
|
||||
if( in_array( $oldId, $groups ) and !in_array( $this->g_id, $groups ) )
|
||||
if( \in_array( $oldId, $groups ) and !\in_array( $this->g_id, $groups ) )
|
||||
{
|
||||
$groups[] = $this->g_id;
|
||||
}
|
||||
@@ -295,6 +312,7 @@ class _Group extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Format Name
|
||||
*
|
||||
* @param string $name The name to format
|
||||
* @return string
|
||||
*/
|
||||
public function formatName( $name )
|
||||
@@ -312,18 +330,13 @@ class _Group extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
return $module->can( 'view', $this );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
function save()
|
||||
{
|
||||
parent::save();
|
||||
unset( \IPS\Data\Store::i()->groups );
|
||||
}
|
||||
|
||||
protected $caches = array( 'groups', 'moderators', 'administrators' );
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
*
|
||||
@@ -331,7 +344,7 @@ class _Group extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
if ( in_array( $this->g_id, array( \IPS\Settings::i()->guest_group, \IPS\Settings::i()->member_group, \IPS\Settings::i()->admin_group ) ) )
|
||||
if ( \in_array( $this->g_id, array( \IPS\Settings::i()->guest_group, \IPS\Settings::i()->member_group, \IPS\Settings::i()->admin_group ) ) )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
@@ -366,10 +379,6 @@ class _Group extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
parent::delete();
|
||||
\IPS\Lang::deleteCustom( 'core', 'core_group_' . $this->g_id );
|
||||
|
||||
unset( \IPS\Data\Store::i()->groups );
|
||||
unset( \IPS\Data\Store::i()->moderators );
|
||||
unset( \IPS\Data\Store::i()->administrators );
|
||||
|
||||
/* Update Core Leaders */
|
||||
\IPS\core\StaffDirectory\User::updateEmptySetting();
|
||||
|
||||
Reference in new issue
Block a user