| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @copyright Copyright (c) 2019-2020 Matias De lellis <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author Matias De lellis <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license GNU AGPL version 3 or any later version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * This program is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * it under the terms of the GNU Affero General Public License as | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * published by the Free Software Foundation, either version 3 of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * License, or (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | namespace OCA\FaceRecognition\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use OCP\AppFramework\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use OCP\AppFramework\Http\JSONResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use OCP\IRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use OCP\IUserManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use OCP\IUser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | use OCP\IL10N; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | use OCP\Util as OCP_Util; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use OCA\FaceRecognition\Helper\MemoryLimits; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | use OCA\FaceRecognition\Model\IModel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | use OCA\FaceRecognition\Model\ModelManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | use OCA\FaceRecognition\Service\SettingsService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | class SettingsController extends Controller { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	/** @var ModelManager */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	private $modelManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	/** @var SettingsService */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	private $settingsService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	/** @var \OCP\IL10N */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	protected $l10n; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	/** @var IUserManager */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	private $userManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	/** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	private $userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	const STATE_OK = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	const STATE_FALSE = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	const STATE_SUCCESS = 2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	const STATE_ERROR = 3; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	public function __construct ($appName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	                             IRequest        $request, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	                             ModelManager    $modelManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	                             SettingsService $settingsService, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	                             IL10N           $l10n, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	                             IUserManager    $userManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	                             $userId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		parent::__construct($appName, $request); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		$this->appName         = $appName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$this->modelManager    = $modelManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		$this->settingsService = $settingsService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		$this->l10n            = $l10n; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		$this->userManager     = $userManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		$this->userId          = $userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	 * @NoAdminRequired | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	 * @param $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	 * @param $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	public function setUserValue($type, $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		$status = self::STATE_SUCCESS; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		switch ($type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 			case SettingsService::USER_ENABLED_KEY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 				$enabled = ($value === 'true'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 				$this->settingsService->setUserEnabled($enabled); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 				if ($enabled) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 					$this->settingsService->setUserFullScanDone(false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 			default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 				$status = self::STATE_ERROR; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		// Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		$result = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 			'status' => $status, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 			'value' => $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 		return new JSONResponse($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	 * @NoAdminRequired | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	 * @param $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 117 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  | 	public function getUserValue($type) { | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  | 		$status = self::STATE_OK; | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  | 		$value ='nodata'; | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  | 		switch ($type) { | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  | 			case SettingsService::USER_ENABLED_KEY: | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  | 				$value = $this->settingsService->getUserEnabled(); | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  | 				break; | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  | 			default: | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  | 				$status = self::STATE_FALSE; | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  | 				break; | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  | 		$result = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  | 			'status' => $status, | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  | 			'value' => $value | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  | 		]; | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  | 		return new JSONResponse($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 	 * @param $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 	 * @param $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 	public function setAppValue($type, $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 		$status = self::STATE_SUCCESS; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 		$message = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 		switch ($type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 			case SettingsService::ANALYSIS_IMAGE_AREA_KEY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 				if (!is_numeric ($value)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 					$status = self::STATE_ERROR; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 					$message = $this->l10n->t("The format seems to be incorrect."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 					$value = '-1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 					break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 				$model = $this->modelManager->getCurrentModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 				if (is_null($model)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 					$status = self::STATE_ERROR; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 					$message = $this->l10n->t("Seems you haven't set up any analysis model yet"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 					$value = '-1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 					break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 				// Apply prudent limits. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 				if ($value > 0 && $value < SettingsService::MINIMUM_ANALYSIS_IMAGE_AREA) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 					$value = SettingsService::MINIMUM_ANALYSIS_IMAGE_AREA; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 					$message = $this->l10n->t("The minimum recommended area is %s", $this->getFourByThreeRelation($value)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 					$status = self::STATE_ERROR; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 				} else if ($value > SettingsService::MAXIMUM_ANALYSIS_IMAGE_AREA) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 					$value = SettingsService::MAXIMUM_ANALYSIS_IMAGE_AREA; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 					$message = $this->l10n->t("The maximum recommended area is %s", $this->getFourByThreeRelation($value)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 					$status = self::STATE_ERROR; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 				$model->open(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 				$maxImageArea = $model->getMaximumArea(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 				if ($value > $maxImageArea) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | 					$value = $maxImageArea; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 					$message = $this->l10n->t("The model does not recommend an area greater than %s", $this->getFourByThreeRelation($value)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 					$status = self::STATE_ERROR; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 				// If any validation error saves the value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 				if ($status !== self::STATE_ERROR) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 					$message = $this->l10n->t("The changes were saved. It will be taken into account in the next analysis."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 					$this->settingsService->setAnalysisImageArea((int) $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 			case SettingsService::SENSITIVITY_KEY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 				$this->settingsService->setSensitivity($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 				$this->userManager->callForSeenUsers(function(IUser $user) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 					$this->settingsService->setNeedRecreateClusters(true, $user->getUID()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 				}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | 			case SettingsService::MINIMUM_CONFIDENCE_KEY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 				$this->settingsService->setMinimumConfidence($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  | 				$this->userManager->callForSeenUsers(function(IUser $user) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 					$this->settingsService->setNeedRecreateClusters(true, $user->getUID()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 				}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 			case SettingsService::MINIMUM_FACES_IN_CLUSTER_KEY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 				$this->settingsService->setMinimumFacesInCluster($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 			case SettingsService::OBFUSCATE_FACE_THUMBS_KEY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 				$this->settingsService->setObfuscateFaces(!$this->settingsService->getObfuscateFaces()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 			default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 				$status = self::STATE_ERROR; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | 		// Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | 		$result = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | 			'status' => $status, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | 			'message' => $message, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | 			'value' => $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  | 		return new JSONResponse($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 	 * @param $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 	 * @return JSONResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 	public function getAppValue($type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 		$status = self::STATE_OK; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 		$value = 'nodata'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  | 		switch ($type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  | 			case SettingsService::SENSITIVITY_KEY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 				$value = $this->settingsService->getSensitivity(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | 			case SettingsService::MINIMUM_CONFIDENCE_KEY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | 				$value = $this->settingsService->getMinimumConfidence(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 			case SettingsService::MINIMUM_FACES_IN_CLUSTER_KEY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 				$value = $this->settingsService->getMinimumFacesInCluster(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  | 			case SettingsService::ANALYSIS_IMAGE_AREA_KEY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  | 				$value = $this->settingsService->getAnalysisImageArea(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 			default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | 		// Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | 		$result = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 			'status' => $status, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 			'value' => $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 		return new JSONResponse($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 	 * Get an approximate image size with 4x3 ratio | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 	 * @param int $area area in pixels^2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 	private function getFourByThreeRelation(int $area): string { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 		$width = intval(sqrt($area * 4 / 3)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 		$height = intval($width * 3  / 4); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 		return $width . 'x' . $height . ' (4x3)'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 264 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 265 |  |  |  |