cancel
Showing results for 
Search instead for 
Did you mean: 

PHP SDK fill aspects

wolfgang_freund
Champ on-the-rise
Champ on-the-rise
Hi there,

i use the php sdk, and it really works quite well.

I can add aspects via the following code:

$contentNode->addAspect("cm_titled");
$contentNode->addAspect("cm_versionable");
$contentNode->addAspect("cm_taggable");
$contentNode->addAspect("{http://www.someco.com/model/content/1.0}webable");
$contentNode->addAspect("{http://www.someco.com/model/content/1.0}productRelated");

But my question is now, how can i fill these aspects? So for example, I give a node the aspect 'cm_taggable'. How do i now add tags lik 'alfresco', 'invoice'.

What I search for is a method like.


$tags = array("alfresco", "invoice");
$contentNode->addAspect("cm_taggable");
$contentNode->addTags($tags);

Thanks a lot.
5 REPLIES 5

ddanninger
Champ in-the-making
Champ in-the-making
actually there are several ways …. but the way in the normal API is to search a Tag first if it exists or you already have the NodeRef of the Tag.

And then you have to add this noderefs to an array and save it to the cm_taggable property….

Quick example:

$tags = array("workspace://SpacesStore/0000-00000-00000-00","workspace://SpacesStore/0000-00000-00000-00");

$contentNode->cm_taggable = $tags;

I implemented the REST Service of tags in my extended PHP Library so there you have functions like .. .

$RESTTags = new RESTTags($repository, $store, $session);
$RESTTags->AddNodeTags($contentNode->getId(),array("alfresco", "invoice"));

If you are interested you can download the extended PHP Library (ifresco PHP library) in forge -> http://forge.alfresco.com/projects/ifresco-phplib/

dallinns
Champ on-the-rise
Champ on-the-rise
but the way in the normal API is to search a Tag first if it exists or you already have the NodeRef of the Tag.

But then how do you create a new tag if it doesn't exist?

ddanninger
Champ in-the-making
Champ in-the-making
alfresco handles it , so no need to worry.

dallinns
Champ on-the-rise
Champ on-the-rise
So then what code do I use to add a new aspect?

I tried:

                    $tags = array("test","tag");
                    $node->cm_taggable = $tags;
and it doesn't actually go into Alfresco and the only pertinent message I get is the following:
Notice: Array to string conversion in C:\xampp\php\PEAR\Alfresco\Service\WebService\AlfrescoWebService.php on line 59

But the fact that it says "Notice" makes me think that's not actually causing it to fail, but the node never makes it into Alfresco and that is the only relevant message I'm getting from PHP when I try to add tags in this way.

ddanninger
Champ in-the-making
Champ in-the-making
Never tried it that way.

I use:

$Tags  = array("tag1","tag2");
$nodeId = "00000-0000-00000-00"; // no workspace://SpacesStore
$RestTags = new RESTTags($repository,$spacesStore,$session);
$RestTags->AddNodeTags($nodeId,$Tags);