This is what I have done to extrapage.php so far oachegroup.org/extrapage
If the links are to documents hosted in the same area of the same server what would the code look like to make them work, please? <a href="http://oachegroup.org/bylaws" title="OACHE By-Laws">
And in each case, to point back to the source ExtraPage so they choose again from the 5 options? <a href="http://oachegroup.org/extrapage.php" title="To Return to the Prior Page">
This is what I have done to extrapage.php so far oachegroup.org/extrapage
If the links are to documents hosted in the same area of the same server what would the code look like to make them work, please? <a href="http://oachegroup.org/bylaws" title="OACHE By-Laws">
And in each case, to point back to the source ExtraPage so they choose again from the 5 options? <a href="http://oachegroup.org/extrapage.php" title="To Return to the Prior Page">
I figured I give you a possible example of a role based "About Page"
here is an attached example of how you could have one about page that displays different info based on a users role. You would need to adjust it to use the role names you want and the info. But it should give you an idea.
unzip it and place this file in the plugins/ExtraPage/views
obviously there are many ways to to do this some cleaner then others. But this will work for displaying different info for different roles.
If you want additional help with this plugin, you can send a donation for the existing code, and I might be able to help further, depending on your needs. Otherwise, you can try other plugins and other suggestions.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Hi @Peregrine, You are my teacher! I looked at the page and figured our that the magic is in these lines:
$Session = Gdn::Session();
$RoleArray = Gdn::UserModel()->GetRoles($Session->UserID)->ResultArray();
$Roles = ConsolidateArrayValuesByKey($RoleArray, 'Name');
if (in_array('name of a role', $Roles))
...do something for that role...
}
While your example placed these lines in extrapage.php, I am wondering whether I could instead place the lines in the plugin's default.php in the "public function Base_Render_Before($Sender)" functions and then instead of adding the "extrapage" to the menu, to add a different page name to the menu where the page name is derived from (or includes) the role. Then what I'll have to do is create as many pages as roles.
If you say that the above makes sense I'll join programmers anonymous;-)
Three complications:
1. A user may have more than one role, so I may want to add more than one menu option. How do I loop through all his roles to do that?
2. How to name the menu pages (since there may be more than one and the menu options need to be named)
3. Since I don't necessarily want to create a page for each role (e.g. no sense to create one for the administrator role), how do I verify that such a page exists (and if not, not adding that menu option that would otherwise result in a "page not found").
Thanks!
you did see the last sentence in my comment. but did you understand it?
you just use the same basic routine to obtain roles.
1) http://www.w3schools.com/php/php_looping_for.asp
2) put if conditional role addlink in the loop and give it a variable name
foreach ($Roles as $therole)
{
code to be executed;
if ($therole == "roleA" ) {
addliink .....
}
if ($therole == "roleB" ) {
addliink .....
}
etc.
}
look at php.net and php tutorials on web.
however, basicpages app now has the permissions.
you could if you desire to make an unconditional donation NOW (meaning pay up front prior to release) to @shadowdare in lieu of a donation to me within 24hours so @hgtonight will match it.
once you figure basics of php from a php primer. post your code and we can try to help.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@Peregrine, @hgtonight: As you may have noticed, I pledged to @Shadowdare's project and I was able to do so because there is this time gap between pledging and paying... I need that gap to get the Paypal set up by accounting. For a while I planned to donate to each of you great guys who helped my in my research on using Vanilla for our planned project, waiting to have the Paypal account set up.
But @peregrine's note about @hgtonight's matching within 24 hours trumps my plan so if it is acceptable, I'd like to "pledge to donate" $20 to each of you once the account is set up. @hgtonight: perhaps you will find this acceptable my promise as valid for your matching.
On related subject -- would have been nice to see a "Donation Guidelines".
@rbrahmson said:
hgtonight: perhaps you will find this acceptable my promise as valid for your matching.
Sounds good.
@rbrahmson said:
On related subject -- would have been nice to see a "Donation Guidelines".
Donations are just that, donations. You get to decide if anything is worth donating to. I, personally, donate to authors who a) have a donation button in at least one of their plugins that I use, b) release "difficult" plugins that help me grow as a dev or c) A valuable contributor to the community. I very often donate my time to projects I like.
As far as the problem at hand, I think putting the role selection logic in each custom page makes the most sense. You don't have to be selective with what links you add, and all the different versions are in the same file. I personally would suggest using an else-if block to ensure only one version of the page gets shown. It is also easy to determine a priority in those types of blocks.
Updated to version 3.0 with options for 3 extra pages.
a few examples for role-based display inside the extrapages. you can also use the same routines to modify the link display based on roles in the default.php. example for showing user photo and useranchor as well.
you can also see shadowdare's basicpages app - or Custom Pages app or any other number of similar plugins, whichever you like better
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Hi @Peregrine,
Looked at your newer version and tried to add some minimal logic to name the extra pages based on the role. Didn't work, so I went back to the original source and added some primitive debugging to see the values in the variables (I'm sure you would be shocked at my way of debugging), and they do not seem to contain what I expected out of your code. Could it be that a mortal like me uncovered an error among the gods? Here is the code in default.php:
// uncomment below if you want to test for a role before adding link. then test for roles in the role array.
$RoleArray = Gdn::UserModel()->GetRoles($Session->UserID)->ResultArray();
$Roles = ConsolidateArrayValuesByKey($RoleArray, 'Name');
$WhichPages = C('Plugins.ExtraPage.WhichPages');
Echo '<br>RB:$WhichPages='.$WhichPages;
Echo '<br>RB:$RoleArray='.$RoleArray;
Echo '<br>RB:$Roles='.$Roles;
foreach ($Roles as $Therole)
{
Echo '<br>RB:$Therole='.$Therole;
}
The output I get on the screen is:
RB:$WhichPages=All
RB:$RoleArray=Array
RB:$Roles=Array
So $WhichPages=All is not surprising. But the values of the following variables do surprise me because I was expecting to see the names of the roles. Needless to day, it seems that the Echo in the foreach loop does not produce anything...
And adding to this, I want to check if the html file exists and if not to skip adding it to the menu bar. I figured how to do the "if" code (hurray!) but how to verify that the html file exist is something I need your guidance... Maybe at the end of this journey I'll end up improving your plugin;-)
Try using the function decho() instead of echo when you are debugging. You'll see the values of arrays, too. And furthermore, decho only outputs if the user is admin, so no user will see your debugging garbage
Echoing a variable tells PHP to cast that variable to a string. An array cast to a string becomes 'Array' as you noticed. If you actually want to see what is in a variable, I suggest you use var_dump($Variable) in the future.
@R_J said:
Try using the function decho() instead of echo when you are debugging. You'll see the values of arrays, too. And furthermore, decho only outputs if the user is admin, so no user will see your debugging garbage
Came here to say this. It is a really nice wrapper for var_dump! You can even pass in a title for multiple lines, ala decho($WhichPages, 'WhichPages');
EDIT - We cross-posted. You are still casting your variable to a string. You need to pass in the variable itself. decho($Variable);.
Thanks!!! So I think the following proves an error within the plugin not retrieving the roles.
My debugging code:
// uncomment below if you want to test for a role before adding link. then test for roles in the role array.
$RoleArray = Gdn::UserModel()->GetRoles($Session->UserID)->ResultArray();
$Roles = ConsolidateArrayValuesByKey($RoleArray, 'Name');
$WhichPages = C('Plugins.ExtraPage.WhichPages');
decho ('RB:master of primitive debugging');
decho ($WhichPages);
decho ($RoleArray);
decho ($Roles);
foreach ($Roles as $Therole)
{
decho ('RB:In the for loop'); decho($Therole);
}
and the results:
DEBUG: RB:master of primitive debugging
DEBUG: All
DEBUG: Array
(
)
DEBUG: Array
(
)
There must be something else wrong here. None of these work. Here is the code again with var_dump:
// uncomment below if you want to test for a role before adding link. then test for roles in the role array.
$RoleArray = Gdn::UserModel()->GetRoles($Session->UserID)->ResultArray(); //Original
decho ('<B>RB:$RoleArray1'); var_dump($RoleArray);
$RoleArray = Gdn::UserModel()->GetRoles($Session->User->UserID)->ResultArray(); // R_J suggestion #1
decho ('<B>RB:$RoleArray2'); var_dump($RoleArray);
$RoleArray = Gdn::UserModel()->GetRoles($Session->User)->ResultArray();// R_J suggestion #2
decho ('<B>RB:$RoleArray3'); var_dump($RoleArray);
$Roles = ConsolidateArrayValuesByKey($RoleArray, 'Name');
$WhichPages = C('Plugins.ExtraPage.WhichPages');
decho ('RB:master of primitive debugging');
var_dump ($WhichPages);
var_dump ($RoleArray);
var_dump ($Roles);
foreach ($Roles as $Therole)
{
decho ('RB:In the for loop'); var_dump($Therole);
}
Well, I'm just the victim here;-))) The source of Peregrine's latest version has this:
<?php if(!defined('APPLICATION')) die();
$PluginInfo['ExtraPage'] = array(
'Name' => 'ExtraPage',
'Description' => 'simple plugin to add extra page or 2 extra pages or 3 extrapages - option for modules in panel. Examples of role-based dispaly and userphoto and user anchor provided',
'Version' => '3.0',
'SettingsUrl' => '/dashboard/settings/extrapage',
'Author' => "Peregrine",
'MobileFriendly' => TRUE,
);
class ExtraPagePlugin extends Gdn_Plugin {
public function Base_Render_Before($Sender) {
// uncomment line below if you only want to show option to logged in users
// if (!Gdn::Session()->IsValid()) return;
// $Session = Gdn::Session();
// uncomment below if you want to test for a role before adding link. then test for roles in the role array.
// $RoleArray = Gdn::UserModel()->GetRoles($Session->UserID)->ResultArray();
// $Roles = ConsolidateArrayValuesByKey($RoleArray, 'Name');
So all I did was to follow the commented advice to un-comment these lines...The rest is history where a mortal proved that gods can err;-)
Still, the mortal has no clue how to fix it...Appreciate any help.
Comments
This is what I have done to extrapage.php so far oachegroup.org/extrapage
If the links are to documents hosted in the same area of the same server what would the code look like to make them work, please?
<a href="http://oachegroup.org/bylaws" title="OACHE By-Laws">
And in each case, to point back to the source ExtraPage so they choose again from the 5 options?
<a href="http://oachegroup.org/extrapage.php" title="To Return to the Prior Page">
This is what I have done to extrapage.php so far oachegroup.org/extrapage
If the links are to documents hosted in the same area of the same server what would the code look like to make them work, please?
<a href="http://oachegroup.org/bylaws" title="OACHE By-Laws">
And in each case, to point back to the source ExtraPage so they choose again from the 5 options?
<a href="http://oachegroup.org/extrapage.php" title="To Return to the Prior Page">
@rbrahmson
I figured I give you a possible example of a role based "About Page"
here is an attached example of how you could have one about page that displays different info based on a users role. You would need to adjust it to use the role names you want and the info. But it should give you an idea.
unzip it and place this file in the plugins/ExtraPage/views
obviously there are many ways to to do this some cleaner then others. But this will work for displaying different info for different roles.
If you want additional help with this plugin, you can send a donation for the existing code, and I might be able to help further, depending on your needs. Otherwise, you can try other plugins and other suggestions.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Hi @Peregrine, You are my teacher! I looked at the page and figured our that the magic is in these lines:
While your example placed these lines in extrapage.php, I am wondering whether I could instead place the lines in the plugin's default.php in the "public function Base_Render_Before($Sender)" functions and then instead of adding the "extrapage" to the menu, to add a different page name to the menu where the page name is derived from (or includes) the role. Then what I'll have to do is create as many pages as roles.
If you say that the above makes sense I'll join programmers anonymous;-)
Three complications:
1. A user may have more than one role, so I may want to add more than one menu option. How do I loop through all his roles to do that?
2. How to name the menu pages (since there may be more than one and the menu options need to be named)
3. Since I don't necessarily want to create a page for each role (e.g. no sense to create one for the administrator role), how do I verify that such a page exists (and if not, not adding that menu option that would otherwise result in a "page not found").
Thanks!
@rbrahmson
you did see the last sentence in my comment. but did you understand it?
you just use the same basic routine to obtain roles.
look at php.net and php tutorials on web.
however, basicpages app now has the permissions.
you could if you desire to make an unconditional donation NOW (meaning pay up front prior to release) to @shadowdare in lieu of a donation to me within 24hours so @hgtonight will match it.
once you figure basics of php from a php primer. post your code and we can try to help.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@Peregrine, @hgtonight: As you may have noticed, I pledged to @Shadowdare's project and I was able to do so because there is this time gap between pledging and paying... I need that gap to get the Paypal set up by accounting. For a while I planned to donate to each of you great guys who helped my in my research on using Vanilla for our planned project, waiting to have the Paypal account set up.
But @peregrine's note about @hgtonight's matching within 24 hours trumps my plan so if it is acceptable, I'd like to "pledge to donate" $20 to each of you once the account is set up. @hgtonight: perhaps you will find this acceptable my promise as valid for your matching.
On related subject -- would have been nice to see a "Donation Guidelines".
Sounds good.
Donations are just that, donations. You get to decide if anything is worth donating to. I, personally, donate to authors who a) have a donation button in at least one of their plugins that I use, b) release "difficult" plugins that help me grow as a dev or c) A valuable contributor to the community. I very often donate my time to projects I like.
If you are looking to pay for development of a new feature, @hbf wrote a quick guide to sponsoring plugin changes/development here: http://homebrewforums.net/plugin/page/customplugins
As far as the problem at hand, I think putting the role selection logic in each custom page makes the most sense. You don't have to be selective with what links you add, and all the different versions are in the same file. I personally would suggest using an else-if block to ensure only one version of the page gets shown. It is also easy to determine a priority in those types of blocks.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Updated to version 3.0 with options for 3 extra pages.
a few examples for role-based display inside the extrapages. you can also use the same routines to modify the link display based on roles in the default.php. example for showing user photo and useranchor as well.
you can also see shadowdare's basicpages app - or Custom Pages app or any other number of similar plugins, whichever you like better
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Hi @Peregrine,
Looked at your newer version and tried to add some minimal logic to name the extra pages based on the role. Didn't work, so I went back to the original source and added some primitive debugging to see the values in the variables (I'm sure you would be shocked at my way of debugging), and they do not seem to contain what I expected out of your code. Could it be that a mortal like me uncovered an error among the gods? Here is the code in default.php:
The output I get on the screen is:
So $WhichPages=All is not surprising. But the values of the following variables do surprise me because I was expecting to see the names of the roles. Needless to day, it seems that the Echo in the foreach loop does not produce anything...
And adding to this, I want to check if the html file exists and if not to skip adding it to the menu bar. I figured how to do the "if" code (hurray!) but how to verify that the html file exist is something I need your guidance... Maybe at the end of this journey I'll end up improving your plugin;-)
Try using the function decho() instead of echo when you are debugging. You'll see the values of arrays, too. And furthermore, decho only outputs if the user is admin, so no user will see your debugging garbage
Thanks @R_J: did that and not surpisingly same results. Code is:
Results are:
Echoing a variable tells PHP to cast that variable to a string. An array cast to a string becomes 'Array' as you noticed. If you actually want to see what is in a variable, I suggest you use
var_dump($Variable)
in the future.Came here to say this. It is a really nice wrapper for var_dump! You can even pass in a title for multiple lines, ala
decho($WhichPages, 'WhichPages');
EDIT - We cross-posted. You are still casting your variable to a string. You need to pass in the variable itself.
decho($Variable);
.Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Thanks!!! So I think the following proves an error within the plugin not retrieving the roles.
My debugging code:
and the results:
Oops, pasted the wrong results (not that is matters). The results are:
DEBUG: RB:master of primitive debugging
DEBUG: All
DEBUG: Array
(
)
DEBUG: Array
(
)
I think $Session gives back the User, so you would need to do the following:
$RoleArray = Gdn::UserModel()->GetRoles($Session->User->UserID)->ResultArray();
And if that doesn't work, try
$RoleArray = Gdn::UserModel()->GetRoles($Session->User)->ResultArray();
There must be something else wrong here. None of these work. Here is the code again with var_dump:
and the results:
DEBUG: RB:$RoleArray1
array(0) { }
DEBUG: RB:$RoleArray2
array(0) { }
DEBUG: RB:$RoleArray3
array(0) { }
DEBUG: RB:master of primitive debugging
string(3) "All" array(0) { } array(0) { }
could it be that the problem is where the code is placed in default.php?
It is right after these lines:
If it is placed right after that line, there is no place for
$Session = Gdn::Session();
...Change
decho ('<B>RB:$RoleArray1'); var_dump($RoleArray);
todecho($RoleArray, 'RoleArray1');
That's what decho() is good for.
Well, I'm just the victim here;-))) The source of Peregrine's latest version has this:
So all I did was to follow the commented advice to un-comment these lines...The rest is history where a mortal proved that gods can err;-)
Still, the mortal has no clue how to fix it...Appreciate any help.