*/
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;
*/
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);
+ $this->addStats($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 addStats(TemplateResponse $res)
+ {
+ if ($this->user === null) {
+ return;
+ }
+
+ $username = $this->user->getUid();
+ $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen);
+ $tokens = new \OCA\Grauphel\Lib\TokenStorage();
+
+ $nav = new \OCP\Template('grauphel', 'indexStats', '');
+ $nav->assign('notes', count($notes->loadNotesOverview($username)));
+ $nav->assign('syncrev', $notes->loadSyncData($username)->latestSyncRevision);
+ $nav->assign('tokens', count($tokens->loadForUser($username, 'access')));
+
+ $params = $res->getParams();
+ $params['stats'] = $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')
+ ),
+ '/'
+ );
}
}
?>