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
@@ -11,30 +11,70 @@
|
||||
namespace IPS\core\modules\admin\clubs;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Table\Db as TableDb;
|
||||
use IPS\Helpers\Tree\Tree;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Club;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
|
||||
use const IPS\Helpers\Table\SEARCH_MEMBER;
|
||||
use const IPS\Helpers\Table\SEARCH_NUMERIC;
|
||||
use const IPS\Helpers\Table\SEARCH_QUERY_TEXT;
|
||||
use const IPS\Helpers\Table\SEARCH_SELECT;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clubs
|
||||
*/
|
||||
class _clubs extends \IPS\Dispatcher\Controller
|
||||
class clubs extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected ?string $nodeClass = null;
|
||||
|
||||
/**
|
||||
* @var Club|null
|
||||
*/
|
||||
protected ?Club $club = null;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'clubs_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -43,37 +83,37 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_clubs_clubs');
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__core_clubs_clubs');
|
||||
|
||||
if ( \IPS\Settings::i()->clubs )
|
||||
if ( Settings::i()->clubs )
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_clubs', \IPS\Http\Url::internal( 'app=core&module=clubs&controller=clubs' ) );
|
||||
$table = new TableDb( 'core_clubs', Url::internal( 'app=core&module=clubs&controller=clubs' ) );
|
||||
$table->include = array( 'name', 'type', 'members', 'owner', 'created' );
|
||||
$table->langPrefix = 'club_';
|
||||
$table->parsers = array(
|
||||
'name' => function( $value, $row )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('clubs')->name( $value, $row );
|
||||
return Theme::i()->getTemplate('clubs')->name( $value, $row );
|
||||
},
|
||||
'type' => function( $value ) {
|
||||
return \IPS\Theme::i()->getTemplate('clubs')->privacy( $value );
|
||||
return Theme::i()->getTemplate('clubs')->privacy( $value );
|
||||
},
|
||||
'created' => function( $value ) {
|
||||
return \IPS\DateTime::ts( $value );
|
||||
return DateTime::ts( $value );
|
||||
},
|
||||
'members' => function( $value, $row ) {
|
||||
if ( $row['type'] !== \IPS\Member\Club::TYPE_PUBLIC )
|
||||
if ( $row['type'] !== Club::TYPE_PUBLIC )
|
||||
{
|
||||
$link = \IPS\Http\Url::internal( "app=core&module=clubs&controller=view&id={$row['id']}&do=members", 'front', 'clubs_view', array( \IPS\Http\Url\Friendly::seoTitle( $row['name'] ) ) );
|
||||
return \IPS\Theme::i()->getTemplate('clubs')->members( $value, $link );
|
||||
$link = Url::internal( "app=core&module=clubs&controller=view&id={$row['id']}&do=members", 'front', 'clubs_view', array( Friendly::seoTitle( $row['name'] ) ) );
|
||||
return Theme::i()->getTemplate('clubs')->members( $value, $link );
|
||||
}
|
||||
return '';
|
||||
},
|
||||
'owner' => function( $value ) {
|
||||
return \IPS\Theme::i()->getTemplate('clubs')->owner( \IPS\Member::load( $value ) );
|
||||
return Theme::i()->getTemplate('clubs')->owner( Member::load( $value ) );
|
||||
},
|
||||
'_highlight' => function( $row ) {
|
||||
if ( !$row['approved'] )
|
||||
@@ -87,96 +127,96 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
$table->sortBy = $table->sortBy ?: 'members';
|
||||
$table->quickSearch = 'name';
|
||||
$table->advancedSearch = array(
|
||||
'name' => \IPS\Helpers\Table\SEARCH_QUERY_TEXT,
|
||||
'members' => \IPS\Helpers\Table\SEARCH_NUMERIC,
|
||||
'owner' => \IPS\Helpers\Table\SEARCH_MEMBER,
|
||||
'created' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
'name' => SEARCH_QUERY_TEXT,
|
||||
'members' => SEARCH_NUMERIC,
|
||||
'owner' => SEARCH_MEMBER,
|
||||
'created' => SEARCH_DATE_RANGE,
|
||||
);
|
||||
if ( \IPS\Settings::i()->clubs_require_approval )
|
||||
if ( Settings::i()->clubs_require_approval )
|
||||
{
|
||||
$table->filters = array(
|
||||
'pending_approval' => 'approved=0'
|
||||
);
|
||||
$table->advancedSearch['type'] = array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => array(
|
||||
\IPS\Member\Club::TYPE_PUBLIC => 'club_type_' . \IPS\Member\Club::TYPE_PUBLIC,
|
||||
\IPS\Member\Club::TYPE_OPEN => 'club_type_' . \IPS\Member\Club::TYPE_OPEN,
|
||||
\IPS\Member\Club::TYPE_CLOSED => 'club_type_' . \IPS\Member\Club::TYPE_CLOSED,
|
||||
\IPS\Member\Club::TYPE_PRIVATE => 'club_type_' . \IPS\Member\Club::TYPE_PRIVATE,
|
||||
\IPS\Member\Club::TYPE_READONLY => 'club_type_' . \IPS\Member\Club::TYPE_READONLY,
|
||||
$table->advancedSearch['type'] = array( SEARCH_SELECT, array( 'options' => array(
|
||||
Club::TYPE_PUBLIC => 'club_type_' . Club::TYPE_PUBLIC,
|
||||
Club::TYPE_OPEN => 'club_type_' . Club::TYPE_OPEN,
|
||||
Club::TYPE_CLOSED => 'club_type_' . Club::TYPE_CLOSED,
|
||||
Club::TYPE_PRIVATE => 'club_type_' . Club::TYPE_PRIVATE,
|
||||
Club::TYPE_READONLY => 'club_type_' . Club::TYPE_READONLY,
|
||||
), 'multiple' => TRUE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$table->filters = array(
|
||||
'club_type_' . \IPS\Member\Club::TYPE_PUBLIC => array( 'type=?', \IPS\Member\Club::TYPE_PUBLIC ),
|
||||
'club_type_' . \IPS\Member\Club::TYPE_OPEN => array( 'type=?', \IPS\Member\Club::TYPE_OPEN ),
|
||||
'club_type_' . \IPS\Member\Club::TYPE_CLOSED => array( 'type=?', \IPS\Member\Club::TYPE_CLOSED ),
|
||||
'club_type_' . \IPS\Member\Club::TYPE_PRIVATE => array( 'type=?', \IPS\Member\Club::TYPE_PRIVATE ),
|
||||
'club_type_' . \IPS\Member\Club::TYPE_READONLY => array( 'type=?', \IPS\Member\Club::TYPE_READONLY )
|
||||
'club_type_' . Club::TYPE_PUBLIC => array( 'type=?', Club::TYPE_PUBLIC ),
|
||||
'club_type_' . Club::TYPE_OPEN => array( 'type=?', Club::TYPE_OPEN ),
|
||||
'club_type_' . Club::TYPE_CLOSED => array( 'type=?', Club::TYPE_CLOSED ),
|
||||
'club_type_' . Club::TYPE_PRIVATE => array( 'type=?', Club::TYPE_PRIVATE ),
|
||||
'club_type_' . Club::TYPE_READONLY => array( 'type=?', Club::TYPE_READONLY )
|
||||
);
|
||||
}
|
||||
$table->rowButtons = function( $row ) {
|
||||
$return = array();
|
||||
if ( !$row['approved'] )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_edit' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_edit' ) )
|
||||
{
|
||||
$return['approve'] = array(
|
||||
'title' => 'approve',
|
||||
'icon' => 'check',
|
||||
'link' => \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs&do=approve&id={$row['id']}")->csrf()
|
||||
'link' => Url::internal("app=core&module=clubs&controller=clubs&do=approve&id={$row['id']}")->csrf()
|
||||
);
|
||||
}
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_delete' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_delete' ) )
|
||||
{
|
||||
$return['delete'] = array(
|
||||
'title' => 'delete',
|
||||
'icon' => 'times',
|
||||
'link' => \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs&do=delete&id={$row['id']}"),
|
||||
'data' => \IPS\Db::i()->select( 'COUNT(*)', 'core_clubs_node_map', array( 'club_id=?', $row['id'] ) )->first() ? array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('delete') ) : array( 'delete' => '' )
|
||||
'link' => Url::internal("app=core&module=clubs&controller=clubs&do=delete&id={$row['id']}"),
|
||||
'data' => Db::i()->select( 'COUNT(*)', 'core_clubs_node_map', array( 'club_id=?', $row['id'] ) )->first() ? array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('delete') ) : array( 'delete' => '' )
|
||||
);
|
||||
}
|
||||
}
|
||||
$return['open'] = array(
|
||||
'title' => 'view',
|
||||
'icon' => 'search',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=clubs&controller=view&id={$row['id']}", 'front', 'clubs_view', array( \IPS\Http\Url\Friendly::seoTitle( $row['name'] ) ) ),
|
||||
'link' => Url::internal( "app=core&module=clubs&controller=view&id={$row['id']}", 'front', 'clubs_view', array( Friendly::seoTitle( $row['name'] ) ) ),
|
||||
'target'=> '_blank'
|
||||
);
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_edit' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_edit' ) )
|
||||
{
|
||||
$return['edit'] = array(
|
||||
'title' => 'edit',
|
||||
'icon' => 'pencil',
|
||||
'link' => \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs&do=edit&id={$row['id']}")
|
||||
'link' => Url::internal("app=core&module=clubs&controller=clubs&do=edit&id={$row['id']}")
|
||||
);
|
||||
}
|
||||
if ( !isset( $return['delete'] ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_delete' ) )
|
||||
if ( !isset( $return['delete'] ) and Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_delete' ) )
|
||||
{
|
||||
$return['delete'] = array(
|
||||
'title' => 'delete',
|
||||
'icon' => 'times-circle',
|
||||
'link' => \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs&do=delete&id={$row['id']}"),
|
||||
'data' => \IPS\Db::i()->select( 'COUNT(*)', 'core_clubs_node_map', array( 'club_id=?', $row['id'] ) )->first() ? array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('delete') ) : array( 'delete' => '' )
|
||||
'link' => Url::internal("app=core&module=clubs&controller=clubs&do=delete&id={$row['id']}"),
|
||||
'data' => Db::i()->select( 'COUNT(*)', 'core_clubs_node_map', array( 'club_id=?', $row['id'] ) )->first() ? array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('delete') ) : array( 'delete' => '' )
|
||||
);
|
||||
}
|
||||
return $return;
|
||||
};
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
Output::i()->output = (string) $table;
|
||||
}
|
||||
else
|
||||
{
|
||||
$availableTypes = array();
|
||||
foreach ( \IPS\Member\Club::availableNodeTypes( NULL ) as $class )
|
||||
foreach ( Club::availableNodeTypes( NULL ) as $class )
|
||||
{
|
||||
$availableTypes[] = \IPS\Member::loggedIn()->language()->addToStack( $class::clubAcpTitle() );
|
||||
$availableTypes[] = Member::loggedIn()->language()->addToStack( $class::clubAcpTitle() );
|
||||
}
|
||||
|
||||
$availableTypes = \IPS\Member::loggedIn()->language()->formatList( $availableTypes );
|
||||
$availableTypes = Member::loggedIn()->language()->formatList( $availableTypes );
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'clubs' )->disabled( $availableTypes );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'clubs' )->disabled( $availableTypes );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,18 +225,18 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function enable()
|
||||
protected function enable() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_settings_manage' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Dispatcher::i()->checkAcpPermission( 'clubs_settings_manage' );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
\IPS\Settings::i()->changeValues( array( 'clubs' => true ) );
|
||||
Settings::i()->changeValues( array( 'clubs' => true ) );
|
||||
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'clubrebuild' ) );
|
||||
Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'clubrebuild' ) );
|
||||
|
||||
\IPS\Session::i()->log( 'acplog__club_settings' );
|
||||
Session::i()->log( 'acplog__club_settings' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=clubs&controller=clubs') );
|
||||
Output::i()->redirect( Url::internal('app=core&module=clubs&controller=clubs') );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,28 +245,28 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
* @csrfChecked Uses node form() 7 Oct 2019
|
||||
* @return void
|
||||
*/
|
||||
protected function edit()
|
||||
protected function edit() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_edit' );
|
||||
Dispatcher::i()->checkAcpPermission( 'clubs_edit' );
|
||||
|
||||
/* Load Club */
|
||||
try
|
||||
{
|
||||
$club = \IPS\Member\Club::load( \IPS\Request::i()->id );
|
||||
$club = Club::load( Request::i()->id );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C352/1', 404, '' );
|
||||
Output::i()->error( 'node_error', '2C352/1', 404, '' );
|
||||
}
|
||||
$editUrl = \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs&do=edit&id={$club->id}");
|
||||
$editUrl = Url::internal("app=core&module=clubs&controller=clubs&do=edit&id={$club->id}");
|
||||
|
||||
/* Tabs */
|
||||
$tabs = array( 'settings' => 'settings' );
|
||||
foreach ( \IPS\Member\Club::availableNodeTypes( \IPS\Member::loggedIn() ) as $class )
|
||||
foreach ( Club::availableNodeTypes( Member::loggedIn() ) as $class )
|
||||
{
|
||||
$tabs[ str_replace( '\\', '-', preg_replace( '/^IPS\\\/', '', $class ) ) ] = $class::clubAcpTitle();
|
||||
}
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'settings';
|
||||
$activeTab = ( isset( Request::i()->tab ) and array_key_exists( Request::i()->tab, $tabs ) ) ? Request::i()->tab : 'settings';
|
||||
|
||||
/* Settings */
|
||||
if ( $activeTab === 'settings' )
|
||||
@@ -244,16 +284,16 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
|
||||
if ( !empty( $changes ) )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->decision( 'product_change_blurb', array(
|
||||
'product_change_blurb_existing' => \IPS\Http\Url::internal( "app=core&module=clubs&controller=clubs&do=updateExisting&id={$club->id}" )->setQueryString( 'changes', json_encode( $changes ) )->csrf(),
|
||||
'product_change_blurb_new' => \IPS\Http\Url::internal( "app=core&module=clubs&controller=clubs" ),
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core', 'global' )->decision( 'product_change_blurb', array(
|
||||
'product_change_blurb_existing' => Url::internal( "app=core&module=clubs&controller=clubs&do=updateExisting&id={$club->id}" )->setQueryString( 'changes', json_encode( $changes ) )->csrf(),
|
||||
'product_change_blurb_new' => Url::internal( "app=core&module=clubs&controller=clubs" ),
|
||||
) );
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs"), "saved" );
|
||||
Output::i()->redirect( Url::internal("app=core&module=clubs&controller=clubs"), "saved" );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -265,21 +305,22 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
/* Node List */
|
||||
else
|
||||
{
|
||||
$nodeClass = 'IPS\\' . str_replace( '-', '\\', \IPS\Request::i()->tab );
|
||||
$nodeClass = 'IPS\\' . str_replace( '-', '\\', Request::i()->tab );
|
||||
$this->nodeClass = $nodeClass;
|
||||
$this->club = $club;
|
||||
|
||||
$tree = new \IPS\Helpers\Tree\Tree( $editUrl->setQueryString( 'tab', \IPS\Request::i()->tab ), 'x', array( $this, '_getNodeRows' ), array( $this, '_getNodeRow' ), function() { return NULL; }, function() { return array(); }, function() use( $nodeClass ) {
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_add_nodes' ) )
|
||||
|
||||
/* @var Model $nodeClass */
|
||||
$tree = new Tree( $editUrl->setQueryString( 'tab', Request::i()->tab ), 'x', array( $this, '_getNodeRows' ), array( $this, '_getNodeRow' ), function() { return NULL; }, function() { return array(); }, function() use( $nodeClass ) {
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_add_nodes' ) )
|
||||
{
|
||||
return array(
|
||||
'create' => array(
|
||||
'title' => 'add',
|
||||
'icon' => 'plus',
|
||||
'link' => \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs&do=nodeForm&club={$this->club->id}&nodeClass={$nodeClass}" ),
|
||||
'link' => Url::internal("app=core&module=clubs&controller=clubs&do=nodeForm&club={$this->club->id}&nodeClass={$nodeClass}" ),
|
||||
'data' => array(
|
||||
'ipsDialog' => '',
|
||||
'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack( $nodeClass::clubAcpTitle() )
|
||||
'ipsDialog-title' => Member::loggedIn()->language()->addToStack( $nodeClass::clubAcpTitle() )
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -291,14 +332,14 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/* Output */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = $activeTabContents;
|
||||
Output::i()->output = $activeTabContents;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = $club->name;
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $activeTabContents, $editUrl );
|
||||
Output::i()->title = $club->name;
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $activeTabContents, $editUrl );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,19 +348,19 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function approve()
|
||||
protected function approve() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_edit' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Dispatcher::i()->checkAcpPermission( 'clubs_edit' );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* Load Club */
|
||||
try
|
||||
{
|
||||
$club = \IPS\Member\Club::load( \IPS\Request::i()->id );
|
||||
$club = Club::load( Request::i()->id );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C352/8', 404, '' );
|
||||
Output::i()->error( 'node_error', '2C352/8', 404, '' );
|
||||
}
|
||||
|
||||
/* Approve */
|
||||
@@ -329,13 +370,13 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
$club->onApprove();
|
||||
|
||||
/* Redirect */
|
||||
$target = \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs");
|
||||
if ( \IPS\Db::i()->select( 'COUNT(*)', 'core_clubs', array( 'approved=0 AND id!=?', $club->id ) )->first() )
|
||||
$target = Url::internal("app=core&module=clubs&controller=clubs");
|
||||
if ( Db::i()->select( 'COUNT(*)', 'core_clubs', array( 'approved=0 AND id!=?', $club->id ) )->first() )
|
||||
{
|
||||
$target = $target->setQueryString( 'filter', 'pending_approval' );
|
||||
}
|
||||
\IPS\Session::i()->modLog( 'acplog__club_approved', array( $club->name => FALSE ) );
|
||||
\IPS\Output::i()->redirect( $target, "approved" );
|
||||
Session::i()->modLog( 'acplog__club_approved', array( $club->name => FALSE ) );
|
||||
Output::i()->redirect( $target, "approved" );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -343,38 +384,38 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
protected function delete() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_delete' );
|
||||
Dispatcher::i()->checkAcpPermission( 'clubs_delete' );
|
||||
|
||||
/* Load Club */
|
||||
try
|
||||
{
|
||||
$club = \IPS\Member\Club::load( \IPS\Request::i()->id );
|
||||
$club = Club::load( Request::i()->id );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C352/7', 404, '' );
|
||||
Output::i()->error( 'node_error', '2C352/7', 404, '' );
|
||||
}
|
||||
|
||||
/* Ask what to do with each node */
|
||||
$nodes = $club->nodes();
|
||||
if ( \count( $nodes ) )
|
||||
if ( count( $nodes ) )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'form', 'delete' );
|
||||
$form = new Form( 'form', 'delete' );
|
||||
$form->addMessage( 'club_delete_blurb' );
|
||||
foreach ( $nodes as $data )
|
||||
{
|
||||
try
|
||||
{
|
||||
$field = new \IPS\Helpers\Form\Node( 'node_' . str_replace( '\\', '-', preg_replace( '/^IPS\\\/', '', $data['node_class'] ) ) . '_' . $data['node_id'], 0, TRUE, array( 'class' => $data['node_class'], 'disabled' => array( $data['node_id'] ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'node_delete_content', 'subnodes' => FALSE, 'permissionCheck' => function( $node )
|
||||
$field = new Node( 'node_' . str_replace( '\\', '-', preg_replace( '/^IPS\\\/', '', $data['node_class'] ) ) . '_' . $data['node_id'], 0, TRUE, array( 'class' => $data['node_class'], 'disabled' => array( $data['node_id'] ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'node_delete_content', 'subnodes' => FALSE, 'permissionCheck' => function( $node )
|
||||
{
|
||||
return array_key_exists( 'add', $node->permissionTypes() );
|
||||
}, 'clubs' => TRUE ) );
|
||||
$field->label = htmlspecialchars( $data['name'] );
|
||||
$form->add( $field );
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
catch ( Exception $e ) {}
|
||||
}
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
@@ -385,6 +426,7 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
|
||||
try
|
||||
{
|
||||
/* @var Model $nodeClass */
|
||||
$node = $nodeClass::load( $exploded[2] );
|
||||
|
||||
$nodesToQueue = array( $node );
|
||||
@@ -410,35 +452,35 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
$_node->deleteOrMoveFormSubmit( $_values );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
catch ( Exception $e ) {}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->output = $form;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
Request::i()->confirmedDelete();
|
||||
}
|
||||
|
||||
/* Delete it */
|
||||
\IPS\Session::i()->log( 'acplog__club_deleted', array( $club->name => FALSE ) );
|
||||
Session::i()->log( 'acplog__club_deleted', array( $club->name => FALSE ) );
|
||||
$club->delete();
|
||||
\IPS\Db::i()->delete( 'core_clubs_memberships', array( 'club_id=?', $club->id ) );
|
||||
\IPS\Db::i()->delete( 'core_clubs_node_map', array( 'club_id=?', $club->id ) );
|
||||
\IPS\Db::i()->delete( 'core_clubs_fieldvalues', array( 'club_id=?', $club->id ) );
|
||||
Db::i()->delete( 'core_clubs_memberships', array( 'club_id=?', $club->id ) );
|
||||
Db::i()->delete( 'core_clubs_node_map', array( 'club_id=?', $club->id ) );
|
||||
Db::i()->delete( 'core_clubs_fieldvalues', array( 'club_id=?', $club->id ) );
|
||||
|
||||
/* Boink */
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( "OK" );
|
||||
Output::i()->json( "OK" );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=clubs&controller=clubs'), 'deleted' );
|
||||
Output::i()->redirect( Url::internal('app=core&module=clubs&controller=clubs'), 'deleted' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,59 +489,59 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function nodeForm()
|
||||
protected function nodeForm() : void
|
||||
{
|
||||
/* Load Club */
|
||||
try
|
||||
{
|
||||
$club = \IPS\Member\Club::load( \IPS\Request::i()->club );
|
||||
$club = Club::load( Request::i()->club );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C352/2', 404, '' );
|
||||
Output::i()->error( 'node_error', '2C352/2', 404, '' );
|
||||
}
|
||||
|
||||
/* Load Node */
|
||||
$nodeClass = \IPS\Request::i()->nodeClass;
|
||||
if ( isset( \IPS\Request::i()->nodeId ) )
|
||||
$nodeClass = Request::i()->nodeClass;
|
||||
if ( isset( Request::i()->nodeId ) )
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_edit_nodes' );
|
||||
Dispatcher::i()->checkAcpPermission( 'clubs_edit_nodes' );
|
||||
|
||||
try
|
||||
{
|
||||
$node = $nodeClass::load( \IPS\Request::i()->nodeId );
|
||||
$node = $nodeClass::load( Request::i()->nodeId );
|
||||
$nodeClub = $node->club();
|
||||
if ( !$nodeClub or $nodeClub->id !== $club->id )
|
||||
{
|
||||
throw new \Exception;
|
||||
throw new Exception;
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C352/3', 404, '' );
|
||||
Output::i()->error( 'node_error', '2C352/3', 404, '' );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_add_nodes' );
|
||||
Dispatcher::i()->checkAcpPermission( 'clubs_add_nodes' );
|
||||
$node = new $nodeClass;
|
||||
}
|
||||
|
||||
/* Build Form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form = new Form;
|
||||
$node->clubForm( $form, $club );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$node->saveClubForm( $club, $values );
|
||||
\IPS\Session::i()->log( 'acplog__node_edited_club', array( $nodeClass::$nodeTitle => TRUE, $node->titleForLog() => FALSE, $club->name => FALSE ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=clubs&controller=clubs&do=edit&id={$club->id}&tab=" . str_replace( '\\', '-', preg_replace( '/^IPS\\\/', '', $nodeClass ) ) ) );
|
||||
Session::i()->log( 'acplog__node_edited_club', array( $nodeClass::$nodeTitle => TRUE, $node->titleForLog() => FALSE, $club->name => FALSE ) );
|
||||
Output::i()->redirect( Url::internal( "app=core&module=clubs&controller=clubs&do=edit&id={$club->id}&tab=" . str_replace( '\\', '-', preg_replace( '/^IPS\\\/', '', $nodeClass ) ) ) );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = $node->_title;
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->title = $node->_title;
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -507,36 +549,36 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteNode()
|
||||
protected function deleteNode() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_delete_nodes' );
|
||||
Dispatcher::i()->checkAcpPermission( 'clubs_delete_nodes' );
|
||||
|
||||
/* Load Club */
|
||||
try
|
||||
{
|
||||
$club = \IPS\Member\Club::load( \IPS\Request::i()->club );
|
||||
$club = Club::load( Request::i()->club );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C352/4', 404, '' );
|
||||
Output::i()->error( 'node_error', '2C352/4', 404, '' );
|
||||
}
|
||||
|
||||
/* Load Node */
|
||||
$nodeClass = \IPS\Request::i()->nodeClass;
|
||||
$nodeClass = Request::i()->nodeClass;
|
||||
try
|
||||
{
|
||||
$node = $nodeClass::load( \IPS\Request::i()->nodeId );
|
||||
$node = $nodeClass::load( Request::i()->nodeId );
|
||||
$nodeClub = $node->club();
|
||||
if ( !$nodeClub or $nodeClub->id !== $club->id )
|
||||
{
|
||||
throw new \Exception;
|
||||
throw new Exception;
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C352/5', 404, '' );
|
||||
Output::i()->error( 'node_error', '2C352/5', 404, '' );
|
||||
}
|
||||
$targetUrl = \IPS\Http\Url::internal( "app=core&module=clubs&controller=clubs&do=edit&id={$club->id}&tab=" . str_replace( '\\', '-', preg_replace( '/^IPS\\\/', '', $nodeClass ) ) );
|
||||
$targetUrl = Url::internal( "app=core&module=clubs&controller=clubs&do=edit&id={$club->id}&tab=" . str_replace( '\\', '-', preg_replace( '/^IPS\\\/', '', $nodeClass ) ) );
|
||||
|
||||
/* Do we have any children or content? */
|
||||
if ( $node->hasChildren( NULL, NULL, TRUE ) or $node->showDeleteOrMoveForm() )
|
||||
@@ -544,36 +586,36 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
$form = $node->deleteOrMoveForm( FALSE );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_clubs_node_map', array( 'club_id=? AND node_class=? AND node_id=?', $club->id, $nodeClass, $node->_id ) );
|
||||
Db::i()->delete( 'core_clubs_node_map', array( 'club_id=? AND node_class=? AND node_id=?', $club->id, $nodeClass, $node->_id ) );
|
||||
$node->deleteOrMoveFormSubmit( $values );
|
||||
\IPS\Output::i()->redirect( $targetUrl );
|
||||
Output::i()->redirect( $targetUrl );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Show form */
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->output = $form;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Make sure the user confirmed the deletion */
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
Request::i()->confirmedDelete();
|
||||
}
|
||||
|
||||
/* Delete it */
|
||||
\IPS\Db::i()->delete( 'core_clubs_node_map', array( 'club_id=? AND node_class=? AND node_id=?', $club->id, $nodeClass, $node->_id ) );
|
||||
\IPS\Session::i()->log( 'acplog__node_deleted_club', array( $nodeClass::$nodeTitle => TRUE, $node->titleForLog() => FALSE, $club->name => FALSE ) );
|
||||
Db::i()->delete( 'core_clubs_node_map', array( 'club_id=? AND node_class=? AND node_id=?', $club->id, $nodeClass, $node->_id ) );
|
||||
Session::i()->log( 'acplog__node_deleted_club', array( $nodeClass::$nodeTitle => TRUE, $node->titleForLog() => FALSE, $club->name => FALSE ) );
|
||||
$node->delete();
|
||||
|
||||
/* Boink */
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( "OK" );
|
||||
Output::i()->json( "OK" );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $targetUrl );
|
||||
Output::i()->redirect( $targetUrl );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,8 +624,9 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getNodeRows()
|
||||
public function _getNodeRows() : array
|
||||
{
|
||||
/* @var Model $nodeClass */
|
||||
$nodeClass = $this->nodeClass;
|
||||
$rows = array();
|
||||
foreach( $nodeClass::roots( NULL, NULL, array( $nodeClass::$databasePrefix . $nodeClass::clubIdColumn() . '=?', $this->club->id ) ) as $node )
|
||||
@@ -602,11 +645,11 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
* @param bool $noSort If TRUE, sort options will be disabled (used for search results)
|
||||
* @return string
|
||||
*/
|
||||
public function _getNodeRow( $id, $root=FALSE, $noSort=FALSE )
|
||||
public function _getNodeRow( mixed $id, bool $root=FALSE, bool $noSort=FALSE ) : string
|
||||
{
|
||||
$nodeClass = $this->nodeClass;
|
||||
|
||||
if ( $id instanceof \IPS\Node\Model )
|
||||
if ( $id instanceof Model )
|
||||
{
|
||||
$node = $id;
|
||||
}
|
||||
@@ -614,11 +657,12 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
/* @var Model $nodeClass */
|
||||
$node = $nodeClass::load( $id );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C352/6', 404, '' );
|
||||
Output::i()->error( 'node_error', '2C352/6', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,29 +675,29 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
'target'=> '_blank',
|
||||
)
|
||||
);
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_edit_nodes' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_edit_nodes' ) )
|
||||
{
|
||||
$buttons['edit'] = array(
|
||||
'title' => 'edit',
|
||||
'icon' => 'pencil',
|
||||
'link' => \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs&do=nodeForm&club={$this->club->id}&nodeClass={$nodeClass}&nodeId={$node->_id}"),
|
||||
'link' => Url::internal("app=core&module=clubs&controller=clubs&do=nodeForm&club={$this->club->id}&nodeClass={$nodeClass}&nodeId={$node->_id}"),
|
||||
'data' => array(
|
||||
'ipsDialog' => '',
|
||||
'ipsDialog-title' => $node->_title
|
||||
)
|
||||
);
|
||||
}
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_delete_nodes' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_delete_nodes' ) )
|
||||
{
|
||||
$buttons['delete'] = array(
|
||||
'title' => 'delete',
|
||||
'icon' => 'times-circle',
|
||||
'link' => \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs&do=deleteNode&club={$this->club->id}&nodeClass={$nodeClass}&nodeId={$node->_id}"),
|
||||
'link' => Url::internal("app=core&module=clubs&controller=clubs&do=deleteNode&club={$this->club->id}&nodeClass={$nodeClass}&nodeId={$node->_id}"),
|
||||
'data' => ( $node->hasChildren( NULL, NULL, TRUE ) or $node->showDeleteOrMoveForm() ) ? array( 'ipsDialog' => '', 'ipsDialog-title' => $node->_title ) : array( 'delete' => '' ),
|
||||
);
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'trees', 'core' )->row(
|
||||
return Theme::i()->getTemplate( 'trees', 'core' )->row(
|
||||
NULL,
|
||||
$node->_id,
|
||||
$node->_title,
|
||||
@@ -668,23 +712,23 @@ class _clubs extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateExisting()
|
||||
public function updateExisting() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$club = \IPS\Member\Club::load( \IPS\Request::i()->id );
|
||||
$club = Club::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '3C352/8', 403, '' );
|
||||
Output::i()->error( 'no_module_permission', '3C352/8', 403, '' );
|
||||
}
|
||||
|
||||
$changes = json_decode( \IPS\Request::i()->changes, TRUE );
|
||||
$changes = json_decode( Request::i()->changes, TRUE );
|
||||
|
||||
\IPS\Task::queue( 'core', 'UpdateClubRenewals', array( 'changes' => $changes, 'club' => $club->id ), 5 );
|
||||
Task::queue( 'core', 'UpdateClubRenewals', array( 'changes' => $changes, 'club' => $club->id ), 5 );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=clubs&controller=clubs" ), 'saved' );
|
||||
Output::i()->redirect( Url::internal( "app=core&module=clubs&controller=clubs" ), 'saved' );
|
||||
}
|
||||
}
|
||||
@@ -12,35 +12,40 @@
|
||||
namespace IPS\core\modules\admin\clubs;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Node\Controller;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* fields
|
||||
*/
|
||||
class _fields extends \IPS\Node\Controller
|
||||
class fields extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\Member\Club\CustomField';
|
||||
protected string $nodeClass = 'IPS\Member\Club\CustomField';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'fields_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'fields_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
@@ -11,30 +11,51 @@
|
||||
namespace IPS\core\modules\admin\clubs;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use IPS\Application;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Form\Money;
|
||||
use IPS\Output;
|
||||
use IPS\Session;
|
||||
use IPS\Settings as SettingsClass;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clubs Settings
|
||||
*/
|
||||
class _settings extends \IPS\Dispatcher\Controller
|
||||
class settings extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_settings_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'clubs_settings_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -43,54 +64,54 @@ class _settings extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
$fields = array( 'clubs_default_sort', 'clubs_header', 'clubs_locations', 'clubs_modperms', 'clubs_require_approval', 'form_header_club_display_settings', 'form_header_club_moderation', 'clubs_default_view', 'clubs_allow_view_change', 'club_nodes_in_apps', 'form_header_clubs_paid_settings', 'clubs_paid_on', '_allow_club_moderators', 'club_max_cover' );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form = new Form;
|
||||
$form->addHeader( 'club_settings' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'clubs_enabled_setting', \IPS\Settings::i()->clubs, FALSE, array( 'togglesOn' => $fields ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'clubs_require_approval', \IPS\Settings::i()->clubs_require_approval, FALSE, array(), NULL, NULL, NULL, 'clubs_require_approval' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'clubs_locations', \IPS\Settings::i()->clubs_locations, FALSE, array(), NULL, NULL, NULL, 'clubs_locations' ) );
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) )
|
||||
$form->add( new YesNo( 'clubs_enabled_setting', SettingsClass::i()->clubs, FALSE, array( 'togglesOn' => $fields ) ) );
|
||||
$form->add( new YesNo( 'clubs_require_approval', SettingsClass::i()->clubs_require_approval, FALSE, array(), NULL, NULL, NULL, 'clubs_require_approval' ) );
|
||||
$form->add( new YesNo( 'clubs_locations', SettingsClass::i()->clubs_locations, FALSE, array(), NULL, NULL, NULL, 'clubs_locations' ) );
|
||||
if ( Application::appIsEnabled( 'nexus' ) )
|
||||
{
|
||||
$form->addHeader( 'clubs_paid_settings' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'clubs_paid_on', \IPS\Settings::i()->clubs_paid_on, FALSE, array( 'togglesOn' => array( 'clubs_paid_tax', 'clubs_paid_commission', 'clubs_paid_transfee', 'clubs_paid_gateways' ) ), NULL, NULL, NULL, 'clubs_paid_on' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'clubs_paid_tax', \IPS\Settings::i()->clubs_paid_tax ?:0, FALSE, array( 'class' => '\IPS\nexus\Tax', 'zeroVal' => 'do_not_tax' ), NULL, NULL, NULL, 'clubs_paid_tax' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'clubs_paid_commission', \IPS\Settings::i()->clubs_paid_commission, FALSE, array( 'min' => 0, 'max' => 100 ), NULL, NULL, '%', 'clubs_paid_commission' ) );
|
||||
$form->add( new \IPS\nexus\Form\Money( 'clubs_paid_transfee', \IPS\Settings::i()->clubs_paid_transfee, FALSE, array(), NULL, NULL, NULL, 'clubs_paid_transfee' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'clubs_paid_gateways', \IPS\Settings::i()->clubs_paid_gateways, FALSE, array( 'class' => '\IPS\nexus\Gateway', 'zeroVal' => 'no_restriction', 'multiple' => TRUE ), NULL, NULL, NULL, 'clubs_paid_gateways' ) );
|
||||
$form->add( new YesNo( 'clubs_paid_on', SettingsClass::i()->clubs_paid_on, FALSE, array( 'togglesOn' => array( 'clubs_paid_tax', 'clubs_paid_commission', 'clubs_paid_transfee', 'clubs_paid_gateways' ) ), NULL, NULL, NULL, 'clubs_paid_on' ) );
|
||||
$form->add( new Node( 'clubs_paid_tax', SettingsClass::i()->clubs_paid_tax ?:0, FALSE, array( 'class' => '\IPS\nexus\Tax', 'zeroVal' => 'do_not_tax' ), NULL, NULL, NULL, 'clubs_paid_tax' ) );
|
||||
$form->add( new Number( 'clubs_paid_commission', SettingsClass::i()->clubs_paid_commission, FALSE, array( 'min' => 0, 'max' => 100 ), NULL, NULL, '%', 'clubs_paid_commission' ) );
|
||||
$form->add( new Money( 'clubs_paid_transfee', SettingsClass::i()->clubs_paid_transfee, FALSE, array(), NULL, NULL, NULL, 'clubs_paid_transfee' ) );
|
||||
$form->add( new Node( 'clubs_paid_gateways', SettingsClass::i()->clubs_paid_gateways, FALSE, array( 'class' => '\IPS\nexus\Gateway', 'zeroVal' => 'no_restriction', 'multiple' => TRUE ), NULL, NULL, NULL, 'clubs_paid_gateways' ) );
|
||||
}
|
||||
$form->addHeader( 'club_display_settings' );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'clubs_default_view', \IPS\Settings::i()->clubs_default_view, FALSE, array( 'options' => array(
|
||||
$form->add( new Radio( 'clubs_default_view', SettingsClass::i()->clubs_default_view, FALSE, array( 'options' => array(
|
||||
'grid' => 'club_view_grid',
|
||||
'list' => 'club_view_list',
|
||||
) ), NULL, NULL, NULL, 'clubs_default_view' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'clubs_allow_view_change', \IPS\Settings::i()->clubs_allow_view_change, FALSE, array(), NULL, NULL, NULL, 'clubs_allow_view_change' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'clubs_default_sort', \IPS\Settings::i()->clubs_default_sort, FALSE, array( 'options' => array(
|
||||
$form->add( new YesNo( 'clubs_allow_view_change', SettingsClass::i()->clubs_allow_view_change, FALSE, array(), NULL, NULL, NULL, 'clubs_allow_view_change' ) );
|
||||
$form->add( new Radio( 'clubs_default_sort', SettingsClass::i()->clubs_default_sort, FALSE, array( 'options' => array(
|
||||
'last_activity' => 'clubs_sort_last_activity',
|
||||
'members' => 'clubs_sort_members',
|
||||
'content' => 'clubs_sort_content',
|
||||
'created' => 'clubs_sort_created',
|
||||
'name' => 'clubs_sort_name'
|
||||
) ), NULL, NULL, NULL, 'clubs_default_sort' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'clubs_header', \IPS\Settings::i()->clubs_header, FALSE, array( 'options' => array(
|
||||
$form->add( new Radio( 'clubs_header', SettingsClass::i()->clubs_header, FALSE, array( 'options' => array(
|
||||
'full' => 'clubs_header_full',
|
||||
'sidebar' => 'clubs_header_sidebar',
|
||||
) ), NULL, NULL, NULL, 'clubs_header' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'club_nodes_in_apps', \IPS\Settings::i()->club_nodes_in_apps, FALSE, array( 'options' => array(
|
||||
$form->add( new Radio( 'club_nodes_in_apps', SettingsClass::i()->club_nodes_in_apps, FALSE, array( 'options' => array(
|
||||
'0' => 'club_nodes_in_apps_off',
|
||||
'1' => 'club_nodes_in_apps_on',
|
||||
) ), NULL, NULL, NULL, 'club_nodes_in_apps' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'club_max_cover', \IPS\Settings::i()->club_max_cover ?: -1, FALSE, array( 'unlimited' => -1 ), function( $value ) {
|
||||
$form->add( new Number( 'club_max_cover', SettingsClass::i()->club_max_cover ?: -1, FALSE, array( 'unlimited' => -1 ), function( $value ) {
|
||||
if( !$value )
|
||||
{
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
throw new InvalidArgumentException('form_required');
|
||||
}
|
||||
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('filesize_raw_k'), 'club_max_cover' ) );
|
||||
}, NULL, Member::loggedIn()->language()->addToStack('filesize_raw_k'), 'club_max_cover' ) );
|
||||
$form->addHeader( 'club_moderation' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( '_allow_club_moderators', ( \IPS\Settings::i()->clubs_modperms != -1 ), FALSE, array( 'togglesOn' => array( 'clubs_modperms' ) ), NULL, NULL, NULL, '_allow_club_moderators' ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'clubs_modperms', ( \IPS\Settings::i()->clubs_modperms != -1 ) ? explode( ',', \IPS\Settings::i()->clubs_modperms ) : array(), FALSE, array( 'options' => array(
|
||||
$form->add( new YesNo( '_allow_club_moderators', ( SettingsClass::i()->clubs_modperms != -1 ), FALSE, array( 'togglesOn' => array( 'clubs_modperms' ) ), NULL, NULL, NULL, '_allow_club_moderators' ) );
|
||||
$form->add( new CheckboxSet( 'clubs_modperms', ( SettingsClass::i()->clubs_modperms != -1 ) ? explode( ',', SettingsClass::i()->clubs_modperms ) : array(), FALSE, array( 'options' => array(
|
||||
'pin' => 'club_modperm_pin',
|
||||
'unpin' => 'club_modperm_unpin',
|
||||
'edit' => 'club_modperm_edit',
|
||||
@@ -117,23 +138,23 @@ class _settings extends \IPS\Dispatcher\Controller
|
||||
$values['clubs_modperms'] = array();
|
||||
}
|
||||
|
||||
$values['clubs_modperms'] = ( \count( $values['clubs_modperms'] ) ) ? implode( ',', $values['clubs_modperms'] ) : -1;
|
||||
$values['clubs_modperms'] = ( count( $values['clubs_modperms'] ) ) ? implode( ',', $values['clubs_modperms'] ) : -1;
|
||||
|
||||
/* Get rid of fake settings */
|
||||
unset( $values['clubs_enabled_setting'], $values['_allow_club_moderators'] );
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) )
|
||||
if ( Application::appIsEnabled( 'nexus' ) )
|
||||
{
|
||||
$values['clubs_paid_tax'] = $values['clubs_paid_tax'] ? $values['clubs_paid_tax']->id : 0;
|
||||
$values['clubs_paid_gateways'] = \is_array( $values['clubs_paid_gateways'] ) ? implode( ',', array_keys( $values['clubs_paid_gateways'] ) ) : $values['clubs_paid_gateways'];
|
||||
$values['clubs_paid_gateways'] = is_array( $values['clubs_paid_gateways'] ) ? implode( ',', array_keys( $values['clubs_paid_gateways'] ) ) : $values['clubs_paid_gateways'];
|
||||
}
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
\IPS\Session::i()->log( 'acplog__club_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=clubs&controller=settings'), 'saved' );
|
||||
Session::i()->log( 'acplog__club_settings' );
|
||||
Output::i()->redirect( Url::internal('app=core&module=clubs&controller=settings'), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_clubs_settings');
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('club_settings');
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -11,30 +11,50 @@
|
||||
namespace IPS\core\modules\admin\clubs;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Db\Select;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Chart;
|
||||
use IPS\Helpers\Chart\Callback;
|
||||
use IPS\Helpers\Chart\Database;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Club;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics
|
||||
*/
|
||||
class _stats extends \IPS\Dispatcher\Controller
|
||||
class stats extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'stats_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'stats_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -43,40 +63,40 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
/* If clubs are not enabled, stop now */
|
||||
if ( !\IPS\Settings::i()->clubs )
|
||||
if ( !Settings::i()->clubs )
|
||||
{
|
||||
$availableTypes = array();
|
||||
foreach ( \IPS\Member\Club::availableNodeTypes( NULL ) as $class )
|
||||
foreach ( Club::availableNodeTypes() as $class )
|
||||
{
|
||||
$availableTypes[] = \IPS\Member::loggedIn()->language()->addToStack( $class::clubAcpTitle() );
|
||||
$availableTypes[] = Member::loggedIn()->language()->addToStack( $class::clubAcpTitle() );
|
||||
}
|
||||
|
||||
$availableTypes = \IPS\Member::loggedIn()->language()->formatList( $availableTypes );
|
||||
$availableTypes = Member::loggedIn()->language()->formatList( $availableTypes );
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'clubs' )->disabled( $availableTypes );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'clubs' )->disabled( $availableTypes );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Generate the tabs */
|
||||
$tabs = array( 'overview' => 'overview', 'total' => 'stats_club_activity', 'byclub' => 'stats_club_club_activity' );
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'overview';
|
||||
$activeTab = ( isset( Request::i()->tab ) and array_key_exists( Request::i()->tab, $tabs ) ) ? Request::i()->tab : 'overview';
|
||||
|
||||
/* Get the HTML to output */
|
||||
$method = '_' . $activeTab;
|
||||
$output = $this->$method();
|
||||
|
||||
/* And then print it */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = (string) $output;
|
||||
Output::i()->output = (string) $output;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_clubs_stats');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $output, \IPS\Http\Url::internal( "app=core&module=clubs&controller=stats" ) );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__core_clubs_stats');
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $output, Url::internal( "app=core&module=clubs&controller=stats" ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,23 +105,23 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _overview()
|
||||
protected function _overview() : string
|
||||
{
|
||||
$clubTypePieChart = $this->_getClubTypePieChart();
|
||||
$clubSignups = $this->_getClubSignups();
|
||||
$clubCreations = $this->_getClubCreations();
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->statsOverview( $clubTypePieChart, $clubSignups, $clubCreations );
|
||||
return Theme::i()->getTemplate( 'clubs', 'core' )->statsOverview( $clubTypePieChart, $clubSignups, $clubCreations );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line chart showing club signups
|
||||
*
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @return Chart
|
||||
*/
|
||||
protected function _getClubSignups()
|
||||
protected function _getClubSignups() : Chart
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Database( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&fetch=signups' ), 'core_clubs_memberships', 'joined', '', array(
|
||||
$chart = new Database( Url::internal( 'app=core&module=clubs&controller=stats&fetch=signups' ), 'core_clubs_memberships', 'joined', '', array(
|
||||
'isStacked' => TRUE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
|
||||
@@ -112,17 +132,17 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
$chart->joins[] = array( 'core_clubs', 'core_clubs.id=core_clubs_memberships.club_id' );
|
||||
$chart->groupBy = 'club_id';
|
||||
|
||||
foreach( \IPS\Member\Club::clubs( NULL, NULL, 'name' ) as $club )
|
||||
foreach( Club::clubs( NULL, NULL, 'name' ) as $club )
|
||||
{
|
||||
$chart->addSeries( $club->name, 'number', 'COUNT(*)', TRUE, $club->id );
|
||||
}
|
||||
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('stats_clubs_signups');
|
||||
$chart->title = Member::loggedIn()->language()->addToStack('stats_clubs_signups');
|
||||
$chart->availableTypes = array( 'ColumnChart', 'BarChart' );
|
||||
|
||||
if( \IPS\Request::i()->fetch == 'signups' AND \IPS\Request::i()->isAjax() )
|
||||
if( Request::i()->fetch == 'signups' AND Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( (string) $chart, 200 );
|
||||
Output::i()->sendOutput( (string) $chart );
|
||||
}
|
||||
|
||||
return $chart;
|
||||
@@ -131,11 +151,11 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
/**
|
||||
* Get line chart showing club creations
|
||||
*
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @return Chart
|
||||
*/
|
||||
protected function _getClubCreations()
|
||||
protected function _getClubCreations() : Chart
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Database( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&fetch=clubs' ), 'core_clubs', 'created', '', array(
|
||||
$chart = new Database( Url::internal( 'app=core&module=clubs&controller=stats&fetch=clubs' ), 'core_clubs', 'created', '', array(
|
||||
'isStacked' => FALSE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'colors' => array( '#10967e' ),
|
||||
@@ -143,13 +163,13 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
'lineWidth' => 1,
|
||||
'areaOpacity' => 0.4
|
||||
), 'ColumnChart', 'monthly', array( 'start' => 0, 'end' => 0 ), array(), 'signups' );
|
||||
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('stats_clubs_creations'), 'number', 'COUNT(*)', FALSE );
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('stats_clubs_creations');
|
||||
$chart->addSeries( Member::loggedIn()->language()->addToStack('stats_clubs_creations'), 'number', 'COUNT(*)', FALSE );
|
||||
$chart->title = Member::loggedIn()->language()->addToStack('stats_clubs_creations');
|
||||
$chart->availableTypes = array( 'ColumnChart', 'BarChart' );
|
||||
|
||||
if( \IPS\Request::i()->fetch == 'clubs' AND \IPS\Request::i()->isAjax() )
|
||||
if( Request::i()->fetch == 'clubs' AND Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( (string) $chart, 200 );
|
||||
Output::i()->sendOutput( (string) $chart );
|
||||
}
|
||||
|
||||
return $chart;
|
||||
@@ -158,15 +178,15 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
/**
|
||||
* Get pie chart showing club types
|
||||
*
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @return string
|
||||
*/
|
||||
protected function _getClubTypePieChart()
|
||||
protected function _getClubTypePieChart() : string
|
||||
{
|
||||
$percentages = array();
|
||||
$counts = array();
|
||||
$total = 0;
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'type, COUNT(*) as total', 'core_clubs', array(), NULL, NULL, array( 'type' ) ) as $clubs )
|
||||
foreach( Db::i()->select( 'type, COUNT(*) as total', 'core_clubs', array(), NULL, NULL, array( 'type' ) ) as $clubs )
|
||||
{
|
||||
$counts[ $clubs['type'] ] = $clubs['total'];
|
||||
$total += $clubs['total'];
|
||||
@@ -177,18 +197,18 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
$percentages[ $type ] = number_format( round( 100 / $total * $typeTotal, 2 ), 2 );
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->clubTypesBar( $percentages, $counts );
|
||||
return Theme::i()->getTemplate( 'clubs', 'core' )->clubTypesBar( $percentages, $counts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Total club activity
|
||||
*
|
||||
* @return \IPS\Helpers\Chart\Dynamic
|
||||
* @return Callback
|
||||
*/
|
||||
protected function _total()
|
||||
protected function _total() : Chart
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Callback(
|
||||
\IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&tab=total' ),
|
||||
$chart = new Callback(
|
||||
Url::internal( 'app=core&module=clubs&controller=stats&tab=total' ),
|
||||
array( $this, 'getResults' ),
|
||||
'',
|
||||
array(
|
||||
@@ -200,17 +220,17 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
),
|
||||
'ColumnChart',
|
||||
'monthly',
|
||||
array( 'start' => ( new \IPS\DateTime )->sub( new \DateInterval('P6M') ), 'end' => \IPS\DateTime::create() ),
|
||||
array( 'start' => ( new DateTime )->sub( new DateInterval('P6M') ), 'end' => DateTime::create() ),
|
||||
'total'
|
||||
);
|
||||
|
||||
foreach( \IPS\Member\Club::availableNodeTypes( NULL ) as $nodeType )
|
||||
foreach( Club::availableNodeTypes() as $nodeType )
|
||||
{
|
||||
$contentClass = $nodeType::$contentItemClass;
|
||||
$chart->addSeries( \IPS\Member::loggedIn()->language()->get( $contentClass::$title . '_pl' ), 'number', TRUE );
|
||||
$chart->addSeries( Member::loggedIn()->language()->get( $contentClass::$title . '_pl' ), 'number');
|
||||
}
|
||||
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_club_activity' );
|
||||
$chart->title = Member::loggedIn()->language()->addToStack( 'stats_club_activity' );
|
||||
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
|
||||
|
||||
return $chart;
|
||||
@@ -221,10 +241,10 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _byclub()
|
||||
protected function _byclub() : string
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Callback(
|
||||
\IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&tab=byclub' ),
|
||||
$chart = new Callback(
|
||||
Url::internal( 'app=core&module=clubs&controller=stats&tab=byclub' ),
|
||||
array( $this, 'getResults' ),
|
||||
'',
|
||||
array(
|
||||
@@ -236,16 +256,16 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
),
|
||||
'ColumnChart',
|
||||
'monthly',
|
||||
array( 'start' => ( new \IPS\DateTime )->sub( new \DateInterval('P6M') ), 'end' => \IPS\DateTime::create() ),
|
||||
array( 'start' => ( new DateTime )->sub( new DateInterval('P6M') ), 'end' => DateTime::create() ),
|
||||
'byclub'
|
||||
);
|
||||
|
||||
foreach( \IPS\Member\Club::clubs( NULL, NULL, 'name' ) as $club )
|
||||
foreach( Club::clubs( NULL, NULL, 'name' ) as $club )
|
||||
{
|
||||
$chart->addSeries( $club->name, 'number', TRUE );
|
||||
}
|
||||
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_club_club_activity' );
|
||||
$chart->title = Member::loggedIn()->language()->addToStack( 'stats_club_club_activity' );
|
||||
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
|
||||
|
||||
return $chart;
|
||||
@@ -254,13 +274,13 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
/**
|
||||
* Fetch the results
|
||||
*
|
||||
* @param \IPS\Helpers\Chart\Callback $chart Chart object
|
||||
* @param Callback $chart Chart object
|
||||
* @return array
|
||||
*/
|
||||
public function getResults( $chart )
|
||||
public function getResults( Callback $chart ) : array
|
||||
{
|
||||
/* Get the info we need */
|
||||
$nodeTypes = \IPS\Member\Club::availableNodeTypes( NULL );
|
||||
$nodeTypes = Club::availableNodeTypes();
|
||||
$clubNodes = array();
|
||||
$classes = array();
|
||||
$classMap = array();
|
||||
@@ -292,7 +312,7 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$clubNodeMap = array();
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_clubs_node_map' ) as $nodeMap )
|
||||
foreach( Db::i()->select( '*', 'core_clubs_node_map' ) as $nodeMap )
|
||||
{
|
||||
$nodeClass = $nodeMap['node_class'];
|
||||
$nodeClass = $nodeClass::$contentItemClass;
|
||||
@@ -322,21 +342,15 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
$where = array();
|
||||
$join = NULL;
|
||||
|
||||
/* Get our container IDs */
|
||||
$containerIds = array();
|
||||
foreach( $clubNodes[ $classMap[ $class ] ] as $node )
|
||||
{
|
||||
$containerIds[] = $node->id;
|
||||
}
|
||||
|
||||
if( is_subclass_of( $class, '\IPS\Content\Comment' ) )
|
||||
{
|
||||
/* We're going to need a subquery... */
|
||||
$parentClass = $class::$itemClass;
|
||||
|
||||
/* @var array $databaseColumnMap */
|
||||
$where[] = array(
|
||||
$class::$databasePrefix . $class::$databaseColumnMap['item'] . " IN(" .
|
||||
(string) \IPS\Db::i()->select( $parentClass::$databasePrefix . $parentClass::$databaseColumnId, $parentClass::$databaseTable, array( \IPS\Db::i()->in( $parentClass::$databasePrefix . $parentClass::$databaseColumnMap['container'], $containerIds ) ) )
|
||||
Db::i()->select( $parentClass::$databasePrefix . $parentClass::$databaseColumnId, $parentClass::$databaseTable, array( Db::i()->in( $parentClass::$databasePrefix . $parentClass::$databaseColumnMap['container'], array_keys( $clubNodes[ $classMap[ $class ] ] ) ) ) )
|
||||
. ")"
|
||||
);
|
||||
|
||||
@@ -354,7 +368,8 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( $class::$databasePrefix . $class::$databaseColumnMap['container'], $containerIds ) );
|
||||
/* @var array $databaseColumnMap */
|
||||
$where[] = array( Db::i()->in( $class::$databasePrefix . $class::$databaseColumnMap['container'], array_keys( $clubNodes[ $classMap[ $class ] ] ) ) );
|
||||
|
||||
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
|
||||
{
|
||||
@@ -364,11 +379,11 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
|
||||
$stmt = $this->getSqlResults(
|
||||
$class::$databaseTable,
|
||||
$class::$databasePrefix . ( isset( $class::$databaseColumnMap['updated'] ) ? $class::$databaseColumnMap['updated'] : $class::$databaseColumnMap['date'] ),
|
||||
$class::$databasePrefix . ( $class::$databaseColumnMap['updated'] ?? $class::$databaseColumnMap['date'] ),
|
||||
$class::$databasePrefix . $class::$databaseColumnMap['author'],
|
||||
$chart,
|
||||
$where,
|
||||
$groupByContainer,
|
||||
( $groupByContainer ?? false ),
|
||||
$join
|
||||
);
|
||||
|
||||
@@ -382,25 +397,19 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
|
||||
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
|
||||
{
|
||||
foreach( \IPS\Member\Club::clubs( NULL, NULL, 'name' ) as $club )
|
||||
foreach( Club::clubs( NULL, NULL, 'name' ) as $club )
|
||||
{
|
||||
$results[ $row['time'] ][ $club->name ] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( \IPS\Member\Club::availableNodeTypes( NULL ) as $nodeType )
|
||||
foreach( Club::availableNodeTypes() as $nodeType )
|
||||
{
|
||||
$contentClass = $nodeType::$contentItemClass;
|
||||
$languageKey = \IPS\Member::loggedIn()->language()->words[ $contentClass::$title . '_pl'];
|
||||
|
||||
/* Pages Databases may need the language string parsing */
|
||||
if( mb_substr( $contentClass, 0, 15 ) === 'IPS\cms\Records' )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $languageKey );
|
||||
}
|
||||
|
||||
$results[ $row['time'] ][ $languageKey ] = 0;
|
||||
$key = Member::loggedIn()->language()->get( $contentClass::$title . '_pl' );
|
||||
Member::loggedIn()->language()->parseOutputForDisplay( $key );
|
||||
$results[ $row['time'] ][ $key ] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -409,24 +418,14 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
|
||||
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
$results[ $row['time'] ][ \IPS\Member\Club::load( $clubNodeMap[ $class::$databaseTable . '-' . $row['container'] ] )->name ] += $row['total'];
|
||||
}
|
||||
catch( \OutOfRangeException $e ){}
|
||||
$results[ $row['time'] ][ Club::load( $clubNodeMap[ $class::$databaseTable . '-' . $row['container'] ] )->name ] += $row['total'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$languageKey = \IPS\Member::loggedIn()->language()->words[ $contentClass::$title . '_pl'];
|
||||
|
||||
/* Pages Databases may need the language string parsing */
|
||||
if( mb_substr( $contentClass, 0, 15 ) === 'IPS\cms\Records' )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $languageKey );
|
||||
}
|
||||
|
||||
$contentClass = $classMap[ $class ]::$contentItemClass;
|
||||
$results[ $row['time'] ][ $languageKey ] += $row['total'];
|
||||
$key = Member::loggedIn()->language()->get( $contentClass::$title . '_pl' );
|
||||
Member::loggedIn()->language()->parseOutputForDisplay( $key );
|
||||
$results[ $row['time'] ][ $key ] += $row['total'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,9 +444,9 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
* @param array $where Where clause
|
||||
* @param bool|string $groupByContainer If a string is provided, it must be a column name to group by in addition to time
|
||||
* @param NULL|array $join Join data, if needed (only used when $groupByContainer is set)
|
||||
* @return array
|
||||
* @return Select
|
||||
*/
|
||||
protected function getSqlResults( $table, $date, $author, $chart, $where = array(), $groupByContainer = FALSE, $join = NULL )
|
||||
protected function getSqlResults( string $table, string $date, string $author, object $chart, array $where = array(), bool|string $groupByContainer = FALSE, ?array $join = NULL ) : Select
|
||||
{
|
||||
/* What's our SQL time? */
|
||||
switch ( $chart->timescale )
|
||||
@@ -461,6 +460,7 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
break;
|
||||
|
||||
case 'monthly':
|
||||
default:
|
||||
$timescale = '%Y-%c';
|
||||
break;
|
||||
}
|
||||
@@ -478,14 +478,14 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
|
||||
/* First we need to get search index activity */
|
||||
$fromUnixTime = "FROM_UNIXTIME( IFNULL( {$date}, 0 ) )";
|
||||
if ( !$chart->timezoneError and \IPS\Member::loggedIn()->timezone and \in_array( \IPS\Member::loggedIn()->timezone, \IPS\DateTime::getTimezoneIdentifiers() ) )
|
||||
if ( !$chart->timezoneError and Member::loggedIn()->timezone and in_array( Member::loggedIn()->timezone, DateTime::getTimezoneIdentifiers() ) )
|
||||
{
|
||||
$fromUnixTime = "CONVERT_TZ( {$fromUnixTime}, @@session.time_zone, '" . \IPS\Db::i()->escape_string( \IPS\Member::loggedIn()->timezone ) . "' )";
|
||||
$fromUnixTime = "CONVERT_TZ( {$fromUnixTime}, @@session.time_zone, '" . Db::i()->escape_string( Member::loggedIn()->timezone ) . "' )";
|
||||
}
|
||||
|
||||
if( $groupByContainer !== FALSE )
|
||||
{
|
||||
$stmt = \IPS\Db::i()->select( "DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time, COUNT(*) as total, {$groupByContainer} as container", $table, $where, 'time ASC', NULL, array( 'time', 'container' ) );
|
||||
$stmt = Db::i()->select( "DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time, COUNT(*) as total, {$groupByContainer} as container", $table, $where, 'time ASC', NULL, array( 'time', 'container' ) );
|
||||
|
||||
if( $join !== NULL )
|
||||
{
|
||||
@@ -494,7 +494,7 @@ class _stats extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
else
|
||||
{
|
||||
$stmt = \IPS\Db::i()->select( "DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time, COUNT(*) as total", $table, $where, 'time ASC', NULL, array( 'time' ) );
|
||||
$stmt = Db::i()->select( "DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time, COUNT(*) as total", $table, $where, 'time ASC', NULL, array( 'time' ) );
|
||||
}
|
||||
|
||||
return $stmt;
|
||||
|
||||
Reference in new issue
Block a user