Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Link Writer Permissions based function in Smarty template

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
TofuWarrior
Smarty Rookie


Joined: 05 Jun 2006
Posts: 18

PostPosted: Mon Jun 05, 2006 9:36 am    Post subject: Link Writer Permissions based function in Smarty template Reply with quote

Hi All,

I am brand new to smarty and am writing a cms system.

I want to use a link writer class that checks the permissions system to see if the current user agent has the correct permission and either displays the appropriate link for that function or displays greyed out placeholder for it.

I have no problem in php of course but I am stumped in smarty. In the linkwriter function I need to use useragentid,permission id, object id and objecttypeid and then also pass it parameteres for the links like what model I am using and any otherparameterss such as target and other stuff for the url.


The problem is that I have to iterate through a wholeload of objects AND a llthe different possible user actions on those objects to crteate a table for the user to use and I cannot see how to set all this stuff in smarty to be passed to the linkwriter function without having to generate some uber array that becaomes the params bit of the function.

This seems like it would be more hassle to create than just coding this stuff in html in the first place and asssgning that html to the template which wouldlet me use smarty forthe framework etc. Which kind of defeats the object of using smarty for me on one level.

Hope this is not too unclear. I can post my linkwriter functikon nup if that willhelp.

Many Thanks,

Paul
_________________
We make a living by what we get.
We make a life by what we give.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Jun 05, 2006 3:50 pm    Post subject: Reply with quote

How do you propose the template user will access/call your function? Are the permissions applicaiton generated or user specified?

Cool nickname btw Wink
Back to top
View user's profile Send private message
TofuWarrior
Smarty Rookie


Joined: 05 Jun 2006
Posts: 18

PostPosted: Tue Jun 06, 2006 1:25 pm    Post subject: Reply with quote

Thanks for the compliment boots Smile
I quite like it (obviously), I was going to go for yoghurtweaver but the domain name was taken.

All the permissions info is in the db so I need ot get it and pass it to the smarty template and then use it in a function.

But the problem is the fact that there are 4 vars that need to be passed to the link writer for it to check the permissions and then on top of that I need to be able to pass information associated with link in question eg text, what model the controller needs to call, any params etc.

Allof which has me in aspin as it seems you can opnly pass one params array to smarty functions.

So I am looking thinking, f** me,the only way to do this is with some uber array and if I am going to build that for every page I mkight as well just do the html in php and pass the chunk into smarty to fit with the rest of the stuff.

Make sense?

Sorry this isn't too clear,hard to describe.
Thanks for taking the time to look.My PHP is pretty sound my smarty is very Nu as I believe is the current teen metal vernacular Wink

Thanks,

TW
_________________
We make a living by what we get.
We make a life by what we give.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Jun 06, 2006 2:42 pm    Post subject: Reply with quote

TofuWarrior wrote:
Allof which has me in aspin as it seems you can opnly pass one params array to smarty functions.


Not at all, functions only get one parameter array -- but it represents all of the parameters specified by the plugin.

I guess I'm probabally not really seeing where the difficulty is. Have you actually tried to implement this? Even if you are still struggling with it, at least then we could talk about some specific problematic code Wink
Back to top
View user's profile Send private message
TofuWarrior
Smarty Rookie


Joined: 05 Jun 2006
Posts: 18

PostPosted: Wed Jun 07, 2006 8:59 am    Post subject: Reply with quote

I did and got in a mess and have moved on to the permissions system admin side. I will get back on it and see how I get on. But am I right that you canonly pass params, and smarty to a function and that all your params need to be in the params array?

Thanks for your help boots.


Cheers,

TW
_________________
We make a living by what we get.
We make a life by what we give.
Back to top
View user's profile Send private message
TofuWarrior
Smarty Rookie


Joined: 05 Jun 2006
Posts: 18

PostPosted: Wed Jun 07, 2006 11:51 am    Post subject: Reply with quote

Hi Boots,

so this is my stripped down plugin.
Code:

 function smarty_function_access_link_write($params, &$smarty)
 {
    $canDo = PermissionsManager::CanDo($params['perm'],$params['object'],$params['agent'],$params['type']);   
    if($canDo===true){
     $this->output ='Link';
    } else {
        $this->output ='GreyLink';
    }
    return $this->output;
 }


And the problem I have is this. I am trying to output, for example, a table of a list of Files and along the row from each file is a series of links, Open, edit, delete etc etc. I need to call this link writer for each of those functions for each of the files and it to check the permissions manager for each of those functions and then display either a greyed out link or the fulllink.

Ignoring how I get the link details for the time being as it is a similar problem I think, The details of each link are determined by the permission id $params['perm'],and the type id $perms['type'].The perm id will be different for every cell in a row. but will be consistently the same in each column as you go down rows,if that makes sense.

Now I cannot see how I can get this to work without setting a big fat multidimensional array and assigning it as the $params of this function and in this case it seems like I would be better off just producing the table in php where I can call all my functions vars and constants nice and easily and then dump it into smarty.

Make sense?

Cheers,

TW
_________________
We make a living by what we get.
We make a life by what we give.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jun 07, 2006 3:37 pm    Post subject: Reply with quote

yes, seems tricky because of the column constraint. If you don't do something programmatic and leave the layout of columns to the template, then you will somehow have to indicate to the plugin which column is being used. So there doesn't seem to be an obvious way around it (at least to me) under your regime.

Perhaps {html_table} can be an inspiration for you. It essentially does build a complete table in PHP (as you propose to do), but packages itself as a simple tag. You may also be able to do something with block plugins but I suspect it would be difficult to accomplish (if possible at all) and probably not worth the effort to find out.

Sorry I couldn't be more helpful here.
Back to top
View user's profile Send private message
TofuWarrior
Smarty Rookie


Joined: 05 Jun 2006
Posts: 18

PostPosted: Wed Jun 07, 2006 3:51 pm    Post subject: Reply with quote

NO worries boots.

Thanks for looking.

If i get time to work this out I will post back here.

The linkwriter kind of looks back in the process so it does make things tricky really.

never mind, nice to know I am pushing some kind of boundary Smile
I hope it isn'tthe 'bad design'boundary Smile

TW
_________________
We make a living by what we get.
We make a life by what we give.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP