| Total Complexity | 24 |
| Total Lines | 150 |
| Duplicated Lines | 0 % |
| Coverage | 7.55% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 32 | class SettingService { |
||
| 33 | |||
| 34 | /* |
||
| 35 | * Settings keys and default values. |
||
| 36 | */ |
||
| 37 | |||
| 38 | /** Current Model used to analyze */ |
||
| 39 | const CURRENT_MODEL_KEY = 'model'; |
||
| 40 | /* Default values is taked from AddDefaultFaceModel */ |
||
| 41 | |||
| 42 | /** Sensitivity used to clustering */ |
||
| 43 | const SENSITIVITY_KEY = 'sensitivity'; |
||
| 44 | const MINIMUM_SENSITIVITY = '0.4'; |
||
| 45 | const DEFAULT_SENSITIVITY = '0.5'; |
||
| 46 | const MAXIMUM_SENSITIVITY = '0.6'; |
||
| 47 | |||
| 48 | /** Minimum confidence used to try to clustring faces */ |
||
| 49 | const MINIMUM_CONFIDENCE_KEY = 'min-confidence'; |
||
| 50 | const MINIMUM_MINIMUM_CONFIDENCE = '0.0'; |
||
| 51 | const DEFAULT_MINIMUM_CONFIDENCE = '0.9'; |
||
| 52 | const MAXIMUM_MINIMUM_CONFIDENCE = '1.0'; |
||
| 53 | |||
| 54 | /** Memory limit suggested for analysis */ |
||
| 55 | const MEMORY_LIMITS_KEY = "memory-limits"; |
||
| 56 | const MINIMUM_MEMORY_LIMITS = 1 * 1024 * 1024 * 1024; |
||
| 57 | const DEFAULT_MEMORY_LIMITS = '-1'; // It is dynamically configured according to hardware |
||
| 58 | const MAXIMUM_MEMORY_LIMITS = 4 * 1024 * 1024 * 1024; |
||
| 59 | |||
| 60 | /** Show single persons on clustes view */ |
||
| 61 | const SHOW_NOT_GROUPED_KEY = 'show-not-grouped'; |
||
| 62 | const DEFAULT_SHOW_NOT_GROUPED = 'false'; |
||
| 63 | |||
| 64 | /** User setting what indicates if has the analysis enabled */ |
||
| 65 | const USER_ENABLED_KEY = 'enabled'; |
||
| 66 | const DEFAULT_USER_ENABLED = 'false'; |
||
| 67 | |||
| 68 | /** User setting that remember last images checked */ |
||
| 69 | const STALE_IMAGES_LAST_CHECKED_KEY = 'stale_images_last_checked'; |
||
| 70 | const DEFAULT_STALE_IMAGES_LAST_CHECKED = '0'; |
||
| 71 | |||
| 72 | /** Define if for some reason need remove old images */ |
||
| 73 | const STALE_IMAGES_REMOVAL_NEEDED_KEY = 'stale_images_removal_needed'; |
||
| 74 | const DEFAULT_STALE_IMAGES_REMOVAL_NEEDED = 'false'; |
||
| 75 | |||
| 76 | /** User setting that indicate when scan finished */ |
||
| 77 | const FULL_IMAGE_SCAN_DONE_KEY = 'full_image_scan_done'; |
||
| 78 | const DEFAULT_FULL_IMAGE_SCAN_DONE = 'false'; |
||
| 79 | |||
| 80 | /** User setting that indicate that need to recreate clusters */ |
||
| 81 | const USER_RECREATE_CLUSTERS_KEY = 'recreate-clusters'; |
||
| 82 | const DEFAULT_USER_RECREATE_CLUSTERS = 'false'; |
||
| 83 | |||
| 84 | /** @var IConfig Config */ |
||
| 85 | private $config; |
||
| 86 | |||
| 87 | /** @var string|null */ |
||
| 88 | private $userId; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @param IConfig $config |
||
| 92 | * @param string $userId |
||
| 93 | */ |
||
| 94 | 1 | public function __construct(IConfig $config, |
|
| 95 | $userId) |
||
| 96 | { |
||
| 97 | 1 | $this->config = $config; |
|
| 98 | 1 | $this->userId = $userId; |
|
| 99 | 1 | } |
|
| 100 | |||
| 101 | /* |
||
| 102 | * User settings. |
||
| 103 | */ |
||
| 104 | public function getUserEnabled ($userId = null): bool { |
||
| 105 | $enabled = $this->config->getUserValue($userId ?? $this->userId, Application::APP_NAME, self::USER_ENABLED_KEY, self::DEFAULT_USER_ENABLED); |
||
| 106 | return ($enabled === 'true'); |
||
| 107 | } |
||
| 108 | |||
| 109 | public function setUserEnabled (bool $enabled, $userId = null) { |
||
| 110 | $this->config->setUserValue($userId ?? $this->userId, Application::APP_NAME, self::USER_ENABLED_KEY, $enabled ? "true" : "false"); |
||
| 111 | } |
||
| 112 | |||
| 113 | public function getUserFullScanDone ($userId = null): bool { |
||
| 116 | } |
||
| 117 | |||
| 118 | public function setUserFullScanDone (bool $fullScanDone, $userId = null) { |
||
| 120 | } |
||
| 121 | |||
| 122 | public function getNeedRemoveStaleImages ($userId = null): bool { |
||
| 123 | $needRemoval = $this->config->getUserValue($userId ?? $this->userId, Application::APP_NAME, self::STALE_IMAGES_REMOVAL_NEEDED_KEY, self::DEFAULT_STALE_IMAGES_REMOVAL_NEEDED); |
||
| 124 | return ($needRemoval === 'true'); |
||
| 125 | } |
||
| 126 | |||
| 127 | public function setNeedRemoveStaleImages (bool $needRemoval, $userId = null) { |
||
| 128 | $this->config->setUserValue($userId ?? $this->userId, Application::APP_NAME, self::STALE_IMAGES_REMOVAL_NEEDED_KEY, $needRemoval ? "true" : "false"); |
||
| 129 | } |
||
| 130 | |||
| 131 | public function getNeedRecreateClusters ($userId = null): bool { |
||
| 132 | $needRecreate = $this->config->getUserValue($userId ?? $this->userId, Application::APP_NAME, self::USER_RECREATE_CLUSTERS_KEY, self::DEFAULT_USER_RECREATE_CLUSTERS); |
||
| 133 | return ($needRecreate === 'true'); |
||
| 134 | } |
||
| 135 | |||
| 136 | public function setNeedRecreateClusters (bool $needRecreate, $userId = null) { |
||
| 137 | $this->config->setUserValue($userId ?? $this->userId, Application::APP_NAME, self::USER_RECREATE_CLUSTERS_KEY, $needRecreate ? "true" : "false"); |
||
| 138 | } |
||
| 139 | |||
| 140 | /* |
||
| 141 | * Admin and process settings. |
||
| 142 | */ |
||
| 143 | public function getCurrentFaceModel(): int { |
||
| 144 | return intval($this->config->getAppValue(Application::APP_NAME, self::CURRENT_MODEL_KEY, AddDefaultFaceModel::DEFAULT_FACE_MODEL_ID)); |
||
| 145 | } |
||
| 146 | |||
| 147 | public function setCurrentFaceModel($model) { |
||
| 148 | $this->config->setAppValue(Application::APP_NAME, self::CURRENT_MODEL_KEY, $model); |
||
| 149 | } |
||
| 150 | |||
| 151 | public function getSensitivity(): float { |
||
| 152 | return floatval($this->config->getAppValue(Application::APP_NAME, self::SENSITIVITY_KEY, self::DEFAULT_SENSITIVITY)); |
||
| 153 | } |
||
| 154 | |||
| 155 | public function setSensitivity($sensitivity) { |
||
| 156 | $this->config->setAppValue(Application::APP_NAME, self::SENSITIVITY_KEY, $sensitivity); |
||
| 157 | } |
||
| 158 | |||
| 159 | public function getMinimumConfidence(): float { |
||
| 160 | return floatval($this->config->getAppValue(Application::APP_NAME, self::MINIMUM_CONFIDENCE_KEY, self::DEFAULT_MINIMUM_CONFIDENCE)); |
||
| 161 | } |
||
| 162 | |||
| 163 | public function setMinimumConfidence($confidence) { |
||
| 164 | $this->config->setAppValue(Application::APP_NAME, self::MINIMUM_CONFIDENCE_KEY, $confidence); |
||
| 165 | } |
||
| 166 | |||
| 167 | public function getMemoryLimits(): int { |
||
| 169 | } |
||
| 170 | |||
| 171 | public function setMemoryLimits(int $memoryLimits) { |
||
| 172 | $this->config->setAppValue(Application::APP_NAME, self::MEMORY_LIMITS_KEY, strval($memoryLimits)); |
||
| 173 | } |
||
| 174 | |||
| 175 | public function getShowNotGrouped (): bool { |
||
| 178 | } |
||
| 179 | |||
| 180 | public function setShowNotGrouped (bool $show) { |
||
| 181 | $this->config->setAppValue(Application::APP_NAME, self::SHOW_NOT_GROUPED_KEY, $show ? "true" : "false"); |
||
| 182 | } |
||
| 183 | |||
| 184 | } |
||
| 185 |