private function GLExchange::_validateSubmission in GlobalLink Connect for Drupal 7.7
1 call to GLExchange::_validateSubmission()
- GLExchange::initSubmission in gl_ws/
glc/ GLExchange.php - * Initialize a new Submission * *
File
- gl_ws/
glc/ GLExchange.php, line 228
Class
Code
private function _validateSubmission($submission) {
if (!isset($submission)) {
throw new Exception("Please initialize submission first.");
}
if (!isset($submission->project)) {
throw new Exception("Please set submission project");
}
if (!isset($submission->name)) {
throw new Exception("Please set submission name");
}
if (isset($submission->workflow)) {
$isSet = false;
foreach ($submission->project->workflows as $workflow) {
if ($workflow->ticket == $submission->workflow->ticket) {
$isSet = true;
break;
}
}
if (!$isSet) {
throw new Exception("Invalid submission workflow " + $submission->workflow->name);
}
}
if (isset($submission->dueDate)) {
$today = date("m.d.y");
if (strtotime($today) * 1000 > $submission->dueDate) {
throw new Exception("Submission due date should be greater than current date");
}
}
if (isset($submission->submitter)) {
if (!$this
->isSubmitterValid($submission->project->shortcode, $submission->submitter)) {
throw new Exception("Specified submitter '" . $submission->submitter . "' doesn`t exist");
}
}
if (isset($submission->project->customAttributes)) {
foreach ($submission->project->customAttributes as $projectCustomAttribute) {
if ($projectCustomAttribute->mandatory) {
$isSet = false;
if (isset($submission->customAttributes)) {
foreach ($submission->customAttributes as $name => $value) {
if ($name == $projectCustomAttribute->name) {
$isSet = true;
break;
}
}
}
if (!$isSet) {
throw new Exception("Mandatory custom field '" . $projectCustomAttribute->name . "' is not set");
}
}
}
if (isset($submission->customAttributes)) {
foreach ($submission->customAttributes as $name => $value) {
$isExists = false;
foreach ($submission->project->customAttributes as $projectCustomAttribute) {
if ($name == $projectCustomAttribute->name) {
$isExists = true;
if ($projectCustomAttribute->type == "COMBO" && isset($projectCustomAttribute->values)) {
$comboValueCorrect = false;
$va = explode(",", $projectCustomAttribute->values);
foreach ($va as $option) {
if ($option == $value) {
$comboValueCorrect = true;
break;
}
}
if (!$comboValueCorrect) {
throw new Exception("Value '" . $value . "' for custom field '" . $name . "' is not allowed. Allowed values:" . $projectCustomAttribute->values);
}
}
}
}
if (!$isExists) {
throw new Exception("Custom field '" . $name . "' is not allowed in project");
}
}
}
}
else {
if (isset($submission->customAttributes)) {
throw new Exception("Project doesn't have custom attributes");
}
}
}