help: workflow and template parameters

Author Message

Alessandro Cipriani

Friday 16 July 2004 4:05:01 am

hi all
i've created a simple workflow that sends an email when a new object is created. this workflow hasn't his own template.

it works ok but i'd like to send in the mail also all the parameters of the newly-reated object like name, ecc

the code is like follows:


function execute(&$process, &$event)
	{
		$parameters = $process->attribute( 'parameter_list' );
		$mail = new eZMail();
		$mail->setReceiver(my_address);
		$mail->setSender(sender_address);
		$mail->setSubject($parameters['name']);;

		$mail->setBody("newly created object");
		$mailResult = eZMailTransport::send($mail);

		return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;

in this way i'd like to have the name of the new object in my email subject, but i get an email with empty subject

anyone has some tip?

best regards
alessandro

Paul Forsyth

Friday 16 July 2004 4:38:47 am

That should work. Can you confirmt that the parameter '$parameters['name']' has content?

paul

http://www.visionwt.com

Alessandro Cipriani

Friday 16 July 2004 5:19:35 am

hi paul
yes, the name parameter is not null, also because is the name (required) of the new object just created.
note: i want to retrieve the name of the object created, not a parameter of the workflow-template.

cheers
alessandro

Paul Forsyth

Friday 16 July 2004 6:55:30 am

Well if you want the object name try:


$object_id = $processParameters['object_id'];
$object = eZContentObject::fetch($object_id);
$objectName= $object->attribute('name');

That should do it.

Also, to debug try adding at the bottom, after the setBody call:

header('Content-type: text/plain');
var_dump($mail);

This will help you see what that variable contains...

paul

--
http://www.visionwt.com

Alessandro Cipriani

Friday 16 July 2004 7:44:54 am

thanx paul!
now it works!
only a further little question:

i'd like to have the mail body as the concatenation of various strings
i tried

$mail->setBody(concat("newly created object", $objectId));

but i get the message:

Fatal error: Call to undefined function: concatstring() in c:\programmi\ezpublish\ezpublish\extension\synch\eventtypes\event\synch\synchtype.php on line 97

how to import the file with the concat function definition?

best regards

alessandro

Paul Forsyth

Friday 16 July 2004 8:29:06 am

Great!

Now, you have to remember this is PHP you are working with, not eZ. There is no concat function in PHP. Take a look at the string documents for PHP for more info.

http://uk2.php.net/manual/en/ref.strings.php

But concatting strings together is very simple in PHP, eg:

$mail->setBody("newly created object".$objectId);

should do the trick.

paul

--
http://www.visionwt.com

Alessandro Cipriani

Monday 19 July 2004 2:03:43 am

hi paul
thanx a lot for your answers, all very useful
now the things get more complicated:

the 'newly created object' is a user class extended by me, and i'm having some trouble extracting all the attributes i need to work

in the .tpl file i get the attributes i need in this way:

login: $current_user.contentobject.data_map.user_account.content.login
my_attribute: $current_user.contentobject.data_map.my_attribute.content

but in my php file i'm not able to get them!

for the login attribute i tried:

		$dataMap = $currentVersion->dataMap(); 
		$userAccount = $dataMap['user_account'];
		$login=$dataMap->login();

but i get an error
no idea for the other attribute

any hint?

best regards
alessandro

Paul Forsyth

Monday 19 July 2004 3:11:19 am

There are few ways to get the attribute:

// Set the title
$contentObjectAttributes =& $currentVersion->contentObjectAttributes();
foreach ($contentObjectAttributes as $attribute)
{
  // Each attribute has an attribute called 'identifier' that identifies it.    
  if ($attribute->attribute("contentclass_attribute_identifier") == "title")
  {
    $attribute->setAttribute("data_text","new title");
    $attribute->store();
   
    break;
  }
}

and there are more but it looks like you are trying to login your user automatically. For this all you need is the contentobject id, and:

    $user =& eZUser::fetch( $contentObjectID );
    $user->loginCurrent();

paul

--
http://www.visionwt.com

Alessandro Cipriani

Monday 19 July 2004 3:27:16 am

hi paul
no, i'm not trying to login
all i'm trying to do is to send an email with all the class attributes after the object is published (created or modified).

so i don't need to login as the new user or store anything

when i fetch the just published object i need to have all the attributes

can you help me?

best regards
alessandro

Paul Forsyth

Monday 19 July 2004 3:38:28 am

You need a template for your mail.

If you do something like in your workflow:

include_once( "kernel/common/template.php" );

$tpl =& templateInit();
$tpl->setVariable( 'current_version', $currentVersion);

$templateResult =& $tpl->fetch( 'design:send_email.tpl' );

$mail->setBody("newly created object");

The template 'send_email.tpl' has to be in the correct design and template directory of course.

Treat this template as a normal template and process the current_version as a normal object. In this way you can list out the attributes at your leisure.

$tpl->fetch will process the template and create text which is used to set the mail body with.

paul

--
http://www.visionwt.com

Alessandro Cipriani

Monday 19 July 2004 3:47:33 am

hi paul

i need to get all the attribute values from the workflow, because in a second moment i got to send the same data via socket. so i need to retrieve all here.

following the instruction from your previous reply i wrote:

// Set the title 
$contentObjectAttributes =& $currentVersion->contentObjectAttributes(); 

$xx="";
foreach ($contentObjectAttributes as $attribute) 
{
	 // Each attribute has an attribute called 'identifier' that identifies it. 
	$xx= $xx ." - ". $attribute->attribute("contentclass_attribute_identifier") ;
}

then i set the mail body to $xx
in this way i received an email with all the attribute names
how can now i retrieve the attribute values?
is there an attribute like 'contentclass_attribute_identifier' able to display the value?

best regards
alessandro

Paul Forsyth

Monday 19 July 2004 4:47:09 am

Content can be found by:

$attribute->content();

Note, some contents are actually classes, or contain things you dont normally expect. So beware.

paul

--
http://www.visionwt.com

Alessandro Cipriani

Monday 19 July 2004 5:28:51 am

great paul!
all works properly, i'm having a little problem only with user account, where the attribute->content() gets 'Object'.
do you know how can i retrieve the informations (login, e-mail) from it?

cheers
alessandro

Paul Forsyth

Monday 19 July 2004 5:43:26 am

Yip.

For this you need to look at the datatype definitions in 'kernel/classes/datatypes'. Specifically 'kernel/classes/datatypes/ezuser/ezusertype.php'.

You'll noice on line 265 the function

function &objectAttributeContent( &$contentObjectAttribute )

This returns the content you tried earlier. In this example it creates a ezuser from the user id and returns it, so now look in 'kernel/classes/datatypes/ezuser/ezuser.php' to see what to return. You'll see things in the definition such as 'login', 'email' and others. You can access these directly in your template by '$user.login', for example.

So, in your case check the contentclass_attribute_identifier for your object and if its an ezuser looking inside the object for your users details instead of printing the object itself.

I've said a little more here than i need to but you need to start looking at the datatype classes for yourself to understand how to use them. It takes a while for it to click - it did for me.

Hope this helps.

paul

--
http://www.visionwt.com

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