Snippet: Template logic to add edit button into your custom user siteaccess design

From: Rappy and Zurgutt

Date: 11-16-2005 07:52:30

Question (Rappy): Anyhow, can someone point me to the place where I can read about how to make an edit-button on the site (that is visible when a user with the correct roles are logged in)

Answere (zrg): you have come to the master :) hang on ill give codesnippet. It has the added possibility of limiting number of objects in each class for given usergroup. Its nice for like mini hosting-plan, “you get to make 5 forums, if you want more, $$”. Unfortunately there seems not to be function to CHECK for existence of ini value, so code below will spam error log.. im open to suggestions. Needless to say it only removes creation choice, no actual access security..

This goes to ini in my case to limit Guest users (group 12) to only one blog each (blog container id 31)

<?php /* #?ini charset="utf8"?

[PerGroupClassLimits]
ClassLimit_12_31=1

*/ ?>

eZ template source code

{let node=fetch( content, node, hash( node_id, $module_result.node_id ) )
     current_user=fetch( user, current_user )
     user_group_id=$current_user.contentobject.main_parent_node_id
}
<div id="quickedit">
  <div class="buttonblock">
    <form method="post" action={concat("/content/action/", $node.object.id)|ezurl}>
    {section show=$node.object.can_edit}
      <input type="hidden" name="ContentNodeID" value="{$node.object.main_node_id}" />
      <input type="hidden" name="ContentObjectID" value="{$node.object.id}" />
      <input class="button" type="submit" name="EditButton" value="{'Edit'|i18n('design/standard/node/view')}" />
      <input class="button" type="submit" name="ActionRemove" value="{'Remove'|i18n('design/standard/node/view')}" />
      <br>
    {/section}
 
    {def $limited_list=array()}
    {section var=class loop=$node.object.can_create_class_list}
      {def $limit=ezini( 'PerGroupClassLimits', concat('ClassLimit_', $user_group_id, '_', $class.id), 'limits.ini' )}
      {if not($limit)}
        {set $limited_list=merge($limited_list, array($class))}
      {else}
        {def $existing=fetch( 'content', 'object_count_by_user_id', hash( 'class_id', $class.id, 'user_id',  $current_user.contentobject_id ) ) }
        {if gt($limit, $existing)}
          {set $limited_list=merge($limited_list, array($class))}
        {/if}
      {/if}
    {/section}
    
    {section show=count($limited_list)}
      <br>
      <input type="hidden" name="NodeID" value="{$node.node_id}" />
      <select name="ClassID">
      {section var=class loop=$limited_list}
        <option value="{$class.id}">{$class.name|wash}</option>
      {/section}
      </select>
      <input class="button" type="submit" name="NewButton" value="{'Create here'|i18n('design/standard/node/view')}" />
    {/section}
  </form>
{**
  <form method="post" action={concat("/content/hide/", $node.node_id)|ezurl}>
    <input class="button" type="submit" name="Hide" value="Hide" />
  </form>
**}
  </div>
</div>
{/let}