Setting relations between Contents and User

Author Message

Jordan Amar

Wednesday 03 December 2008 12:50:18 pm

Hi, here is my situation :
I have a class named "Article". There is a field named "author" which is type of User.
I have a class names "Category", with a field named "name".

I'm creating an extension which should create imported articles (from somewere). I have problems with linking existing user to it, and setting it a specified category. Below is the code that I have :

	$user = eZUser::fetchByName("user_login");
	$datamap = array (
		"title" => "my title -lol-",
		"date" => mktime(0, 0, 0, 12, 25, 1984),
		"body" => "Curabitur eu lectus. Fusce sagittis laoreet augue. Suspendisse at felis. Aenean tellus ipsum, mollis iaculis, dignissim eget, blan ",
	);
	$remoteID = md5( time() . rand( 0 , 100000 ) );
	$this->contentHandler->insertMyContent( "article" , $remoteID , $datamap , "blogs");
	$galerieObject =& eZContentObject::fetchByRemoteID( $remoteID );
	$attr =& $galerieObject->attribute('data_map');
	$author =& $attr['author'];
	$author->setContent($user);

What's wrong with it ?

Piotrek Karaś

Saturday 06 December 2008 11:37:30 pm

You're missing lots of eZ Publish basics here. For example, adding a User datatype attribute to a content class results in a new content user class. What would be the purpose of creating users that are articles a the same time? I see no logical sense in here. Users are users, and whenever they create new content (for example Articles), special reference (or meta data) is created by the system, it's the default feature.

I suggest going through the entire documentation, especially the basics and concepts part.

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Jérôme Vieilledent

Monday 08 December 2008 5:17:04 am

I would suggest you to use the <b>Object relations</b> datatype in your class.
http://ez.no/doc/ez_publish/technical_manual/4_0/reference/datatypes/object_relations

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 20 2025 08:03:45
Script start
Timing: Jan 20 2025 08:03:45
Module start 'layout'
Timing: Jan 20 2025 08:03:45
Module start 'content'
Timing: Jan 20 2025 08:03:46
Module end 'content'
Timing: Jan 20 2025 08:03:46
Script end

Main resources:

Total runtime0.6345 sec
Peak memory usage4,096.0000 KB
Database Queries59

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 589.2891152.6406
Module start 'layout' 0.00500.0030 741.929739.4766
Module start 'content' 0.00800.6252 781.4063581.7031
Module end 'content' 0.63320.0012 1,363.109412.1250
Script end 0.6344  1,375.2344 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.4828160.0002
Check MTime0.00130.2082160.0001
Mysql Total
Database connection0.00070.110810.0007
Mysqli_queries0.578291.1355590.0098
Looping result0.00060.0917570.0000
Template Total0.609196.020.3046
Template load0.00200.316720.0010
Template processing0.607195.684420.3036
Template load and register function0.00020.038310.0002
states
state_id_array0.00090.145010.0009
state_identifier_array0.00080.118520.0004
Override
Cache load0.00170.2616170.0001
Sytem overhead
Fetch class attribute can translate value0.00050.077930.0002
Fetch class attribute name0.00120.183350.0002
XML
Image XML parsing0.01031.622730.0034
class_abstraction
Instantiating content class attribute0.00000.001650.0000
General
dbfile0.00941.4883240.0004
String conversion0.00000.001440.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
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/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
2content/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: 14
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs