cancel
Showing results for 
Search instead for 
Did you mean: 

PHP Library Examples Wanted ...

rwetherall
Confirmed Champ
Confirmed Champ
Hi All,

Over the coming weeks I hope to add some example scripts to the Wiki and PHP library to help make the process of understanding the Alfresco PHP API easier.

If you have any examples you'd be willing to share then this will help speed up this process.  I'm looking for anything from the very simple (eg: accessing a property value, uploading content, traversing an association) to more complicated scripts, perhaps with elements of UI.  The examples can be code snipits or complete scripts.

Any help will be gratefully received and appropriate credit will be given to those scripts that make it into the documentation/library.

Please feel free to post on this thread with your contributions.

Many thanks,
Roy
9 REPLIES 9

sacco
Champ in-the-making
Champ in-the-making
Hi Roy

If we could have just a hint here it would help: Smiley Happy

http://wiki.alfresco.com/wiki/Enabling_Alfresco_PHP_Server

You might also find it helpful to know that your Wiki (or whatever is indexing behind it)
is configured to consider anything less than four characters a stop-word, which might
tend to make PHP, AMP, API, SDK, JVM, UI, etc. less visible than they deserve to be.

Smiley Sad

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Sure thing, its on my list to fill out this coming week.  I'll let you know when it's done.

Thanks for the tip regarding the Wiki.  I'll pass that onto our web master.

Cheers,
Roy

marcus
Champ in-the-making
Champ in-the-making
Here's a method I use quite often from my alfresco wrapper class. The spacesStore variable refers to an object of type SpacesStore


   /**
     * Get the node for a given path beneath /Company Home
    *
    * Example: $alfrescoWrapper->getNodeByPath('/Guest Home/Alfresco_Tutorial.pdf');
     *
     * @param string $path
     */
    public function getNodeByPath($path, $node = null)
    {
        $bits = split('/', $path);

        if ($node == null) {
            $node = $this->spacesStore->getCompanyHome();
        }

        /* @var $node Node */
        foreach ($bits as $bit) {
            // Skip up until we have the parts after the company home
            if (empty($bit) || $bit == 'Company Home') {
                continue;
            }

            // Get the node for the current bit. If the current
            // "bit" doesn't exist, then
            $children = $node->getChildren();
            foreach ($children as $child) {
                $childNode = $child->getChild();
                if ($childNode->cm_name == $bit) {
                    $node = $childNode;

                    // Cheat and skip to the next 'bit' to scan
                    continue 2;
                }
            }

            $node = null;
            break;
        }

        return $node;
    }

romain_lamarche
Champ in-the-making
Champ in-the-making
Why you don't use a Lucene query like 'PATH:"/app:company_home/cm:myfolder/cm:myotherfolder"' ?

The only disadvantage I see is that the query is handled by Lucene, and Lucene index content in background.
So, if you have juste created a node near the node you are querying, the query may not return the node, even if it exists !

Why can't we query the repository with classic method "selectNodes" in xpath through the webservice api ?

I know, CMIS will cover this weak … Smiley Happy

marcus
Champ in-the-making
Champ in-the-making
Why you don't use a Lucene query like 'PATH:"/app:company_home/cm:myfolder/cm:myotherfolder"' ?

A lot of the time content is referred to by the name path, which isn't always the same as the PATH stored in lucene for a variety of reasons.

k_magnai
Champ in-the-making
Champ in-the-making
hi all,  Smiley Surprisedops:  sorry for my bad english
1.on alfresco wiki Node class contain a public function copy($destinationNode, $associationType, $associationName, $copyChildren=true); but it function is not found
2. i can't understand association why it is used(what is $assiociationType,$associationName parameter ).
3.is php api just for admin user if no how can i get logged users home folder
please help me all

marcus
Champ in-the-making
Champ in-the-making
I'm not sure why there's no copy() method in the Node class, but I have a feeling the released PHP library is quite outdated, so you might want to try getting it from the Alfresco SVN repository and see if it is more up to date.

Associations are used to link to node objects together. They can have a particular type (eg childAssociations, relatedAssociation) which provides a way of selecting linked nodes along a particular type of association. Associations are also named with a fully qualified name, which helps when identifying a specific association name.

k_magnai
Champ in-the-making
Champ in-the-making
Thanks for your reply. but i'm sure that copy function is not found i'm searching through all files but i never find copy function.
Can you give me some example little code if copy method is found how to use this method because i can't really understand association.
please help me

ddanninger
Champ in-the-making
Champ in-the-making
If you look for a copy function in Standard Alfresco PHP Library , you will not find such a function….

You should implement it via RESTFul Services … works fine….

Check out my PHP LIbrary i implemented in there ->
http://forge.alfresco.com/projects/ifresco-phplib/

Code must be like:


$Transport = new RESTTransport($repository,$store,$session);
$Transport->CopyTo($DestinationNode->getId(),array($Node->getId()));
// Same with ->MoveTo

Why an array with the Target Node? Cuz Copy & Move Restful Services can handle multiple Noderefs.