diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2012-10-19 13:21:05 +0200 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-10-19 13:21:05 +0200 |
commit | 180326028587be3e266aa0c7d4ec9e870bd55265 (patch) | |
tree | de8bb3e8bdc82e2618d08a84c2009fb97fbd064f /lib/vcategories.php | |
parent | 0e4ed2887cb413db0e3eecdb0595a09dc3b01a0f (diff) | |
download | nextcloud-server-180326028587be3e266aa0c7d4ec9e870bd55265.tar.gz nextcloud-server-180326028587be3e266aa0c7d4ec9e870bd55265.zip |
Renamed OC_VCategories::add() to addMulti() and let the add() method return the id of the newly created category.
Diffstat (limited to 'lib/vcategories.php')
-rw-r--r-- | lib/vcategories.php | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/lib/vcategories.php b/lib/vcategories.php index 22bd8a3c851..c958368238c 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -74,7 +74,7 @@ class OC_VCategories { ); if($defcategories && count(self::$categories) === 0) { - $this->add($defcategories, true); + $this->addMulti($defcategories, true); } } @@ -273,13 +273,37 @@ class OC_VCategories { } /** - * @brief Add a new category name. + * @brief Add a new category. + * @param $name A string with a name of the category + * @returns int the id of the added category or false if it already exists. + */ + public function add($name) { + OCP\Util::writeLog('core', __METHOD__.', name: ' . $name, OCP\Util::DEBUG); + if($this->hasCategory($name)) { + OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', OCP\Util::DEBUG); + return false; + } + OCP\DB::insertIfNotExist(self::CATEGORY_TABLE, + array( + 'uid' => $this->user, + 'type' => $this->type, + 'category' => $name, + )); + $id = OCP\DB::insertid(self::CATEGORY_TABLE); + OCP\Util::writeLog('core', __METHOD__.', id: ' . $id, OCP\Util::DEBUG); + self::$categories[$id] = $name; + return $id; + } + + /** + * @brief Add a new category. * @param $names A string with a name or an array of strings containing * the name(s) of the categor(y|ies) to add. * @param $sync bool When true, save the categories + * @param $id int Optional object id to add to this|these categor(y|ies) * @returns bool Returns false on error. */ - public function add($names, $sync=false, $id = null) { + public function addMulti($names, $sync=false, $id = null) { if(!is_array($names)) { $names = array($names); } @@ -309,7 +333,7 @@ class OC_VCategories { * @param $vobject The instance of OC_VObject to load the categories from. */ public function loadFromVObject($id, $vobject, $sync=false) { - $this->add($vobject->getAsArray('CATEGORIES'), $sync, $id); + $this->addMulti($vobject->getAsArray('CATEGORIES'), $sync, $id); } /** |