2016-08-04 05:59:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace CustomValidations;
|
|
|
|
|
|
|
|
use Respect\Validation\Rules\AbstractRule;
|
|
|
|
|
|
|
|
class DataStoreId extends AbstractRule {
|
|
|
|
private $dataStoreName;
|
|
|
|
|
|
|
|
public function __construct($dataStoreName = '') {
|
|
|
|
if ($this->isDataStoreNameValid($dataStoreName)) {
|
|
|
|
$this->dataStoreName = $dataStoreName;
|
|
|
|
} else {
|
|
|
|
throw new \Exception("Invalid DataStore: $dataStoreName");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validate($dataStoreId) {
|
|
|
|
$dataStore = null;
|
|
|
|
|
|
|
|
switch ($this->dataStoreName) {
|
|
|
|
case 'user':
|
|
|
|
$dataStore = \User::getUser($dataStoreId);
|
|
|
|
break;
|
|
|
|
case 'ticket':
|
|
|
|
$dataStore = \Ticket::getTicket($dataStoreId);
|
|
|
|
break;
|
|
|
|
case 'department':
|
|
|
|
$dataStore = \Department::getDataStore($dataStoreId);
|
|
|
|
break;
|
2016-10-03 21:44:41 +02:00
|
|
|
case 'customresponse':
|
|
|
|
$dataStore = \CustomResponse::getDataStore($dataStoreId);
|
|
|
|
break;
|
2016-11-23 02:27:05 +01:00
|
|
|
case 'topic':
|
|
|
|
$dataStore = \Topic::getDataStore($dataStoreId);
|
|
|
|
break;
|
|
|
|
case 'article':
|
|
|
|
$dataStore = \Article::getDataStore($dataStoreId);
|
|
|
|
break;
|
2016-08-04 05:59:04 +02:00
|
|
|
}
|
|
|
|
|
2016-08-04 21:01:24 +02:00
|
|
|
return !$dataStore->isNull();
|
2016-08-04 05:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function isDataStoreNameValid($dataStoreName) {
|
|
|
|
return in_array($dataStoreName, [
|
|
|
|
'user',
|
|
|
|
'ticket',
|
2016-10-03 21:44:41 +02:00
|
|
|
'department',
|
2016-11-23 02:27:05 +01:00
|
|
|
'customresponse',
|
|
|
|
'topic',
|
|
|
|
'article'
|
2016-08-04 05:59:04 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|