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
+39
-30
@@ -11,57 +11,66 @@
|
||||
namespace IPS\Poll;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\DateTime;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use IPS\Poll;
|
||||
use IPS\Request;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Poll Vote Model
|
||||
*/
|
||||
class _Vote extends \IPS\Patterns\ActiveRecord
|
||||
class Vote extends ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_voters';
|
||||
public static ?string $databaseTable = 'core_voters';
|
||||
|
||||
/**
|
||||
* @brief Database ID Column
|
||||
*/
|
||||
public static $databaseColumnId = 'vid';
|
||||
public static string $databaseColumnId = 'vid';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Fields
|
||||
*/
|
||||
protected static $databaseIdFields = array( 'member_id' );
|
||||
protected static array $databaseIdFields = array( 'member_id' );
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
protected static array $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* Create from form
|
||||
*
|
||||
* @param array|NULL $values Form values
|
||||
* @return \IPS\Poll\Vote
|
||||
* @return Vote
|
||||
*/
|
||||
public static function fromForm( $values )
|
||||
public static function fromForm( array|null $values ): Vote
|
||||
{
|
||||
$vote = new static;
|
||||
$vote->member_id = \IPS\Member::loggedIn()->member_id;
|
||||
$vote->member_id = Member::loggedIn()->member_id;
|
||||
if ( $values )
|
||||
{
|
||||
$vote->member_choices = $values;
|
||||
}
|
||||
$vote->ip_address = \IPS\Request::i()->ipAddress();
|
||||
$vote->ip_address = Request::i()->ipAddress();
|
||||
return $vote;
|
||||
}
|
||||
|
||||
@@ -70,18 +79,18 @@ class _Vote extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
public function setDefaultValues() : void
|
||||
{
|
||||
$this->vote_date = new \IPS\DateTime;
|
||||
$this->vote_date = new DateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set vote date
|
||||
*
|
||||
* @param \IPS\DateTime $value Value
|
||||
* @param DateTime $value Value
|
||||
* @return void
|
||||
*/
|
||||
public function set_vote_date( \IPS\DateTime $value )
|
||||
public function set_vote_date( DateTime $value ) : void
|
||||
{
|
||||
$this->_data['vote_date'] = $value->getTimestamp();
|
||||
}
|
||||
@@ -89,11 +98,11 @@ class _Vote extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get vote date
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_vote_date()
|
||||
public function get_vote_date(): DateTime
|
||||
{
|
||||
return \IPS\DateTime::ts( $this->_data['vote_date'] );
|
||||
return DateTime::ts( $this->_data['vote_date'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +111,7 @@ class _Vote extends \IPS\Patterns\ActiveRecord
|
||||
* @param array $value Value
|
||||
* @return void
|
||||
*/
|
||||
public function set_member_choices( array $value )
|
||||
public function set_member_choices( array $value ) : void
|
||||
{
|
||||
$this->_data['member_choices'] = json_encode( $value );
|
||||
}
|
||||
@@ -110,9 +119,9 @@ class _Vote extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get choices
|
||||
*
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function get_member_choices()
|
||||
public function get_member_choices(): ?array
|
||||
{
|
||||
return isset( $this->_data['member_choices'] ) ? json_decode( $this->_data['member_choices'], TRUE ) : NULL;
|
||||
}
|
||||
@@ -120,10 +129,10 @@ class _Vote extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Set poll
|
||||
*
|
||||
* @param \IPS\Poll $value Value
|
||||
* @param Poll $value Value
|
||||
* @return void
|
||||
*/
|
||||
public function set_poll( \IPS\Poll $value )
|
||||
public function set_poll( Poll $value ) : void
|
||||
{
|
||||
$this->_data['poll'] = $value->pid;
|
||||
}
|
||||
@@ -131,19 +140,19 @@ class _Vote extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get poll
|
||||
*
|
||||
* @return array
|
||||
* @return Poll
|
||||
*/
|
||||
public function get_poll()
|
||||
public function get_poll(): Poll
|
||||
{
|
||||
return \IPS\Poll::load( $this->_data['poll'] );
|
||||
return Poll::load( $this->_data['poll'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
if ( $this->member_choices !== NULL )
|
||||
{
|
||||
@@ -152,7 +161,7 @@ class _Vote extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
if ( isset( $choices[ $k ] ) ) // If the question has been deleted since this vote was cast, this won't be set
|
||||
{
|
||||
if ( \is_array( $v ) )
|
||||
if ( is_array( $v ) )
|
||||
{
|
||||
foreach ( $v as $key => $memberValues )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user