summaryrefslogtreecommitdiffstats
path: root/lib/api.php
blob: d3d0e1f1bb966e7ef4ae0227220d32ae2ed26f8f (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php

/**
* ownCloud - App Template Example
*
* @author Bernhard Posselt
* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com 
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/


namespace OCA\News;

/**
 * This is used to wrap the owncloud static api calls into an object to make the
 * code better abstractable for use in the dependency injection container
 *
 * Extend this to your needs
 */
class API {

	private $appName;

	/**
	 * @param string $appName: the name of your application
	 */
	public function __construct($appName){
		$this->appName = $appName;
	}


	/**
	 * @return the name of your application
	 */
	public function getAppName(){
		return $this->appName;
	}


	/**
	 * @return: the user id of the current user
	 */
	public function getUserId(){
		return \OCP\USER::getUser();
	}


	/**
	 * Sets the current navigation entry to the currently running app
	 */
	public function activateNavigationEntry(){
		\OCP\App::setActiveNavigationEntry($this->appName);
	}


	/**
	 * Adds a new javascript file
	 * @param string $scriptName: the name of the javascript in js/ 
	 *                            without the suffix
	 */
	public function addScript($scriptName){
		\OCP\Util::addScript($this->appName, $scriptName);
	}


	/**
	 * Adds a new css file
	 * @param string $styleName: the name of the css file in css/ 
	 *                           without the suffix
	 */
	public function addStyle($styleName){
		\OCP\Util::addStyle($this->appName, $styleName);
	}


	/**
	 * @brief shorthand for addScript for files in the 3rdparty directory
	 * @param string $name: the name of the file without the suffix
	 */
	public function add3rdPartyScript($name){
		\OCP\Util::addScript($this->appName . '/3rdparty', $name);
	}


	/**
	 * @brief shorthand for addStyle for files in the 3rdparty directory
	 * @param string $name: the name of the file without the suffix
	 */
	public function add3rdPartyStyle($name){
		\OCP\Util::addStyle($this->appName . '/3rdparty', $name);
	}

	/**
	 * Looks up a systemwide defined value
	 * @param string $key: the key of the value, under which it was saved
	 * @return the saved value
	 */
	public function getSystemValue($key){
		return \OCP\Config::getSystemValue($key, '');
	}
	

	/**
	 * Sets a new systemwide value
	 * @param string $key: the key of the value, under which will be saved
	 * @param $value: the value that should be stored
	 */
	public function setSystemValue($key, $value){
		return \OCP\Config::setSystemValue($key, $value);
	}
	

	/**
	 * 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
	 */
	public function setUserValue($key, $value){
		\OCP\Config::setUserValue($this->getUserId(), $this->appName, $key, $value);
	}


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


	/**
	 * Returns the translation object
	 * @return the translation object
	 */
	public function getTrans(){
		return \OC_L10N::get($this->appName);
	}
	

	public function getLocalFilePath($path){
		return \OC_Filesystem::getLocalFile($path);
	}


	public function openEventSource(){
		return new \OC_EventSource();
	}

}