Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
aXenDev Posted July 7, 2019 Posted July 7, 2019 Hey, I would like to add group sorting to my plugin. Based on the possibility of sorting from this plugin: I added the settings accordingly and led the plug to the state of operation as in the "Group Name Indicator". I added sorting in php: public function SecondaryGroupsIndicator() { try { $groups = array(); $selectedGroups = explode( ',', \IPS\Settings::i()->ips1s2ktest ); if ( \count( $selectedGroups ) ) { foreach( $selectedGroups as $groupId ) { if( \array_key_exists( $groupId, \IPS\Member\Group::groups() ) ) { $groups[] = \IPS\Member\Group::load( $groupId ); } } } return $groups; } } And then I added to the template: {{$groups = \IPS\Member::loggedIn()->SecondaryGroupsIndicator();}} {{foreach $groups as $group}} {$group->formattedName|raw} {{endforeach}} And I have no idea how to connect the code that displays subgroups for me: {{$secondaryGroups = [];}} {{foreach explode(',', $comment->author()->mgroup_others) as $secondaryGroup}} {{$secondaryGroups[] = \IPS\Member\Group::load($secondaryGroup)->formattedName;}} {{endforeach}} <li>{expression="implode('<br> ', $secondaryGroups)" raw="true"}</li> Do you have any ideas to connect this?
newbie LAC Posted July 8, 2019 Posted July 8, 2019 Hello, Hook in \IPS\Member public function sortedGroups() { $allGroups = \IPS\Member\Group::groups(); $ips1s2ktest = explode(',', \IPS\Settings::i()->ips1s2kSGI); $otherGroups = array_flip(explode(',', $this->mgroup_others)); $sortedGroups = array(); $notSortedGroups = array(); foreach ($ips1s2ktest as $id) { if (isset($allGroups[$id]) and isset($otherGroups[$id])) { $sortedGroups[$id] = $allGroups[$id]; unset($otherGroups[$id]); } } foreach ($otherGroups as $sid => $i) { if (isset($allGroups[$sid])) { $notSortedGroups[$sid] = $allGroups[$sid]; } } return ($sortedGroups + $notSortedGroups); } Then use In the profile {{if $member->sortedGroups()}} {{foreach $member->sortedGroups() as $group}} {$group->formattedName|raw} {{endforeach}} {{endif}} In the post {{if $comment->author()->sortedGroups()}} {{foreach $comment->author()->sortedGroups() as $group}} {$group->formattedName|raw} {{endforeach}} {{endif}}
aXenDev Posted July 8, 2019 Author Posted July 8, 2019 @newbie LAC I inserted the code as you say, but nothing is happening when editing the group space. I just changed the key to: \IPS\Settings::i()->ips1s2kSGI
aXenDev Posted July 8, 2019 Author Posted July 8, 2019 8 hours ago, newbie LAC said: In the profile {{if $member->sortedGroups()}} {{foreach $member->sortedGroups() as $group}} {$group->formattedName|raw} {{endforeach}} {{endif}} I need to put commas between groups. I wanted to add it like this: {{$group = [];}} {{foreach $member->sortedGroups() as $group}} {expression="implode(', ', $group)" raw="true"} {$group->formattedName|raw} {{endforeach}} But I have a message: "implode(): Invalid arguments passed"
newbie LAC Posted July 9, 2019 Posted July 9, 2019 13 hours ago, krystek1s2k said: I need to put commas between groups. I wanted to add it like this: {{$group = [];}} {{foreach $member->sortedGroups() as $group}} {expression="implode(', ', $group)" raw="true"} {$group->formattedName|raw} {{endforeach}} But I have a message: "implode(): Invalid arguments passed" {{$groups = [];}} {{foreach $member->sortedGroups() as $group}} {{$groups[] = $group->formattedName;}} {{endforeach}} {expression="implode(', ', $groups)" raw="true"} or all in one line {expression="implode(', ', array_map(function($group) { return $group->formattedName; }, $member->sortedGroups()))" raw="true"}
bfarber Posted July 9, 2019 Posted July 9, 2019 Or, perhaps, a better option is to use the built in list formatting functionality we have. {expression="\IPS\Member::loggedIn()->language()->formatList( array_map(function($group) { return $group->formattedName; }, $member->sortedGroups()) )" raw="true"}
newbie LAC Posted July 10, 2019 Posted July 10, 2019 15 hours ago, bfarber said: Or, perhaps, a better option is to use the built in list formatting functionality we have. In that case the output will be Members, Moderators and VIP But OP need On 7/8/2019 at 8:11 PM, krystek1s2k said: I need to put commas between groups. You should to use 2nd param /** * Format List * Takes an array and returns a string, appropriate for the language (e.g. "a, b and c") * * Relies on the _list_format_ language string which should be an example list of three items using the keys a, b and c. * Any can be capitalised to run ucfirst on that item * * Examples if $items = array( 'foo', 'bar', 'baz', 'moo' ); * If _list_format_ is this: Output will be this: * a, b and c foo, bar, baz and moo * A, B und C Foo, Bar, Baz und Moo * a; b; c. foo; bar; baz; moo. * * @param array $items The items for the list * @param string $format If provided, will override _list_format_ * @return string */ public function formatList( $items, $format=NULL ) {expression="\IPS\Member::loggedIn()->language()->formatList( array_map(function($group) { return $group->formattedName; }, $member->sortedGroups()), 'a, b, c' )" raw="true"}
Recommended Posts
Archived
This topic is now archived and is closed to further replies.