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,9 +11,22 @@
|
||||
namespace IPS\Helpers\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use IPS\Db;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Theme;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
use function is_numeric;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -22,7 +35,7 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
/**
|
||||
* Content Item selector
|
||||
*/
|
||||
class _Item extends FormAbstract
|
||||
class Item extends FormAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
@@ -39,7 +52,7 @@ class _Item extends FormAbstract
|
||||
* );
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
protected array $defaultOptions = array(
|
||||
'class' => NULL,
|
||||
'permissionCheck' => 'read',
|
||||
'maxItems' => NULL,
|
||||
@@ -55,15 +68,15 @@ class _Item extends FormAbstract
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
/* Display */
|
||||
$url = \IPS\Request::i()->url()->setQueryString( '_itemSelectName', $this->name );
|
||||
$url = Request::i()->url()->setQueryString( '_itemSelectName', $this->name );
|
||||
|
||||
$template = NULL;
|
||||
if ( $this->options['itemTemplate'] === NULL )
|
||||
{
|
||||
$template = array( \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' ), 'itemResult' );
|
||||
$template = array( Theme::i()->getTemplate( 'forms', 'core', 'global' ), 'itemResult' );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -71,19 +84,20 @@ class _Item extends FormAbstract
|
||||
}
|
||||
|
||||
/* Are we getting some AJAX stuff? */
|
||||
if ( isset( \IPS\Request::i()->_itemSelectName ) and \IPS\Request::i()->_itemSelectName === $this->name )
|
||||
if ( isset( Request::i()->_itemSelectName ) and Request::i()->_itemSelectName === $this->name )
|
||||
{
|
||||
/* @var array $databaseColumnMap */
|
||||
$results = array();
|
||||
$class = $this->options['class'];
|
||||
$field = $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['title'];
|
||||
$where = array( array( $field . " LIKE CONCAT('%', ?, '%')", \IPS\Request::i()->q ) );
|
||||
$where = array( array( $field . " LIKE CONCAT('%', ?, '%')", Request::i()->q ) );
|
||||
$idField = $class::$databaseColumnId;
|
||||
if ( isset( $class::$databaseColumnMap['container'] ) and \is_array( $this->options['containerIds'] ) and \count( $this->options['containerIds'] ) )
|
||||
if ( isset( $class::$databaseColumnMap['container'] ) and is_array( $this->options['containerIds'] ) and count( $this->options['containerIds'] ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['container'], $this->options['containerIds'] ) );
|
||||
$where[] = array( Db::i()->in( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['container'], $this->options['containerIds'] ) );
|
||||
}
|
||||
|
||||
if ( isset( $this->options['where'] ) and \count( $this->options['where'] ) )
|
||||
if ( isset( $this->options['where'] ) and count( $this->options['where'] ) )
|
||||
{
|
||||
$where = array_merge( $where, $this->options['where'] );
|
||||
}
|
||||
@@ -96,10 +110,10 @@ class _Item extends FormAbstract
|
||||
);
|
||||
}
|
||||
|
||||
\IPS\Output::i()->json( $results );
|
||||
Output::i()->json( $results );
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->item( $this->name, $this->value, $this->options['maxItems'], $this->options['minAjaxLength'], $url, $template );
|
||||
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->item( $this->name, $this->value, $this->options['maxItems'], $this->options['minAjaxLength'], $url, $template );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,12 +121,12 @@ class _Item extends FormAbstract
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValue()
|
||||
public function getValue(): mixed
|
||||
{
|
||||
$name = $this->name . '_values';
|
||||
if ( isset( \IPS\Request::i()->$name ) )
|
||||
if ( isset( Request::i()->$name ) )
|
||||
{
|
||||
return explode( ',', \IPS\Request::i()->$name );
|
||||
return explode( ',', Request::i()->$name );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -125,7 +139,7 @@ class _Item extends FormAbstract
|
||||
*
|
||||
* @return array|NULL
|
||||
*/
|
||||
public function formatValue()
|
||||
public function formatValue(): mixed
|
||||
{
|
||||
$itemClass = $this->options['class'];
|
||||
$order = NULL;
|
||||
@@ -138,19 +152,19 @@ class _Item extends FormAbstract
|
||||
else
|
||||
{
|
||||
/* $this->value may be a single, numeric, ID, so look for that to avoid a Countable error */
|
||||
if ( \is_numeric( $this->value ) )
|
||||
if ( is_numeric( $this->value ) )
|
||||
{
|
||||
$this->value = array( $this->value );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->value = ( \is_string( $this->value ) ) ? explode( ',', $this->value ) : $this->value;
|
||||
$this->value = ( is_string( $this->value ) ) ? explode( ',', $this->value ) : $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $this->value ) )
|
||||
if ( count( $this->value ) )
|
||||
{
|
||||
if ( \is_array( $this->options['orderResults'] ) )
|
||||
if ( is_array( $this->options['orderResults'] ) )
|
||||
{
|
||||
if ( isset( $itemClass::$databaseColumnMap[ $this->options['orderResults'][0] ] ) )
|
||||
{
|
||||
@@ -158,7 +172,7 @@ class _Item extends FormAbstract
|
||||
}
|
||||
}
|
||||
|
||||
$where = array( \IPS\Db::i()->in( $itemClass::$databaseTable . '.' . $itemClass::$databasePrefix . $itemClass::$databaseColumnId, $this->value ) );
|
||||
$where = array( Db::i()->in( $itemClass::$databaseTable . '.' . $itemClass::$databasePrefix . $itemClass::$databaseColumnId, $this->value ) );
|
||||
foreach( $itemClass::getItemsWithPermission( array( $where ), $order, NULL, $this->options['permissionCheck'] ) as $item )
|
||||
{
|
||||
$items[ $item->$idField ] = $item;
|
||||
@@ -187,15 +201,15 @@ class _Item extends FormAbstract
|
||||
* String Value
|
||||
*
|
||||
* @param mixed $value The value
|
||||
* @return string
|
||||
* @return string|int|null
|
||||
*/
|
||||
public static function stringValue( $value )
|
||||
public static function stringValue( mixed $value ): string|int|null
|
||||
{
|
||||
if ( \is_array( $value ) )
|
||||
if ( is_array( $value ) )
|
||||
{
|
||||
return implode( ',', array_keys( $value ) );
|
||||
}
|
||||
elseif ( \is_object( $value ) )
|
||||
elseif ( is_object( $value ) )
|
||||
{
|
||||
return $value->_id;
|
||||
}
|
||||
@@ -204,16 +218,16 @@ class _Item extends FormAbstract
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
* @return TRUE
|
||||
*/
|
||||
public function validate()
|
||||
public function validate(): bool
|
||||
{
|
||||
if( empty( $this->value ) and $this->required )
|
||||
{
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
throw new InvalidArgumentException('form_required');
|
||||
}
|
||||
|
||||
parent::validate();
|
||||
return parent::validate();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user