What to do in PHP and what to do with template programming?

Author Message

Mikael Johansson

Monday 11 July 2005 9:51:27 am

I am writing an extension and I think I'm getting into trouble because I do things that shold be done in PHP in my templates and vice versa. Could someone please explain the general idea?

Template programming is very convenient because all the objects are avaliable directly, but some things don't seem to be possible in the template code (removing nodes, doing SQL queries, etc).

Theoretically everything could be done in PHP I guess, but there is little documentation about it and I don't think it is the eZpublish way.

Mikael Johansson, Sweden

Mikael Johansson

Monday 11 July 2005 9:55:39 am

I'll give you an example just to get started:

I have User groups with some extened attributes (Group phone number, group emiail, etc) and these groups contain users.

I want my group administrator, who has edit rights on one of the groups, to be able to remove users from this group. The administrator does not (can not) have edit rights on the users. This is what I have done so far, but I think I have complicated stuff by doing it all in template programming.

{* removelocation.tpl
/*
 *
 * Input:  nodeID of the location to delete as eZpublish template variable
 * Output: Success or failure of removing the node
 * Result: Node is removed.
 *
 * written by Mikael Johansson, mjo[at]chs.chalmers.se July 2005
*/
*}

{* Check permissions *}
{* 1. Current user.contentobject_id == thenode.contentobject_id
   2. Current user has admin rights on thenode.


*}

{def $permsOK = false}
{def $chscurruser = fetch( 'user', 'current_user' )}
{def $thenode = fetch('content', 'node', hash('node_id', $nodeID))}
{if eq($chscurruser.contentobject_id, $thenode.contentobject_id)}
 user is trying to remove itself from the group. That's ok
{set $permsOK = true}
{/if}

{if $thenode.parent.can_edit}
<div> user is admin for the group. Permissions ok </div>
{set $permsOK = true}
{/if}

{if eq($permsOK, false)}
<div>Insufficient access rights.</div>
{else}
<div>Perms ok, removing...</div>

// CODE HERE FOR REMOVING THE NODE

}


{/if}

Mikael Johansson, Sweden

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 20:47:26
Script start
Timing: Jan 18 2025 20:47:26
Module start 'layout'
Timing: Jan 18 2025 20:47:26
Module start 'content'
Timing: Jan 18 2025 20:47:26
Module end 'content'
Timing: Jan 18 2025 20:47:26
Script end

Main resources:

Total runtime0.7497 sec
Peak memory usage4,096.0000 KB
Database Queries52

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0073 588.1719152.6563
Module start 'layout' 0.00730.0036 740.828139.5078
Module start 'content' 0.01090.7372 780.3359454.9609
Module end 'content' 0.74810.0015 1,235.29698.0938
Script end 0.7496  1,243.3906 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.4714160.0002
Check MTime0.00150.2025160.0001
Mysql Total
Database connection0.00160.216810.0016
Mysqli_queries0.706794.2656520.0136
Looping result0.00060.0800500.0000
Template Total0.689792.020.3448
Template load0.00240.319820.0012
Template processing0.687391.674820.3436
Template load and register function0.00020.028810.0002
states
state_id_array0.00630.841610.0063
state_identifier_array0.00130.178820.0007
Override
Cache load0.00190.2583110.0002
Sytem overhead
Fetch class attribute can translate value0.00050.062410.0005
Fetch class attribute name0.00100.129320.0005
XML
Image XML parsing0.00010.014010.0001
class_abstraction
Instantiating content class attribute0.00000.001720.0000
General
dbfile0.00090.1211100.0001
String conversion0.00000.001640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 7
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs