if ($user === null) {
    $fail('User not logged in.');
}
//Checking correct type and typeText parameters:
require_once 'database/areaOfInterest.php';
$type = $_POST['type'];
$typeText = $_POST['typeText'];
if (!AreaOfInterestType::validType($type)) {
    $fail("Invalid type: '{$type}'");
}
if (AreaOfInterestType::hasText($type)) {
    if (!is_string($typeText) || $typeText === '') {
        $fail("Type text must be a non empty string, and not '{$typeText}'.");
    }
} else {
    $typeText = null;
}
//Checking scanRectangleMap:
$scanRectangleMap = json_decode($_POST['scanRectangleMap'], true);
if ($scanRectangleMap === null) {
    $scanRectangleMap = $_POST['scanRectangleMap'];
    $fail("Could not decode json: '{$scanRectangleMap}'.");
}
//Creating AOI:
$aoi = AreaOfInterest::createAOI($scanRectangleMap, $user, $type, $typeText);
if ($aoi instanceof Exception) {
    $msg = $aoi->getMessage();
    $fail("Ran into problems when trying to create AOI: {$msg}");
}
//Finishing:
echo json_encode($aoi->toArray());
Example #2
0
 /**
     @return $aois [AreaOfInterest]
     Returns all areas of interest that belong to this file.
 */
 public function getAOIs()
 {
     if ($this->aois === null) {
         $urns = $this->getAOIUrns();
         $this->aois = AreaOfInterest::getAOIsFromUrns($urns);
     }
     return $this->aois;
 }