Add location to user with template programming? [SOLVED]

Author Message

Mikael Johansson

Thursday 07 July 2005 3:12:36 am

I am trying to add a location to a user using template programming but haven't gotten very far.

I fetch the user object using

{def $userobject = fetch('content', 'object', hash('object_id', $userID))}

If I do a

{$userobject|attribute(show, 3)}

I get a list of the attributes of the user, so I now that it returns a valid user object.

The problem arises when I try to do

{$userobject->createNodeAssignment($groupNodeID, false)}

to add the user to a new group. I get this error:
parser error @ extension/chsuser/design/standard/templates/chsuser/add.tpl:40[12]
Extra characters found in expression, they will be ignored.
>createNodeAssignment($groupID, false)' ($userobject-)

Is the function createNodeAssignment not avaliable for user objects? The code works for my custom content objects.

Is it possible to do this another way?

Best regards
Mikael Johansson, Sweden

Mikael Johansson, Sweden

Mikael Johansson

Friday 08 July 2005 7:58:47 am

Solved it:

$object =& eZContentObject::fetch( $userID );

// Need to unpublish the user to be able to add it to the new location.
include_once('kernel/classes/ezcontentobject.php');
$object =& eZContentObject::fetch( $userID );
$version =& eZContentObjectVersion::fetchVersion(  $object->attribute('current_version'), $userID );
$version->unpublish();

// Add the location to the user
$object->createNodeAssignment($groupID, false);

// Finally, publish the user again.
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $userID,
                                                                             'version' => $object->attribute('current_version') ) );

Mikael Johansson, Sweden

Pål J Didriksen

Monday 11 July 2005 7:48:05 am

Great! I've been struggeling with this for a while too... But now it works!

Mikael Johansson

Tuesday 12 July 2005 2:23:47 am

I found a problem: I need to check for permissions in the php code. Now it is possible to add any user to any group as ling as you know the nodeid of the group.

How do I check permissions?
I have template code to do it, bit I need to do the check in the php code.

{* Check permissions *}
{def $groupobject = fetch('content', 'node', hash('node_id', $groupID))}
{if not($groupobject.can_edit)}
You do not have the proper permissions to add people to group {$groupID}.
{else}
User has been added. Thank you!
{/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 19 2025 00:29:38
Script start
Timing: Jan 19 2025 00:29:38
Module start 'layout'
Timing: Jan 19 2025 00:29:38
Module start 'content'
Timing: Jan 19 2025 00:29:38
Module end 'content'
Timing: Jan 19 2025 00:29:38
Script end

Main resources:

Total runtime0.7424 sec
Peak memory usage4,096.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0068 588.1406152.6406
Module start 'layout' 0.00680.0034 740.781339.4766
Module start 'content' 0.01010.7308 780.2578552.2969
Module end 'content' 0.74090.0014 1,332.554712.1094
Script end 0.7424  1,344.6641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.4336160.0002
Check MTime0.00130.1712160.0001
Mysql Total
Database connection0.00100.141210.0010
Mysqli_queries0.685692.3553600.0114
Looping result0.00070.0976580.0000
Template Total0.707095.220.3535
Template load0.00260.354420.0013
Template processing0.704494.880720.3522
Template load and register function0.00030.033710.0003
states
state_id_array0.00100.130810.0010
state_identifier_array0.00120.160220.0006
Override
Cache load0.00170.2239300.0001
Sytem overhead
Fetch class attribute can translate value0.00070.090020.0003
Fetch class attribute name0.00100.129250.0002
XML
Image XML parsing0.00060.077220.0003
class_abstraction
Instantiating content class attribute0.00000.002050.0000
General
dbfile0.00090.1164160.0001
String conversion0.00000.001240.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
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 24
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs