summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2013-09-24 17:10:01 +0200
committerThomas Tanghus <thomas@tanghus.net>2013-09-24 17:10:01 +0200
commitaaed871cee445633cb81f0aa230ba2f65c667803 (patch)
treee7a61c5db28a54e4d6792bd4e8a914ba477da700 /lib
parent7cad510f28e3d80de06cb98bbc5915b26dfa35d3 (diff)
downloadnextcloud-server-aaed871cee445633cb81f0aa230ba2f65c667803.tar.gz
nextcloud-server-aaed871cee445633cb81f0aa230ba2f65c667803.zip
Add factory class for the server container.
Diffstat (limited to 'lib')
-rw-r--r--lib/public/iservercontainer.php3
-rw-r--r--lib/public/itagmanager.php48
-rw-r--r--lib/public/itags.php9
-rw-r--r--lib/server.php3
-rw-r--r--lib/tagmanager.php68
-rw-r--r--lib/tags.php28
6 files changed, 140 insertions, 19 deletions
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index 0df746a28ed..f37bdb10f8f 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -58,7 +58,8 @@ interface IServerContainer {
/**
* Returns the tag manager which can get and set tags for different object types
*
- * @return \OCP\ITags
+ * @see \OCP\ITagManager::load()
+ * @return \OCP\ITagManager
*/
function getTagManager();
diff --git a/lib/public/itagmanager.php b/lib/public/itagmanager.php
new file mode 100644
index 00000000000..07e1d12fc0f
--- /dev/null
+++ b/lib/public/itagmanager.php
@@ -0,0 +1,48 @@
+<?php
+/**
+* ownCloud
+*
+* @author Thomas Tanghus
+* @copyright 2013 Thomas Tanghus <thomas@tanghus.net>
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Factory class creating instances of \OCP\ITags
+ *
+ * A tag can be e.g. 'Family', 'Work', 'Chore', 'Special Occation' or
+ * anything else that is either parsed from a vobject or that the user chooses
+ * to add.
+ * Tag names are not case-sensitive, but will be saved with the case they
+ * are entered in. If a user already has a tag 'family' for a type, and
+ * tries to add a tag named 'Family' it will be silently ignored.
+ */
+
+namespace OCP;
+
+interface ITagManager {
+
+ /**
+ * Create a new \OCP\ITags instance and load tags from db.
+ *
+ * @see \OCP\ITags
+ * @param string $type The type identifier e.g. 'contact' or 'event'.
+ * @param array $defaultTags An array of default tags to be used if none are stored.
+ * @return \OCP\ITags
+ */
+ public function load($type, $defaultTags=array());
+
+} \ No newline at end of file
diff --git a/lib/public/itags.php b/lib/public/itags.php
index 12643400548..5b1ebd189da 100644
--- a/lib/public/itags.php
+++ b/lib/public/itags.php
@@ -39,15 +39,6 @@ namespace OCP;
interface ITags {
/**
- * Load tags from db.
- *
- * @param string $type The type identifier e.g. 'contact' or 'event'.
- * @param array $defaultTags An array of default tags to be used if none are stored.
- * @return \OCP\ITags
- */
- public function loadTagsFor($type, $defaultTags=array());
-
- /**
* Check if any tags are saved for this type and user.
*
* @return boolean.
diff --git a/lib/server.php b/lib/server.php
index f3c79aa797f..c47f0e2b461 100644
--- a/lib/server.php
+++ b/lib/server.php
@@ -146,7 +146,8 @@ class Server extends SimpleContainer implements IServerContainer {
/**
* Returns the tag manager which can get and set tags for different object types
*
- * @return \OCP\ITags
+ * @see \OCP\ITagManager::load()
+ * @return \OCP\ITagManager
*/
function getTagManager() {
return $this->query('TagManager');
diff --git a/lib/tagmanager.php b/lib/tagmanager.php
new file mode 100644
index 00000000000..9a371a11253
--- /dev/null
+++ b/lib/tagmanager.php
@@ -0,0 +1,68 @@
+<?php
+/**
+* ownCloud
+*
+* @author Thomas Tanghus
+* @copyright 2013 Thomas Tanghus <thomas@tanghus.net>
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Factory class creating instances of \OCP\ITags
+ *
+ * A tag can be e.g. 'Family', 'Work', 'Chore', 'Special Occation' or
+ * anything else that is either parsed from a vobject or that the user chooses
+ * to add.
+ * Tag names are not case-sensitive, but will be saved with the case they
+ * are entered in. If a user already has a tag 'family' for a type, and
+ * tries to add a tag named 'Family' it will be silently ignored.
+ */
+
+namespace OC;
+
+class TagManager implements \OCP\ITagManager {
+
+ /**
+ * User
+ *
+ * @var string
+ */
+ private $user = null;
+
+ /**
+ * Constructor.
+ *
+ * @param string $user The user whos data the object will operate on.
+ */
+ public function __construct($user) {
+
+ $this->user = $user;
+
+ }
+
+ /**
+ * Create a new \OCP\ITags instance and load tags from db.
+ *
+ * @see \OCP\ITags
+ * @param string $type The type identifier e.g. 'contact' or 'event'.
+ * @param array $defaultTags An array of default tags to be used if none are stored.
+ * @return \OCP\ITags
+ */
+ public function load($type, $defaultTags=array()) {
+ return new Tags($this->user, $type, $defaultTags);
+ }
+
+} \ No newline at end of file
diff --git a/lib/tags.php b/lib/tags.php
index ff9f35ebc9e..9fdb35a7d6e 100644
--- a/lib/tags.php
+++ b/lib/tags.php
@@ -38,15 +38,30 @@ class Tags implements \OCP\ITags {
/**
* Tags
+ *
+ * @var array
*/
private $tags = array();
/**
* Used for storing objectid/categoryname pairs while rescanning.
+ *
+ * @var array
*/
private static $relations = array();
+ /**
+ * Type
+ *
+ * @var string
+ */
private $type = null;
+
+ /**
+ * User
+ *
+ * @var string
+ */
private $user = null;
const TAG_TABLE = '*PREFIX*vcategory';
@@ -59,10 +74,10 @@ class Tags implements \OCP\ITags {
*
* @param string $user The user whos data the object will operate on.
*/
- public function __construct($user) {
-
+ public function __construct($user, $type, $defaultTags = array()) {
$this->user = $user;
-
+ $this->type = $type;
+ $this->loadTags($defaultTags);
}
/**
@@ -70,10 +85,8 @@ class Tags implements \OCP\ITags {
*
* @param string $type The type identifier e.g. 'contact' or 'event'.
* @param array $defaultTags An array of default tags to be used if none are stored.
- * @return \OCP\ITags
*/
- public function loadTagsFor($type, $defaultTags=array()) {
- $this->type = $type;
+ protected function loadTags($defaultTags=array()) {
$this->tags = array();
$result = null;
$sql = 'SELECT `id`, `category` FROM `' . self::TAG_TABLE . '` '
@@ -101,7 +114,6 @@ class Tags implements \OCP\ITags {
\OCP\Util::writeLog('core', __METHOD__.', tags: ' . print_r($this->tags, true),
\OCP\Util::DEBUG);
- return $this;
}
/**
@@ -345,7 +357,7 @@ class Tags implements \OCP\ITags {
}
}
// reload tags to get the proper ids.
- $this->loadTagsFor($this->type);
+ $this->loadTags();
// Loop through temporarily cached objectid/tagname pairs
// and save relations.
$tags = $this->tags;