Remove CLI, HTTP Frontend and add default container
authorMichael Spahn <m.spahn@metaways.de>
Mon, 24 Sep 2012 12:58:43 +0000 (14:58 +0200)
committerMichael Spahn <m.spahn@metaways.de>
Thu, 4 Oct 2012 13:54:57 +0000 (15:54 +0200)
Change-Id: I81812292983603916a188fe83643fb6b455793fa
Reviewed-on: https://gerrit.tine20.org/tine20/1104
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: jenkins user
tine20/Inventory/Frontend/Cli.php [deleted file]
tine20/Inventory/Frontend/Http.php [deleted file]
tine20/Inventory/Frontend/Json.php
tine20/Inventory/Preference.php [new file with mode: 0644]

diff --git a/tine20/Inventory/Frontend/Cli.php b/tine20/Inventory/Frontend/Cli.php
deleted file mode 100644 (file)
index a09580b..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/**
- * Tine 2.0
- * @package     Inventory
- * @subpackage  Frontend
- * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
- * @author      Cornelius Weiss <c.weiss@metaways.de>
- * @copyright   Copyright (c) 2009 Metaways Infosystems GmbH (http://www.metaways.de)
- */
-
-/**
- * cli server for timetracker
- *
- * This class handles cli requests for the timetracker
- *
- * @package     Inventory
- * @subpackage  Frontend
- */
-class Inventory_Frontend_Cli
-{
-    /**
-     * the internal name of the application
-     *
-     * @var string
-     */
-    protected $_applicationName = 'Inventory';
-    
-    /**
-     * help array with function names and param descriptions
-     */
-    protected $_help = array(
-        /*
-        'functionName' => array(
-            'description'   => 'function description',
-            'params'        => array()
-            )
-        ),
-        */
-    );
-    
-    /**
-     * echos usage information
-     *
-     */
-    public function getHelp()
-    {
-        foreach ($this->_help as $functionHelp) {
-            echo $functionHelp['description']."\n";
-            echo "parameters:\n";
-            foreach ($functionHelp['params'] as $param => $description) {
-                echo "$param \t $description \n";
-            }
-        }
-    }
-}
diff --git a/tine20/Inventory/Frontend/Http.php b/tine20/Inventory/Frontend/Http.php
deleted file mode 100644 (file)
index 549aa96..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-/**
- * Tine 2.0
- *
- * @package     Inventory
- * @subpackage  Frontend
- * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
- * @author      Philipp Schüle <p.schuele@metaways.de>
- * @copyright   Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
- */
-
-/**
- * This class handles all Http requests for the Inventory application
- *
- * @package     Inventory
- * @subpackage  Frontend
- */
-class Inventory_Frontend_Http extends Tinebase_Frontend_Http_Abstract
-{
-    protected $_applicationName = 'Inventory';
-}
index c9a0743..4687fd2 100644 (file)
@@ -135,16 +135,15 @@ class Inventory_Frontend_Json extends Tinebase_Frontend_Json_Abstract
 
     /**
      * Returns registry data
-     * 
+     *
      * @return array
      */
     public function getRegistryData()
     {
-        $defaultContainerArray = Tinebase_Container::getInstance()->getDefaultContainer($this->_applicationName)->toArray();\r
+        $defaultContainerArray = Tinebase_Container::getInstance()->getDefaultContainer('Inventory_Model_InventoryItem', NULL, 'defaultInventoryItemContainer')->toArray();
         $defaultContainerArray['account_grants'] = Tinebase_Container::getInstance()->getGrantsOfAccount(Tinebase_Core::getUser(), $defaultContainerArray['id'])->toArray();
-
         return array(
-            'defaultContainer' => $defaultContainerArray
+            'defaultInventoryItemContainer' => $defaultContainerArray
         );
     }
 }
diff --git a/tine20/Inventory/Preference.php b/tine20/Inventory/Preference.php
new file mode 100644 (file)
index 0000000..df10dc6
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+/**
+ * Tine 2.0
+ * 
+ * @package     Inventory
+ * @subpackage  Preference
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Michael Spahn <m.spahn@metaways.de>
+ * @copyright   Copyright (c) 2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ */
+
+
+/**
+ * backend for Inventory preferences
+ *
+ * @package     Inventory
+ * @subpackage  Preference
+ */
+class Inventory_Preference extends Tinebase_Preference_Abstract
+{
+    /**************************** application preferences/settings *****************/
+    
+    /**
+     * default container for inventory items
+     */
+    const DEFAULT_INVENTORYITEM_CONTAINER = 'defaultInventoryItemContainer';
+    
+    /**
+     * @var string application
+     */
+    protected $_application = 'Inventory';
+        
+    /**************************** public functions *********************************/
+    
+    /**
+     * get all possible application prefs
+     *
+     * @return  array   all application prefs
+     */
+    public function getAllApplicationPreferences()
+    {
+        $allPrefs = array(
+            self::DEFAULT_INVENTORYITEM_CONTAINER,
+        );
+            
+        return $allPrefs;
+    }
+    
+    /**
+     * get translated right descriptions
+     * 
+     * @return  array with translated descriptions for this applications preferences
+     */
+    public function getTranslatedPreferences()
+    {
+        $translate = Tinebase_Translation::getTranslation($this->_application);
+
+        $prefDescriptions = array(
+            self::DEFAULT_INVENTORYITEM_CONTAINER  => array(
+                'label'         => $translate->_('Default Inventory Item Container'),
+                'description'   => $translate->_('The default container for new items'),
+            )
+        );
+        return $prefDescriptions;
+    }
+    
+    /**
+     * get preference defaults if no default is found in the database
+     *
+     * @param string $_preferenceName
+     * @param string|Tinebase_Model_User $_accountId
+     * @param string $_accountType
+     * @return Tinebase_Model_Preference
+     */
+    public function getApplicationPreferenceDefaults($_preferenceName, $_accountId = NULL, $_accountType = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER)
+    {
+        $preference = $this->_getDefaultBasePreference($_preferenceName);
+        
+        switch($_preferenceName) {
+            case self::DEFAULT_INVENTORYITEM_CONTAINER:
+                $this->_getDefaultContainerPreferenceDefaults($preference, $_accountId);
+                break;
+            default:
+                throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.');
+        }
+        
+        return $preference;
+    }
+}