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.