summaryrefslogtreecommitdiffstats
path: root/controllers/controller.php
blob: 032cb45eeca149cb5cc3f0600709271359e28ac1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* ownCloud - News app
*
* @author Bernhard Posselt
* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com>
*
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file
*
*/

namespace OCA\News;

class Controller {

    protected $userId;
    protected $trans;


    public function __construct(){
        $this->userId = \OCP\USER::getUser();
        $this->trans = \OC_L10N::get('news');
        $this->safeParams = array();
    }


    protected function addScript($name){
        \OCP\Util::addScript('news', $name);
    }


    protected function addStyle($name){
        \OCP\Util::addStyle('news', $name);
    }


    protected function add3rdPartyScript($name){
        \OCP\Util::addScript('news/3rdparty', $name);
    }


    protected function add3rdPartyStyle($name){
        \OCP\Util::addStyle('news/3rdparty', $name);
    }


    /**
     * Shortcut for setting a user defined value
     * @param $key the key under which the value is being stored
     * @param $value the value that you want to store
     */
    protected function setUserValue($key, $value){
        \OCP\Config::setUserValue($this->userId, 'news', $key, $value);
    }


    /**
     * Shortcut for getting a user defined value
     * @param $key the key under which the value is being stored
     */
    protected function getUserValue($key){
        return \OCP\Config::getUserValue($this->userId, 'news', $key);
    }


    /**
     * Binds variables to the template and prints it
     * The following values are always assigned: userId, trans
     * @param $arguments an array with arguments in $templateVar => $content
     * @param $template the name of the template
     * @param $safeParams template parameters which should not be escaped
     * @param $fullPage if true, it will render a full page, otherwise only a part
     *                  defaults to true
     */
    protected function render($template, $arguments=array(), $safeParams=array(),
                              $fullPage=true){

        if($fullPage){
            $template = new \OCP\Template('news', $template, 'user');
        } else {
            $template = new \OCP\Template('news', $template);
        }

        foreach($arguments as $key => $value){
            if(array_key_exists($key, $safeParams)) {
                $template->assign($key, $value, false);
            } else {
                $template->assign($key, $value);
            }

        }

        $template->assign('userId', $this->userId);
        $template->assign('trans', $this->trans);
        $template->printPage();
    }


}