Jump to content

Forums

Search In
  • More options...
Find results that contain...
Find results in...

Block to extract data


Recommended Posts

Good Evening all,

I was wondering if someone with some expert knowledge of php coding and blocks on Invision could assist me. 

I want to create an invision block for the Pages that takes information from the perscom_personnel table where the number within the personnel_administrative_unit_positions column is equal to X (basically, if they are a member of a specific administrative position, list their name).

I then want to show the soldiers full rank, first name, surname ad extract the ID so that I can provide a link to that person.

Example

Anyone within our OACO group (group ID: 22) it will show:

Rank FirstName Surname *Button to PM on forum*
Rank FirstName Surname *Button to PM on forum*

Is this something that is possible?

Link to comment
Share on other sites

  • Administrators

Using a function from our Soldier class roots():

/**
* 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
* @param   bool                $includeDischarged  If you want to include discharged personnel in the returned array
* @return	array
*/
public static function roots( $permissionCheck='view', $member=NULL, $where=array(), $includeDischarged=FALSE )
{
    // Get all the soldiers
    $soldiers = parent::roots( $permissionCheck, $member, $where, $includeDischarged );

    // Get saved discharged and combat unit soldiers
    $status = \IPS\Settings::i()->perscom_settings_personnel_discharge_status;
    $unit = \IPS\Settings::i()->perscom_settings_personnel_discharge_unit;

    // Remove the ones where their status or unit matches the discharge status
    return array_filter( $soldiers, function( $soldier ) use ( $status, $unit ){
    return $soldier->combat_unit->_id == $unit OR $soldier->status->_id == $status ? FALSE : TRUE;
    } );
}

 

For straight up PHP:

$position = INSERT_POSITION_ID_HERE;
foreach ( \IPS\perscom\Personnel\Soldier::roots( 'view', NULL, array( array( \IPS\Db::i()->findInSet( 'personnel_administrative_unit_positions', array( $position ) ) ) ) as $soldier )
{
    // List each soldier
    echo $soldier->_title;
}

Using IPB template syntax:

{{$position = INSERT_POSITION_ID_HERE;}}
{{foreach \IPS\perscom\Personnel\Soldier::roots( 'view', NULL, array( array( \IPS\Db::i()->findInSet( 'personnel_administrative_unit_positions', array( $position ) ) ) ) as $soldier}}
	{$soldier->_title}
{{endforeach}}

I have no actually plugged this in to make sure there's no syntax errors, but I use the same queries within the application, specifically on the administrative frontend rosters.

Owner
Deschutes Design Group LLC
email | jon@deschutesdesigngroup.com

Link to comment
Share on other sites

Hi Jon, thanks for the assistance, apologies for the lateness, we've just transferred all our data to IPS and changed host all in one night lol.

I've tried both of these in a PHP Custom Block, error messages below:

Straight up PHP:

ParseError: syntax error, unexpected 'as' (T_AS), expecting ',' or ')' (0)
#0 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/FormAbstract.php(377): IPS\cms\Blocks\_Block->IPS\cms\Blocks\{closure}('$position = 22;...')
#1 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/TextArea.php(119): IPS\Helpers\Form\_FormAbstract->validate()
#2 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/FormAbstract.php(165): IPS\Helpers\Form\_TextArea->validate()
#3 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/FormAbstract.php(142): IPS\Helpers\Form\_FormAbstract->setValue(true)
#4 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/TextArea.php(66): IPS\Helpers\Form\_FormAbstract->__construct('block_content', '', false, Array, Object(Closure), NULL, NULL, 'block_content')
#5 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/Codemirror.php(68): IPS\Helpers\Form\_TextArea->__construct('block_content', '', false, Array, Object(Closure), NULL, NULL, 'block_content')
#6 /home/sites/6b/5/5faa0124ea/public_html/applications/cms/sources/Blocks/Block.php(668): IPS\Helpers\Form\_Codemirror->__construct('block_content', '', false, Array, Object(Closure), NULL, NULL, 'block_content')
#7 /home/sites/6b/5/5faa0124ea/public_html/system/Node/Controller.php(489): IPS\cms\Blocks\_Block->form(Object(IPS\Helpers\Form))
#8 /home/sites/6b/5/5faa0124ea/public_html/system/Node/Controller.php(388): IPS\Node\_Controller->_addEditForm(Object(IPS\cms\Blocks\Block))
#9 /home/sites/6b/5/5faa0124ea/public_html/system/Dispatcher/Controller.php(85): IPS\Node\_Controller->form()
#10 /home/sites/6b/5/5faa0124ea/public_html/system/Node/Controller.php(62): IPS\Dispatcher\_Controller->execute()
#11 /home/sites/6b/5/5faa0124ea/public_html/applications/cms/modules/admin/pages/blocks.php(39): IPS\Node\_Controller->execute()
#12 /home/sites/6b/5/5faa0124ea/public_html/system/Dispatcher/Dispatcher.php(152): IPS\cms\modules\admin\pages\_blocks->execute()
#13 /home/sites/6b/5/5faa0124ea/public_html/admin/index.php(14): IPS\_Dispatcher->run()
#14 {main}

IPS Syntax:

ParseError: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting '(' (0)
#0 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/FormAbstract.php(377): IPS\cms\Blocks\_Block->IPS\cms\Blocks\{closure}('{{$position = 2...')
#1 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/TextArea.php(119): IPS\Helpers\Form\_FormAbstract->validate()
#2 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/FormAbstract.php(165): IPS\Helpers\Form\_TextArea->validate()
#3 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/FormAbstract.php(142): IPS\Helpers\Form\_FormAbstract->setValue(true)
#4 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/TextArea.php(66): IPS\Helpers\Form\_FormAbstract->__construct('block_content', '', false, Array, Object(Closure), NULL, NULL, 'block_content')
#5 /home/sites/6b/5/5faa0124ea/public_html/system/Helpers/Form/Codemirror.php(68): IPS\Helpers\Form\_TextArea->__construct('block_content', '', false, Array, Object(Closure), NULL, NULL, 'block_content')
#6 /home/sites/6b/5/5faa0124ea/public_html/applications/cms/sources/Blocks/Block.php(668): IPS\Helpers\Form\_Codemirror->__construct('block_content', '', false, Array, Object(Closure), NULL, NULL, 'block_content')
#7 /home/sites/6b/5/5faa0124ea/public_html/system/Node/Controller.php(489): IPS\cms\Blocks\_Block->form(Object(IPS\Helpers\Form))
#8 /home/sites/6b/5/5faa0124ea/public_html/system/Node/Controller.php(388): IPS\Node\_Controller->_addEditForm(Object(IPS\cms\Blocks\Block))
#9 /home/sites/6b/5/5faa0124ea/public_html/system/Dispatcher/Controller.php(85): IPS\Node\_Controller->form()
#10 /home/sites/6b/5/5faa0124ea/public_html/system/Node/Controller.php(62): IPS\Dispatcher\_Controller->execute()
#11 /home/sites/6b/5/5faa0124ea/public_html/applications/cms/modules/admin/pages/blocks.php(39): IPS\Node\_Controller->execute()
#12 /home/sites/6b/5/5faa0124ea/public_html/system/Dispatcher/Dispatcher.php(152): IPS\cms\modules\admin\pages\_blocks->execute()
#13 /home/sites/6b/5/5faa0124ea/public_html/admin/index.php(14): IPS\_Dispatcher->run()
#14 {main}

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.