Version 5.0.6
This commit is contained in:
1 parent
a3a4a9ccbd
commit
b89858b2ff
1214 files changed
+92828
-14859
No files matched your search
@@ -15,12 +15,14 @@ namespace IPS\Content;
|
||||
use IPS\Application\Module;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Club;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Output;
|
||||
use IPS\Output\UI\UiExtension;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use OutOfRangeException;
|
||||
@@ -129,8 +131,47 @@ trait ClubContainer
|
||||
*/
|
||||
public function clubForm( Form $form, Club $club ): void
|
||||
{
|
||||
$itemClass = static::$contentItemClass;
|
||||
$form->add( new Text( 'club_node_name', $this->_id ? $this->_title : Member::loggedIn()->language()->addToStack( static::clubFrontTitle() ), TRUE, array( 'maxLength' => 255 ) ) );
|
||||
$this->_clubForm( $form, $club );
|
||||
|
||||
/* Only do this if the form is still empty */
|
||||
if( empty( $form->elements ) )
|
||||
{
|
||||
$itemClass = static::$contentItemClass;
|
||||
$form->add( new Text( 'club_node_name', $this->_id ? $this->_title : Member::loggedIn()->language()->addToStack( static::clubFrontTitle() ), TRUE, array( 'maxLength' => 255 ) ) );
|
||||
}
|
||||
|
||||
$form->add( new Radio( 'club_node_creators', $this->_id ? $this->creators() : null, false, [ 'options' => [ 0 => 'club_node_creators_0', 1 => 'club_node_creators_1' ] ] ) );
|
||||
|
||||
/* Now loop through and add all the elements to the form */
|
||||
if( static::$canBeExtended )
|
||||
{
|
||||
foreach( UiExtension::i()->getObjectExtensions( $this ) as $extension )
|
||||
{
|
||||
foreach( $extension->clubFormElements( $this, $club ) as $element )
|
||||
{
|
||||
if( is_object( $element ) )
|
||||
{
|
||||
$form->add( $element );
|
||||
}
|
||||
else
|
||||
{
|
||||
$form->addHtml( $element );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class-specific method for each Model to implement
|
||||
*
|
||||
* @param Form $form
|
||||
* @param Club $club
|
||||
* @return void
|
||||
*/
|
||||
public function _clubForm( Form $form, Club $club ) : void
|
||||
{
|
||||
/* Intentionally blank */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,6 +197,15 @@ trait ClubContainer
|
||||
$this->$clubIdColumn = $club->id;
|
||||
}
|
||||
|
||||
/* Loop through each extension and update the values; do this before we save */
|
||||
if( static::$canBeExtended )
|
||||
{
|
||||
foreach( UiExtension::i()->getObjectExtensions( $this ) as $extension )
|
||||
{
|
||||
$values = $extension->processClubForm( $this, $club, $values );
|
||||
}
|
||||
}
|
||||
|
||||
$this->_saveClubForm( $club, $values );
|
||||
|
||||
$needToUpdatePermissions = FALSE;
|
||||
@@ -169,20 +219,25 @@ trait ClubContainer
|
||||
'node_class' => $nodeClass,
|
||||
'node_id' => $this->_id,
|
||||
'name' => $values['club_node_name'],
|
||||
'public' => $values['club_node_public'] ?? 0
|
||||
'public' => $values['club_node_public'] ?? 0,
|
||||
'creators' => $values['club_node_creators'] ?? 0
|
||||
) );
|
||||
|
||||
$needToUpdatePermissions = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( isset( $values['club_node_public'] ) AND $values['club_node_public'] != $this->isPublic() )
|
||||
if( ( isset( $values['club_node_public'] ) and $values['club_node_public'] != $this->isPublic() ) or ( isset( $values['club_node_creators'] ) and $values['club_node_creators'] != $this->creators() ) )
|
||||
{
|
||||
$needToUpdatePermissions = TRUE;
|
||||
}
|
||||
|
||||
$this->save();
|
||||
Db::i()->update( 'core_clubs_node_map', array( 'name' => $values['club_node_name'], 'public' => isset( $values['club_node_public'] ) ? (int) $values['club_node_public'] : 0), array( 'club_id=? AND node_class=? AND node_id=?', $club->id, $nodeClass, $this->_id ) );
|
||||
Db::i()->update( 'core_clubs_node_map', array(
|
||||
'name' => $values['club_node_name'],
|
||||
'public' => isset( $values['club_node_public'] ) ? (int) $values['club_node_public'] : 0,
|
||||
'creators' => isset( $values['club_node_creators'] ) ? (int) $values['club_node_creators'] : 0
|
||||
), array( 'club_id=? AND node_class=? AND node_id=?', $club->id, $nodeClass, $this->_id ) );
|
||||
}
|
||||
|
||||
Lang::saveCustom( $itemClass::$application, static::$titleLangPrefix . $this->_id, $values['club_node_name'] );
|
||||
@@ -210,6 +265,15 @@ trait ClubContainer
|
||||
Db::i()->insert( 'core_follow', $follows );
|
||||
}
|
||||
}
|
||||
|
||||
/* At the very end, call the post-save in extensions */
|
||||
if( static::$canBeExtended )
|
||||
{
|
||||
foreach( UiExtension::i()->getObjectExtensions( $this ) as $extension )
|
||||
{
|
||||
$values = $extension->clubFormPostSave( $this, $club, $values );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,19 +322,26 @@ trait ClubContainer
|
||||
}
|
||||
elseif ( in_array( $k, array( 'add', 'edit', 'reply', 'review' ) ) )
|
||||
{
|
||||
switch ( $club->type )
|
||||
if( in_array( $k, [ 'add', 'edit' ] ) and $this->creators() == 1 )
|
||||
{
|
||||
case $club::TYPE_PUBLIC:
|
||||
$insert[ 'perm_' . $v ] = 'ca';
|
||||
break;
|
||||
case $club::TYPE_CLOSED:
|
||||
$insert[ 'perm_' . $v ] = ( $this->isPublic() == 2 ) ? "*" : "cm,c{$club->id}";
|
||||
break;
|
||||
case $club::TYPE_OPEN:
|
||||
case $club::TYPE_PRIVATE:
|
||||
case $club::TYPE_READONLY:
|
||||
$insert[ 'perm_' . $v ] = "cm,c{$club->id}";
|
||||
break;
|
||||
$insert[ 'perm_' . $v ] = 'cm';
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ( $club->type )
|
||||
{
|
||||
case $club::TYPE_PUBLIC:
|
||||
$insert[ 'perm_' . $v ] = 'ca';
|
||||
break;
|
||||
case $club::TYPE_CLOSED:
|
||||
$insert[ 'perm_' . $v ] = ( $this->isPublic() == 2 ) ? "*" : "cm,c{$club->id}";
|
||||
break;
|
||||
case $club::TYPE_OPEN:
|
||||
case $club::TYPE_PRIVATE:
|
||||
case $club::TYPE_READONLY:
|
||||
$insert[ 'perm_' . $v ] = "cm,c{$club->id}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -450,4 +521,21 @@ trait ClubContainer
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Who can create content in this node?
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function creators() : int
|
||||
{
|
||||
try
|
||||
{
|
||||
return (int) Db::i()->select( 'creators', 'core_clubs_node_map', array( 'club_id=? AND node_class=? AND node_id=?', $this->club()->id, get_called_class(), $this->_id ) )->first();
|
||||
}
|
||||
catch ( UnderflowException $e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user