add sidebar
[grauphel.git] / controller / guicontroller.php
index e3753d7fc0f5f1d8a861323109aeed739799b7ba..06ea681af572b62cba800ed64a9f8de4dcab2c03 100644 (file)
@@ -29,13 +29,13 @@ use \OCP\AppFramework\Http\TemplateResponse;
  */
 class GuiController extends Controller
 {
-       /**
-        * constructor of the controller
+    /**
+     * constructor of the controller
      *
-        * @param string   $appName Name of the app
-        * @param IRequest $request Instance of the request
-        */
-       public function __construct($appName, \OCP\IRequest $request, $user, $urlGen)
+     * @param string   $appName Name of the app
+     * @param IRequest $request Instance of the request
+     */
+    public function __construct($appName, \OCP\IRequest $request, $user, $urlGen)
     {
         parent::__construct($appName, $request);
         $this->user   = $user;
@@ -56,18 +56,40 @@ class GuiController extends Controller
      */
     public function index()
     {
+        $this->checkDeps();
+
         $res = new TemplateResponse('grauphel', 'index');
-        $res->setParams(
-            array(
-                'apiurl' => $this->urlGen->getAbsoluteURL(
-                    $this->urlGen->linkToRoute(
-                        'grauphel.gui.index'
-                    )
-                ),
-            )
-        );
+        $res->setParams(array('apiurl' => $this->getApiUrl()));
+        $this->addNavigation($res);
         return $res;
+    }
+
+    protected function addNavigation(TemplateResponse $res)
+    {
+        $nav = new \OCP\Template('grauphel', 'appnavigation', '');
+        $nav->assign('apiurl', $this->getApiUrl());
 
+        $params = $res->getParams();
+        $params['appNavigation'] = $nav;
+        $res->setParams($params);
+    }
+
+    protected function checkDeps()
+    {
+        if (!class_exists('OAuthProvider')) {
+            throw new \Exception('PHP extension "oauth" is required');
+        }
+    }
+
+    protected function getApiUrl()
+    {
+        //we need to remove the trailing / for tomdroid and conboy
+        return rtrim(
+            $this->urlGen->getAbsoluteURL(
+                $this->urlGen->linkToRoute('grauphel.gui.index')
+            ),
+            '/'
+        );
     }
 }
 ?>