Jump to content

Creating Basic Smarty Tags + Access to Variables


jarod

Recommended Posts

I'm creating an admin hook and I have two questions.

 

How can I pull the current admin user role id?

 

I need to know how I can grab the
$roleId
of the current admin user.

 

How do I create a smarty tag that can be used throughout the admin area?

 

I want to use a smarty tag to control where this is output. If I echo something right now it dumps it into the top of the page before <html>...

 


 

I've started my hook with this snippet:

 

add_hook('AdminAreaPage', 1, function($vars) {
   if ($vars['adminid'] == '3') {
	// Do Awesome Stuff		
   }
});	

Link to comment
Share on other sites

How can I pull the current admin user role id?

I need to know how I can grab the
$roleId
of the current admin user.

the usual two ways - either query the database or use the class documentation. :)

 

I want to use a smarty tag to control where this is output. If I echo something right now it dumps it into the top of the page before <html>...

i'm sure if you search the forums for 'adminareapage', you'll find lots of example hooks that will help you... e.g the hook below creates a new variable in the admin area... :idea:

 

https://forum.whmcs.com/showthread.php?115031-Show-active-tickets-count-at-top-of-page&p=465459#post465459

Link to comment
Share on other sites

  • 3 months later...

Thank you, Brian.

 

Can you provide a working db query example for grabbing the roleid?

 

Also, how can I use this in a smarty variable? I'm familiar with $smarty.session.adminid, but what about roleid? I can't dig anything up on the web that covers it.

Link to comment
Share on other sites

Can you provide a working db query example for grabbing the roleid?

in v7.2, you could query the database like this...

 

<?php

# Get Admin Roleid (using Capsule).
# Written by brian!

use Illuminate\Database\Capsule\Manager as Capsule;

function admin_roleid_capsule_hook($vars) 
{
   $adminid = $vars['adminid'];
   $roleid = Capsule::table('tbladmins')
               ->where('id', $adminid)
               ->value('roleid');

   return array("roleid1" => $roleid);
}
add_hook("AdminAreaPage", 1, "admin_roleid_capsule_hook");
?>

that will give you a Smarty variable {$roleid1} that you can use anywhere in the template. :idea:

and if you want to do magical things with the value, then you can... and then output the result of that back to the template by returning the variable.

 

or if you want to use the Class method...

 

<?php

# Get Admin Roleid (using Class).
# Written by brian!

use WHMCS\User\Admin;

function admin_roleid_class_hook($vars) 
{
   $admin = Admin::find($vars['adminid']);
   $roleid = $admin->roleId;

   return array("roleid2" => $roleid);
}
add_hook("AdminAreaPage", 1, "admin_roleid_class_hook");
?>

similarly, that will give you a {$roleid2} Smarty variable - hopefully if you run both hooks together, the values should be exactly the same! praying.gif

 

Also, how can I use this in a smarty variable? I'm familiar with $smarty.session.adminid, but what about roleid? I can't dig anything up on the web that covers it.

either of the above methods should give you a Smarty variable that you can use - obviously, you won't need to use both hooks, just whichever one suits your needs.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated