| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Calendar App | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author Georg Ehrke | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright 2016 Georg Ehrke <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * This library is free software; you can redistribute it and/or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * License as published by the Free Software Foundation; either | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * version 3 of the License, or any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * This library is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * GNU AFFERO GENERAL PUBLIC LICENSE for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * You should have received a copy of the GNU Affero General Public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * License along with this library.  If not, see <http://www.gnu.org/g/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | namespace OCA\Calendar\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use OCP\AppFramework\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use OCP\AppFramework\Http\JSONResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use OCP\AppFramework\Http; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use OCP\IConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use OCP\IRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use OCP\IUserSession; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | class SettingsController extends Controller { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	 * @var IConfig | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	private $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 * @var IUserSession | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	private $userSession; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	 * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	private $userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 7 |  | 	 * @param string $appName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	 * @param IRequest $request an instance of the request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 7 |  | 	 * @param IUserSession $userSession | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 7 |  | 	 * @param IConfig $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 7 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 7 |  | 	public function __construct($appName, IRequest $request, IUserSession $userSession, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 								IConfig $config) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		parent::__construct($appName, $request); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		$this->config = $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$this->userSession = $userSession; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$this->userId = $userSession->getUser()->getUID(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	 * get a configuration item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 5 |  | 	 * @NoAdminRequired | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 5 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 1 |  | 	 * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 4 |  | 	public function getConfig($key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 4 |  | 		switch ($key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			case 'view': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 				return $this->getView(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 4 |  | 			case 'skipPopover': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 4 |  | 				return $this->getSkipPopover(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 4 |  | 			case 'showWeekNr': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 4 |  | 				return $this->getShowWeekNr(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 4 |  | 				return new JSONResponse([], Http::STATUS_BAD_REQUEST); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 4 |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 1 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 3 |  | 	 * set a configuration item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 * @NoAdminRequired | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	 * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	 * @param mixed $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	public function setConfig($key, $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		switch ($key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 			case 'view': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 2 |  | 				return $this->setView($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 2 |  | 			case 'skipPopover': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 2 |  | 				return $this->setSkipPopover($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 			case 'showWeekNr': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 				return $this->setShowWeekNr($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 2 |  | 			default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 2 |  | 				return new JSONResponse([], Http::STATUS_BAD_REQUEST); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 2 |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 2 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 2 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 2 |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 1 |  | 	 * set a new view | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	 * @param string $view | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 1 |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 1 |  | 	 */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 112 | 1 | View Code Duplication | 	private function setView($view) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		if (!$this->isViewAllowed($view)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 			return new JSONResponse([], Http::STATUS_UNPROCESSABLE_ENTITY); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 			$this->config->setUserValue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 				$this->userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 				$this->appName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 5 |  | 				'currentView', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 				$view | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 5 |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 5 |  | 		} catch(\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 | 5 |  | 			return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 5 |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 5 |  | 		return new JSONResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 	 * get a config value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 137 |  | View Code Duplication | 	private function getView() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 			$view = $this->config->getUserValue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 				$this->userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 				$this->appName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 				'currentView', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 				'month' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 		} catch(\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 			return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 		return new JSONResponse([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 			'value' => $view, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 	 * check if view is allowed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	 * @param $view | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 	private function isViewAllowed($view) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 		$allowedViews = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 			'agendaDay', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 			'agendaWeek', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 			'month', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 		return in_array($view, $allowedViews); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 	 * set if popover shall be skipped | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 	 * @param $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 176 |  | View Code Duplication | 	private function setSkipPopover($value) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 		if (!$this->isSkipPopoverValueAllowed($value)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 			return new JSONResponse([], Http::STATUS_UNPROCESSABLE_ENTITY); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 			$this->config->setUserValue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 				$this->userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 				$this->appName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 				'skipPopover', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 				$value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 		} catch(\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 			return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | 		return new JSONResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 	 * get if popover shall be skipped | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 200 |  | View Code Duplication | 	private function getSkipPopover() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 			$view = $this->config->getUserValue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 				$this->userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 				$this->appName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 				'skipPopover', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 				'no' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | 		} catch(\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | 			return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | 		return new JSONResponse([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | 			'value' => $view, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 	 * check if value for skipPopover is allowed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 	 * @param $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 	private function isSkipPopoverValueAllowed($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 		$allowedValues = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 			'yes', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | 			'no' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 		return in_array($value, $allowedValues); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | 	 * set config value for showing week numbers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 	 * @param $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  | 	private function setShowWeekNr($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | 		if (!$this->isShowWeekNrValueAllowed($value)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 			return new JSONResponse([], Http::STATUS_UNPROCESSABLE_ENTITY); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | 			$this->config->setUserValue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | 				$this->userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 				$this->appName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 				'showWeekNr', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 				$value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 		} catch(\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 			return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 		return new JSONResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 	 * get config value for showing week numbers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 262 |  | View Code Duplication | 	private function getShowWeekNr() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 			$value = $this->config->getUserValue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 				$this->userId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | 				$this->appName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 				'showWeekNr', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | 				'no' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  | 		} catch(\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  | 			return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  | 		return new JSONResponse([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  | 			'value' => $value, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | 	 * check if value for showWeekNr is allowed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  | 	 * @param $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  | 	 * @return bool | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 284 |  |  | 	 */ | 
            
                                                        
            
                                    
            
            
                | 285 |  |  | 	private function isShowWeekNrValueAllowed($value) { | 
            
                                                        
            
                                    
            
            
                | 286 |  |  | 		$allowedValues = [ | 
            
                                                        
            
                                    
            
            
                | 287 |  |  | 			'yes', | 
            
                                                        
            
                                    
            
            
                | 288 |  |  | 			'no' | 
            
                                                        
            
                                    
            
            
                | 289 |  |  | 		]; | 
            
                                                        
            
                                    
            
            
                | 290 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 291 |  |  | 		return in_array($value, $allowedValues); | 
            
                                                        
            
                                    
            
            
                | 292 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 293 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 294 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.