ZF-4976: Add new DocumentsList Data API functionality for Folders

Issue Type: Improvement Created: 2008-11-18T10:05:42.000+0000 Last Updated: 2010-01-06T18:40:48.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Jochen Hartmann (jhartmann) Assignee: Trevor Johns (tjohns) Tags: - Zend_Gdata

Related issues: - ZF-8732

Attachments: - DocsFolderSupport.diff


File your documents: You can now create new folders in the API, move documents in and out of folders and have full access to nested folders. (Issue 377, Issue 383)


Posted by Matthew Romaine (mromaine) on 2009-06-20T10:44:52.000+0000

Here's an initial patch that adds folder creation support.

Once you patch this in, you can also move and delete folders relatively easily with code outside the Gdata library.

Posted by Trevor Johns (tjohns) on 2009-06-22T12:29:50.000+0000

Hi Matthew, Thanks for the patch. Unfortunately, before we can accept your contributions, you need to sign and submit the Zend Framework CLA. This can be found here:…

Once this is done and you're added to the zf-framework-dev group in JIRA, let me know and I'll process this patch.

Posted by Matthew Romaine (mromaine) on 2009-06-23T23:27:44.000+0000

Hi Trevor,

My CLA has been accepted and Hilary has added my account to the contributor group. Please proceed with processing this patch. Thanks!

Posted by Eric Bidelman (api.eric) on 2009-06-24T17:20:04.000+0000

Thanks Matthew. A couple of suggestions/comments.

  • DOCUMENTS_FOLDER_FEED_URI should not have a trailing '/folder'
  • It would be nice to have an additional (optional) argument $resource_id for creating a folder within another folder. This is similar to creating documents in folders:…

public function createFolder($folderName, $folderResourceId=null) { ... if ($folderResourceId != null) { $uri = self::DOCUMENTS_FOLDER_FEED_URI . '/' . $folderResourceId; } else { $uri = self::DOCUMENTS_LIST_FEED_URI; } return $this->insertEntry($entry, $uri); }

You could additionally allow $folderResourceId to be a full URI (…)

Posted by Matthew Romaine (mromaine) on 2010-01-05T06:06:51.000+0000

Hi guys,

Sorry it's taken me so long to get back to this. I've implemented Eric's suggestions (thanks Eric) and have attached an updated patch.

Would be great to see this in the next release.

Cheers, Matt

Posted by Trevor Johns (tjohns) on 2010-01-05T13:02:48.000+0000

Hi Matt. Looks good. Just a few comments from me.

My comments are preceded with a !. Eric may have additional review comments as well.

<pre class="highlight">
--- Docs.php    (revision 20086)
+++ Docs.php    (working copy)
@@ -37,6 +37,12 @@
 require_once 'Zend/Gdata/Docs/DocumentListEntry.php';
+ * App Extensions
+ */

! Because of the way phpdoc works, using this style of comment to group
! require_once statements doesn't work. Please stick with the existing
! convention, namely an @see $CLASS_NAME for each require_once.

+require_once 'Zend/Gdata/App/Extension/Category.php';
+require_once 'Zend/Gdata/App/Extension/Title.php';
  * Service class for interacting with the Google Document List data API
  * @link <a href=""></a>
@@ -50,19 +56,29 @@
     const DOCUMENTS_LIST_FEED_URI = '<a href="">…</a>';
+    const DOCUMENTS_FOLDER_FEED_URI = '<a href=""></a>';
+    const DOCUMENTS_CATEGORY_SCHEMA = '<a href=""></a>';
+    const DOCUMENTS_CATEGORY_TERM = '<a href=""></a>';
     const AUTH_SERVICE_NAME = 'writely';
     protected $_defaultPostUri = self::DOCUMENTS_LIST_FEED_URI;
     private static $SUPPORTED_FILETYPES = array(
+      'TXT'=>'text/plain',
+      'TSV'=>'text/tab-separated-values',
+      'TAB'=>'text/tab-separated-values',
+      'HTML'=>'text/html',
+      'HTM'=>'text/html',
-      'TXT'=>'text/plain',
-      'XLS'=>'application/');
+      'XLS'=>'application/',
+      'XLSX'=>'application/',
+      'PPT'=>'application/',
+      'PPS'=>'application/');
      * Create Gdata_Docs object
@@ -235,6 +251,31 @@
+     * Creates a new folder in Google Docs
+     *
+     * @param string $folderName The folder name to create
+     * @param string $folderResourceId The parent folder to create it in ("folder%3Amy_parent_folder")

! This actually accepts string|null.

+     *

! Remove extra newline here.

+     * @return boolean
+     */
+    public function createFolder($folderName, $folderResourceId=null) {
+        $category = new Zend_Gdata_App_Extension_Category(self::DOCUMENTS_CATEGORY_TERM, 
+                                                          self::DOCUMENTS_CATEGORY_SCHEMA);
+        $title = new Zend_Gdata_App_Extension_Title($folderName);
+        $entry = new Zend_Gdata_Entry();
+        $entry->setCategory(array($category));
+        $entry->setTitle($title);
+        $uri = self::DOCUMENTS_LIST_FEED_URI;
+        if ($folderResourceId != null) {
+            $uri = self::DOCUMENTS_FOLDER_FEED_URI . '/' . $folderResourceId;
+        }
+        return $this->insertEntry($entry, $uri);
+    }
+    /**
      * Inserts an entry to a given URI and returns the response as an Entry.
      * @param mixed  $data The Zend_Gdata_Docs_DocumentListEntry or media

Posted by Eric Bidelman (api.eric) on 2010-01-05T13:09:58.000+0000

Looks good to me.

Posted by Matthew Romaine (mromaine) on 2010-01-05T19:46:16.000+0000

Hi guys, I've updated the patch file to include your comments. Hope that makes integration easier.

Posted by Trevor Johns (tjohns) on 2010-01-06T11:57:35.000+0000

One last change. I'll just go ahead and make this for you.

<pre class="highlight">
+ * @see Zend_Gdata_App_Extension_Category
+ * @see Zend_Gdata_App_Extension_Title
+ */
+require_once 'Zend/Gdata/App/Extension/Category.php';
+require_once 'Zend/Gdata/App/Extension/Title.php';

Each @see line needs to come immediately before it's respective require_once line.

As it currently stands, Zend_Gdata_App_Extension_Category will have too "See Also" lines in it's documentation, and Zend_Gdata_App_Extension_Title will have none.

Posted by Trevor Johns (tjohns) on 2010-01-06T18:40:48.000+0000

Commited to trunk as r20112. Scheduled for next minor release. Thanks for the patch!

I've created ZF-8732 to track some additional changes that need to be made to this, but that don't block integration.

<pre class="literal">
commit 4e85fb9f4d222d2eb8603a4938625520683a8261
Author: tjohns 
Date:   Thu Jan 7 02:39:32 2010 +0000

    ZF-4976: Add createFolder() method to Zend_Gdata_Docs.
    Tests and a minor doc changes added by me. All other changes submitted
    via patch.
    Patch by: Matthew Romaine (mromaine)
    git-svn-id: <a href="">…</a> 44c647ce-9c0f-0410-b52a-842

 library/Zend/Gdata/Docs.php   |   51 ++++++++++++++++++++++++++++++++++++-
 tests/Zend/Gdata/DocsTest.php |   55 ++++++++++++++++++++++++++++++++++++++---
 2 files changed, 100 insertions(+), 6 deletions(-)

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.