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,51 +12,65 @@
|
||||
namespace IPS\calendar;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use BadMethodCallException;
|
||||
use IPS\File;
|
||||
use IPS\GeoLocation;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Address;
|
||||
use IPS\Helpers\Form\Translatable;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Request;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calendar Node
|
||||
*/
|
||||
class _Venue extends \IPS\Node\Model
|
||||
class Venue extends Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'calendar_venues';
|
||||
public static ?string $databaseTable = 'calendar_venues';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'venue_';
|
||||
public static string $databasePrefix = 'venue_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
public static ?string $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'venues';
|
||||
public static string $nodeTitle = 'venues';
|
||||
|
||||
/**
|
||||
* @brief URL Base
|
||||
*/
|
||||
public static $urlTemplate = 'calendar_venue';
|
||||
public static string $urlTemplate = 'calendar_venue';
|
||||
|
||||
/**
|
||||
* @brief URL Base
|
||||
*/
|
||||
public static $urlBase = 'app=calendar&module=calendar&controller=venue&id=';
|
||||
public static string $urlBase = 'app=calendar&module=calendar&controller=venue&id=';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
@@ -74,36 +88,43 @@ class _Venue 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' => 'calendar',
|
||||
'module' => 'calendars',
|
||||
'all' => 'venues_manage'
|
||||
'module' => 'venues',
|
||||
'prefix' => 'venues_'
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'calendar_venue_';
|
||||
public static ?string $titleLangPrefix = 'calendar_venue_';
|
||||
|
||||
/**
|
||||
* @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] Moderator Permission
|
||||
*/
|
||||
public static $modPerm = 'calendar_venues';
|
||||
public static string $modPerm = 'calendar_venues';
|
||||
|
||||
/**
|
||||
* @brief [Node] Maximum results to display at a time in any node helper form elements. Useful for user-submitted node types when there may be a lot. NULL for no limit.
|
||||
*/
|
||||
public static $maxFormHelperResults = 2000;
|
||||
public static ?int $maxFormHelperResults = 2000;
|
||||
|
||||
/**
|
||||
* @brief The class of the ACP \IPS\Node\Controller that manages this node type
|
||||
*/
|
||||
protected static $acpController = "IPS\\calendar\\modules\\admin\\calendars\\venues";
|
||||
protected static ?string $acpController = "IPS\\calendar\\modules\\admin\\calendars\\venues";
|
||||
|
||||
/**
|
||||
* Determines if this class can be extended via UI Extension
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static bool $canBeExtended = true;
|
||||
|
||||
/**
|
||||
* [Node] Get whether or not this node is enabled
|
||||
@@ -111,7 +132,7 @@ class _Venue extends \IPS\Node\Model
|
||||
* @note Return value NULL indicates the node cannot be enabled/disabled
|
||||
* @return bool|null
|
||||
*/
|
||||
protected function get__enabled()
|
||||
protected function get__enabled(): ?bool
|
||||
{
|
||||
return (bool) $this->enabled;
|
||||
}
|
||||
@@ -122,7 +143,7 @@ class _Venue extends \IPS\Node\Model
|
||||
* @param bool|int $enabled Whether to set it enabled or disabled
|
||||
* @return void
|
||||
*/
|
||||
protected function set__enabled( $enabled )
|
||||
protected function set__enabled( bool|int $enabled ): void
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
@@ -130,35 +151,37 @@ class _Venue extends \IPS\Node\Model
|
||||
/**
|
||||
* @brief Cached URL
|
||||
*/
|
||||
protected $_url = NULL;
|
||||
protected mixed $_url = NULL;
|
||||
|
||||
/**
|
||||
* Get SEO name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_seo()
|
||||
public function get_title_seo(): string
|
||||
{
|
||||
if( !$this->_data['title_seo'] )
|
||||
{
|
||||
$this->title_seo = \IPS\Http\Url\Friendly::seoTitle( \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( 'calendar_venue_' . $this->id ) );
|
||||
$this->title_seo = Friendly::seoTitle( Lang::load( Lang::defaultLanguage() )->get( 'calendar_venue_' . $this->id ) );
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return $this->_data['title_seo'] ?: \IPS\Http\Url\Friendly::seoTitle( \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( 'calendar_venue_' . $this->id ) );
|
||||
return $this->_data['title_seo'] ?: Friendly::seoTitle( Lang::load( Lang::defaultLanguage() )->get( 'calendar_venue_' . $this->id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* [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->add( new \IPS\Helpers\Form\Translatable( 'venue_title', NULL, TRUE, array( 'app' => 'calendar', 'key' => ( $this->id ? "calendar_venue_{$this->id}" : NULL ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'venue_description', NULL, FALSE, array( 'app' => 'calendar', 'key' => ( $this->id ? "calendar_venue_{$this->id}_desc" : NULL ), 'editor' => array( 'app' => 'calendar', 'key' => 'Venue', 'autoSaveKey' => ( $this->id ? "calendar-venue-{$this->id}" : "calendar-new-venue" ), 'attachIds' => $this->id ? array( $this->id, NULL, 'description' ) : NULL ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Address( 'venue_address', $this->id ? \IPS\GeoLocation::buildFromJson( $this->address ) : NULL, TRUE, array( 'minimize' => ( $this->id and $this->address ) ? FALSE : TRUE, 'requireFullAddress' => FALSE, 'preselectCountry' => FALSE ), NULL, NULL, NULL, 'venue_address' ) );
|
||||
$form->add( new Translatable( 'venue_title', NULL, TRUE, array( 'app' => 'calendar', 'key' => ( $this->id ? "calendar_venue_{$this->id}" : NULL ) ) ) );
|
||||
$form->add( new Translatable( 'venue_description', NULL, FALSE, array( 'app' => 'calendar', 'key' => ( $this->id ? "calendar_venue_{$this->id}_desc" : NULL ), 'editor' => array( 'app' => 'calendar', 'key' => 'Venue', 'autoSaveKey' => ( $this->id ? "calendar-venue-{$this->id}" : "calendar-new-venue" ), 'attachIds' => $this->id ? array( $this->id, NULL, 'description' ) : NULL ) ) ) );
|
||||
$form->add( new Address( 'venue_address', $this->id ? GeoLocation::buildFromJson( $this->address ) : NULL, TRUE, array( 'minimize' => !( ( $this->id and $this->address ) ), 'requireFullAddress' => FALSE, 'preselectCountry' => FALSE ), NULL, NULL, NULL, 'venue_address' ) );
|
||||
|
||||
parent::form( $form );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,32 +190,32 @@ class _Venue extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
if ( !$this->id )
|
||||
{
|
||||
$this->save();
|
||||
\IPS\File::claimAttachments( 'calendar-new-venue', $this->id, NULL, 'description', TRUE );
|
||||
File::claimAttachments( 'calendar-new-venue', $this->id, NULL, 'description', TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ( \IPS\Lang::languages() as $lang )
|
||||
foreach ( Lang::languages() as $lang )
|
||||
{
|
||||
\IPS\Request::i()->setClearAutosaveCookie( "calendar-venue-{$this->id}{$lang->id}" );
|
||||
Request::i()->setClearAutosaveCookie( "calendar-venue-{$this->id}{$lang->id}" );
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( $values['venue_title'] ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'calendar', 'calendar_venue_' . $this->id, $values['venue_title'] );
|
||||
$values['title_seo'] = \IPS\Http\Url\Friendly::seoTitle( $values['venue_title'][ \IPS\Lang::defaultLanguage() ] );
|
||||
Lang::saveCustom( 'calendar', 'calendar_venue_' . $this->id, $values['venue_title'] );
|
||||
$values['title_seo'] = Friendly::seoTitle( $values['venue_title'][ Lang::defaultLanguage() ] );
|
||||
|
||||
unset( $values['venue_title'] );
|
||||
}
|
||||
|
||||
if( isset( $values['venue_description'] ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'calendar', 'calendar_venue_' . $this->id .'_desc', $values['venue_description'] );
|
||||
Lang::saveCustom( 'calendar', 'calendar_venue_' . $this->id .'_desc', $values['venue_description'] );
|
||||
unset( $values['venue_description'] );
|
||||
}
|
||||
|
||||
@@ -204,19 +227,19 @@ class _Venue extends \IPS\Node\Model
|
||||
/**
|
||||
* @brief SEO Title Column
|
||||
*/
|
||||
public static $seoTitleColumn = 'title_seo';
|
||||
public static string $seoTitleColumn = 'title_seo';
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
\IPS\Lang::deleteCustom( 'calendar', 'calendar_venue_' . $this->id );
|
||||
\IPS\Lang::deleteCustom( 'calendar', 'calendar_venue_' . $this->id . '_desc' );
|
||||
Lang::deleteCustom( 'calendar', 'calendar_venue_' . $this->id );
|
||||
Lang::deleteCustom( 'calendar', 'calendar_venue_' . $this->id . '_desc' );
|
||||
|
||||
return parent::delete();
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,15 +250,15 @@ class _Venue extends \IPS\Node\Model
|
||||
* @return string
|
||||
* @note \BadMethodCallException can be thrown if the google maps integration is shut off - don't show any error if that happens.
|
||||
*/
|
||||
public function map( $width, $height )
|
||||
public function map( int $width, int $height ): string
|
||||
{
|
||||
if( $this->address )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\GeoLocation::buildFromJson( $this->address )->map()->render( $width, $height );
|
||||
return GeoLocation::buildFromJson( $this->address )->map()->render( $width, $height );
|
||||
}
|
||||
catch( \BadMethodCallException $e ){}
|
||||
catch( BadMethodCallException $e ){}
|
||||
}
|
||||
|
||||
return '';
|
||||
@@ -244,20 +267,20 @@ class _Venue extends \IPS\Node\Model
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @param Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string title Title
|
||||
* @apiresponse string description Description
|
||||
* @apiresponse \IPS\GeoLocation address The address
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
public function apiOutput( Member $authorizedMember = NULL ): array
|
||||
{
|
||||
return array(
|
||||
'id' => $this->id,
|
||||
'title' => $this->_title,
|
||||
'description' => \IPS\Member::loggedIn()->language()->addToStack('calendar_venue_' . $this->id . '_desc', NULL, array( 'removeLazyLoad' => true ) ),
|
||||
'address' => \IPS\GeoLocation::buildFromJson( $this->address )->apiOutput( $authorizedMember )
|
||||
'description' => Member::loggedIn()->language()->addToStack('calendar_venue_' . $this->id . '_desc' ),
|
||||
'address' => GeoLocation::buildFromJson( $this->address )->apiOutput( $authorizedMember )
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user