Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
+123
-15
@@ -20,12 +20,17 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
/**
|
||||
* Profile Step Model
|
||||
*/
|
||||
class _ProfileStep extends \IPS\Patterns\ActiveRecord
|
||||
class _ProfileStep extends \IPS\Node\Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
@@ -41,6 +46,26 @@ class _ProfileStep extends \IPS\Patterns\ActiveRecord
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'step_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'profile_completion';
|
||||
|
||||
/**
|
||||
* @brief [Node] Sortable
|
||||
*/
|
||||
public static $nodeSortable = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Positon Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'profile_step_title_';
|
||||
|
||||
/**
|
||||
* Load Record
|
||||
@@ -57,14 +82,11 @@ class _ProfileStep extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
if ( $idField === NULL AND $extraWhereClause === NULL )
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->profileSteps ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->profileSteps = iterator_to_array( \IPS\Db::i()->select( '*', 'core_profile_steps' )->setKeyField( 'step_id' ) );
|
||||
}
|
||||
$steps = static::getStore();
|
||||
|
||||
if ( isset( \IPS\Data\Store::i()->profileSteps[ $id ] ) )
|
||||
if ( isset( $steps[ $id ] ) )
|
||||
{
|
||||
return static::constructFromData( \IPS\Data\Store::i()->profileSteps[ $id ] );
|
||||
return static::constructFromData( $steps[ $id ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -76,6 +98,63 @@ class _ProfileStep extends \IPS\Patterns\ActiveRecord
|
||||
return parent::load( $id, $idField, $extraWhereClause );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Return the custom badge for each row
|
||||
*
|
||||
* @return NULL|array Null for no badge, or an array of badge data (0 => CSS class type, 1 => language string, 2 => optional raw HTML to show instead of language string)
|
||||
*/
|
||||
protected function get__badge()
|
||||
{
|
||||
if( $this->required )
|
||||
{
|
||||
return array( 0 => 'positive ipsPos_right', 1 => 'required' );
|
||||
}
|
||||
|
||||
return parent::get__badge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data store
|
||||
*
|
||||
* @return array
|
||||
* @note Note that all records are returned, even disabled promotion rules. Enable status needs to be checked in userland code when appropriate.
|
||||
*/
|
||||
public static function getStore()
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->profileSteps ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->profileSteps = iterator_to_array( \IPS\Db::i()->select( '*', 'core_profile_steps', NULL, "step_position ASC" )->setKeyField( 'step_id' ) );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->profileSteps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch All Root Nodes
|
||||
*
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param mixed $where Additional WHERE clause
|
||||
* @return array
|
||||
*/
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array() )
|
||||
{
|
||||
if ( !count( $where ) )
|
||||
{
|
||||
$return = array();
|
||||
foreach( static::getStore() AS $node )
|
||||
{
|
||||
$return[ $node['step_id'] ] = static::constructFromData( $node );
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::roots( $permissionCheck, $member, $where );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Changed Columns
|
||||
@@ -176,6 +255,8 @@ class _ProfileStep extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
}
|
||||
|
||||
$steps = static::setOrder( $steps );
|
||||
|
||||
foreach( $steps as $key => $object )
|
||||
{
|
||||
if ( $nextOneIsIt )
|
||||
@@ -200,13 +281,9 @@ class _ProfileStep extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public static function loadAll()
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->profileSteps ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->profileSteps = iterator_to_array( \IPS\Db::i()->select( '*', 'core_profile_steps' )->setKeyField( 'step_id' ) );
|
||||
}
|
||||
|
||||
$return = array();
|
||||
foreach( \IPS\Data\Store::i()->profileSteps AS $id => $data )
|
||||
|
||||
foreach( static::getStore() AS $id => $data )
|
||||
{
|
||||
$return[ $id ] = static::constructFromData( $data );
|
||||
}
|
||||
@@ -449,6 +526,16 @@ class _ProfileStep extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
if ( !$this->id )
|
||||
{
|
||||
/* Set initial position to the end of the list and save initial data */
|
||||
try
|
||||
{
|
||||
$this->position = \IPS\Db::i()->select( 'MAX(step_position)', 'core_profile_steps' )->first() + 1;
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
$this->position = 1;
|
||||
}
|
||||
|
||||
$this->save();
|
||||
}
|
||||
|
||||
@@ -577,13 +664,13 @@ class _ProfileStep extends \IPS\Patterns\ActiveRecord
|
||||
* @param \IPS\Application $app The application being deleted
|
||||
* @return void
|
||||
*/
|
||||
public function deleteByApplication( \IPS\Application $app )
|
||||
public static function deleteByApplication( \IPS\Application $app )
|
||||
{
|
||||
$iterator = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_profile_steps' ), '\IPS\Member\ProfileStep' );
|
||||
|
||||
foreach( $iterator as $step )
|
||||
{
|
||||
list( $application, $extension ) = explode( '_', $this->_data['extension'] );
|
||||
list( $application, $extension ) = explode( '_', $step->_data['extension'] );
|
||||
|
||||
if ( $application == $app->directory )
|
||||
{
|
||||
@@ -591,4 +678,25 @@ class _ProfileStep extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array of wizard steps, reorder them based on AdminCP order
|
||||
*
|
||||
* @param array $steps Wizard steps
|
||||
* @return array
|
||||
*/
|
||||
public static function setOrder( $steps )
|
||||
{
|
||||
$finalSteps = array();
|
||||
|
||||
foreach( array_keys( static::loadAll() ) as $id )
|
||||
{
|
||||
if( isset( $steps['profile_step_title_' . $id ] ) )
|
||||
{
|
||||
$finalSteps['profile_step_title_' . $id ] = $steps['profile_step_title_' . $id ];
|
||||
}
|
||||
}
|
||||
|
||||
return $finalSteps;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user