cancel
Showing results for 
Search instead for 
Did you mean: 

Adding content to multiple categories via PHP

dwilson
Champ in-the-making
Champ in-the-making
Hello all, thanks in advance for any assistance.  (As indicated by other posts, I've had an unexpectedly rough time working with the PHP API lately, so I will try to be more constructive by documenting specific questions.)

I'm trying to complete a content import script, and one of the requirements is to add numerous categories to each new node.  I have no troubles adding a single category by creating a NodeRef and setting it as the property:
// $contentNode is my newly created content.
$contentNode->addAspect("{http://www.alfresco.org/model/content/1.0}generalclassifiable");
$results = $session->query($store, 'PATH:"/cm:generalclassifiable/cm:MyCategory"');
$category = $results[0];
$categoryNodeRef = "workspace://SpacesStore/".$category->getId();
$properties = $contentNode->getProperties();
$properties["{http://www.alfresco.org/model/content/1.0}categories"] = $categoryNodeRef;
$contentNode->setProperties($properties);
// save the session, etc.
But after trying numerous methods I cannot figure out how to do the same with two categories instead of just one.  Using arrays will earn me "Array to string conversion" errors even though other content nodes with multiple categories (created via the admin view) actually display them in this manner.  Here is a print_r example of a property array from an object created in the Alfresco Web Client with multiple categories set up:
    …
    [{http://www.alfresco.org/model/content/1.0}creator] => dwilson
    [{http://www.alfresco.org/model/content/1.0}created] => 2008-07-26T17:12:22.652-07:00
    [{http://www.alfresco.org/model/content/1.0}categories] => Array
        (
            [0] => workspace://SpacesStore/c74a7372-5b71-11dd-941b-79398bf43fa6
            [1] => workspace://SpacesStore/bc9d99c9-5b71-11dd-941b-79398bf43fa6
        )
    …
Here Jean supports the idea that you can indeed treat the cm:categories property as an array in the Javascript API along with all other multi-valued properties.
http://forums.alfresco.com/en/viewtopic.php?f=4&t=13879&p=45900&hilit=classification#p45900

I have seen several similar posts for other APIs stating to add the properties along with the cm:generalclassifiable aspect, although this similarly does not work in PHP.
http://forums.alfresco.com/en/viewtopic.php?f=36&t=15512&p=51344&hilit=categories#p51344
var categories = new Array();
categories["cm:categories"] = catNodes;
upload.addAspect("cm:generalclassifiable", categories);
(Of course the Javascript API has the CategoryNode object in place to support that code.)

Thoughts?
Thanks!
Dave
8 REPLIES 8

dwilson
Champ in-the-making
Champ in-the-making
*bump* Any thoughts on this one?

dwilson
Champ in-the-making
Champ in-the-making
*bump* *bump* ?

hr61369256
Champ in-the-making
Champ in-the-making
Hi dwilson,

pretty poor community reaction on your interessting post …

Before I go into experimentation some questions:

- Have you got some results to your question of assigning more than one category to a node?
- Is there - maybe - a possiblilty and/or a necessity to set the MultiValueFlag to true via the PHP API?

Thanks for any response in advance.

Ralf

dwilson
Champ in-the-making
Champ in-the-making
Ralf,

We gave up on the PHP API and moved to making SOAP calls to JS webscripts that we wrote.  The JS API proved to be a lot more flexible, so we inserted that layer to get our PHP app working.

I'm not sure how the PHP API might've changed (or not changed) since I made this post, the optimistic side of me would hope the issue is fixed.  Smiley Happy

Hope this helps,
Dave

hr61369256
Champ in-the-making
Champ in-the-making
Hi Dave,

thank you for your answer. Again some questions:
- Is it possible to mix both api's (PHP and Javascript)?
- Does the Javascript api uses something like AJAX to communicate with the remote server/webscripts?
- Could post a tiny example code, perhaps fitting to the origin of this topic with categories etc.?

Thanks so much,
Ralf

hr61369256
Champ in-the-making
Champ in-the-making
… again me:  just to explain what I mean with mixing both api's:  is it possible to use a ticket - received through php - for other services activating through the javascriipt api?

Ralf

ddanninger
Champ in-the-making
Champ in-the-making
Javascript API - i think he ment the server side scripting language javascripts to create webscripts in alfresco so every program language who is able to make http requests is able to have an integration with this API  (RESTFul Services)

Ticket sharing works fine for me if you log in via Webservice and give the ticket to the HTTP Request for the restful call.

To the outdated not supported Alfresco PHP Library - i had many problems with the API and i extended this API so that it is useful … still much to do on this API but i released a beta of my Library so you can have a look in it.

I implemented restful services like tags, categories and many other features. Docu is not ready yet but as you can read PHP you'll be able to read my Source Smiley Wink


-> ifresco PHP library - Forge Project -> http://forge.alfresco.com/projects/ifresco-phplib/




But the the real question on this topic:

Did you already try to add the noderefs of the categories in an array and save this array to the property?

Like:


$categoryNodeRefOne= "workspace://SpacesStore/".$categoryOne->getId();
$categoryNodeRefTwo= "workspace://SpacesStore/".$categoryTwo->getId();

$properties["{http://www.alfresco.org/model/content/1.0}categories"] = array(categoryNodeRefOne,categoryNodeRefTwo);

i think this should solve your problem

hr61369256
Champ in-the-making
Champ in-the-making
@ddanninger:
Thank you very much for this great php llibrary add on … that''s exactly what lots of php developers are looking for.
Ralf