Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional attributes 'Usage' and 'Token' for scenery objects. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions scenemodels/classes/ObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct($objectDaoRO) {
}

public function createObject($id, $modelId, $lon, $lat, $countryCode,
$elevOffset, $orientation, $group, $desc) {
$elevOffset, $orientation, $group, $desc, $usageId = 0, $tokenId = 0) {
$country = $this->objectDaoRO->getCountry($countryCode);

$object = new \model\TheObject();
Expand All @@ -45,7 +45,8 @@ public function createObject($id, $modelId, $lon, $lat, $countryCode,
$object->getPosition()->setOrientation($orientation);
$object->setDescription($desc);
$object->setGroupId($group);

$object->setUsageId($usageId);
$object->setTokenId($tokenId);
return $object;
}
}
12 changes: 9 additions & 3 deletions scenemodels/classes/controller/AddModelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ public function __construct() {
*/
public function formAction() {
parent::menu();

// Show all the families other than the static family
$modelsGroups = $this->getModelsGroups();
$countries = $this->objectDaoRO->getCountries();
$nbModels = $this->getModelDaoRO()->countTotalModels();
$authors = $this->authorDaoRO->getAllAuthors(0, "ALL");
$usages = \model\TheObject::usages();
$tokens = \model\TheObject::tokens();

include 'view/submission/model/add_model_form.php';
}
Expand All @@ -59,7 +61,7 @@ public function addRequestAction() {

/** STEP 1 : CHECK IF ALL FILES WERE RECEIVED */
$exceptions = $this->checkFilesArray();

/** STEP 2 : MOVE THUMBNAIL, AC3D, PNG AND XML FILES IN TMP DIRECTORY (Will be removed later on) */
$thumbName = $_FILES['mo_thumbfile']['name'];
$ac3dName = $_FILES['ac3d_file']['name'];
Expand Down Expand Up @@ -127,6 +129,10 @@ public function addRequestAction() {
$offset = strip_tags($this->getVar('offset'));
$heading = strip_tags($this->getVar('heading'));
$country = $this->getVar('ob_country');
$country = $this->getVar('ob_country');
$usageId = $this->getVar('ob_usage_id');
$tokenId = $this->getVar('ob_token_id');

$objectValidator = \submission\ObjectValidator::getPositionValidator($longitude, $latitude, $country, $offset, $heading);

$validatorsSet = new \submission\ValidatorsSet();
Expand Down Expand Up @@ -183,7 +189,7 @@ public function addRequestAction() {
$newModel->setThumbnail($thumbFile);

$newObject = $objectFactory->createObject(-1, -1, $longitude, $latitude, $country,
$offset, \ObjectUtils::headingSTG2True($heading), 1, $name);
$offset, \ObjectUtils::headingSTG2True($heading), 1, $name, $usageId, $tokenId);

// Check captcha
if (!$this->checkCaptcha()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function viewRequestAction() {
// Check first if the author already exist
$authorExist = $this->authorDaoRO->getAuthorByEmail($newAuthor->getEmail()) != null;
}

$usages = \model\TheObject::usages();
$tokens = \model\TheObject::tokens();

include 'view/submission/model/validator/view_add_model_request.php';
}
}
Expand Down
2 changes: 2 additions & 0 deletions scenemodels/classes/controller/ObjectValidatorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
class ObjectValidatorController extends ValidatorController {
public function viewRequestAction() {
$request = $this->getRequest();
$usages = \model\TheObject::usages();
$tokens = \model\TheObject::tokens();
if ($request != null) {
include 'view/submission/object/validator/object_submission.php';
}
Expand Down
2 changes: 2 additions & 0 deletions scenemodels/classes/controller/ObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function viewAction() {
$object = $this->objectDaoRO->getObject($id);
$modelMetadata = $this->getModelDaoRO()->getModelMetadata($object->getModelId());
$group = $this->objectDaoRO->getObjectsGroup($object->getGroupId());
$usages = \model\TheObject::usages();
$tokens = \model\TheObject::tokens();
include 'view/objectview.php';
} else {
$pageTitle = "Object ID not valid";
Expand Down
9 changes: 7 additions & 2 deletions scenemodels/classes/controller/UpdateObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public function updateFormAction() {
if (\FormChecker::isLongitude($this->getVar('lon'))) {
$defaultLon = $this->getVar('lon');
}
$usages = \model\TheObject::usages();
$tokens = \model\TheObject::tokens();

include 'view/submission/object/update_object_form.php';
}
Expand All @@ -144,7 +146,9 @@ public function checkAction() {
$new_offset = $this->getVar('new_offset');
$new_orientation = $this->getVar('new_heading');
$safe_new_ob_text = $this->getVar('new_ob_text');

$new_usageId = $this->getVar('new_usage_id');
$new_tokenId = $this->getVar('new_token_id');

$idToUpdate = $this->getVar('id_to_update');
if (!\FormChecker::isObjectId($idToUpdate)) {
$pageTitle = 'Objects update Form';
Expand Down Expand Up @@ -178,7 +182,8 @@ public function checkAction() {
$oldObject = $this->objectDaoRO->getObject($idToUpdate);
$newObject = $objectFactory->createObject($idToUpdate, $modelId,
$new_long, $new_lat, $new_country,
$new_offset, \ObjectUtils::headingSTG2True($new_orientation), 1, $safe_new_ob_text);
$new_offset, \ObjectUtils::headingSTG2True($new_orientation), 1, $safe_new_ob_text,
$new_usageId, $new_tokenId);

$oldModelMD = $this->getModelDaoRO()->getModelMetadata($oldObject->getModelId());
$newModelMD = $this->getModelDaoRO()->getModelMetadata($modelId);
Expand Down
17 changes: 11 additions & 6 deletions scenemodels/classes/dao/ObjectDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ public function addObject(\model\TheObject $obj) {
$objPos = $obj->getPosition();
$obOffset = $objPos->getElevationOffset();

$query = "INSERT INTO fgs_objects (ob_id, ob_text, wkb_geometry, ob_gndelev, ob_elevoffset, ob_heading, ob_country, ob_model, ob_group) ".
$query = "INSERT INTO fgs_objects (ob_id, ob_text, wkb_geometry, ob_gndelev, ob_elevoffset, ob_heading, ob_country, ob_model, ob_usage, ob_token, ob_group) ".
"VALUES (DEFAULT, '".pg_escape_string($obj->getDescription())."', ST_PointFromText('POINT(".pg_escape_string($objPos->getLongitude())." ".pg_escape_string($objPos->getLatitude()).")', 4326), -9999, ".
(($obOffset == 0 || $obOffset == '')?"NULL":pg_escape_string($obOffset)) .
", ".pg_escape_string($objPos->getOrientation()).", '".pg_escape_string($obj->getCountry()->getCode())."', ".pg_escape_string($obj->getModelId()).", 1) RETURNING ob_id;";

", ".pg_escape_string($objPos->getOrientation()).", '".pg_escape_string($obj->getCountry()->getCode())."', ".pg_escape_string($obj->getModelId()).
", ".pg_escape_string($obj->getUsageId()).", ".pg_escape_string($obj->getTokenId()).", 1) RETURNING ob_id;";

$result = $this->database->query($query);

if (!$result) {
Expand All @@ -40,8 +41,10 @@ public function updateObject(\model\TheObject $object) {
"SET ob_text=$$".pg_escape_string($object->getDescription())."$$, ".
"wkb_geometry=ST_PointFromText('POINT(".pg_escape_string($objPos->getLongitude())." ".pg_escape_string($objPos->getLatitude()).")', 4326),".
"ob_country='".pg_escape_string($object->getCountry()->getCode())."',".
"ob_gndelev=-9999, ob_elevoffset=".pg_escape_string($objPos->getElevationOffset()).", ob_heading=".pg_escape_string($objPos->getOrientation()).", ob_model=".pg_escape_string($object->getModelId()).", ob_group=1 ".
"WHERE ob_id=".pg_escape_string($object->getId()).";";
"ob_gndelev=-9999, ob_elevoffset=".pg_escape_string($objPos->getElevationOffset()).", ob_heading=".pg_escape_string($objPos->getOrientation()).", ob_model=".pg_escape_string($object->getModelId()).", ".
"ob_usage=".pg_escape_string($object->getUsageId()).",".
"ob_token=".pg_escape_string($object->getTokenId()).",".
"ob_group=1 WHERE ob_id=".pg_escape_string($object->getId()).";";

$result = $this->database->query($query);

Expand Down Expand Up @@ -203,7 +206,9 @@ private function getObjectFromRow($objectRow) {
$object->setDescription($objectRow['ob_text']);
$object->setGroupId($objectRow['ob_group']);
$object->setLastUpdated(new \DateTime($objectRow['ob_modified']));

$object->setUsageId($objectRow['ob_usage']);
$object->setTokenId($objectRow['ob_token']);

return $object;
}

Expand Down
14 changes: 10 additions & 4 deletions scenemodels/classes/dao/RequestDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ private function arrayObject(\model\TheObject $object) {
'offset'=>(empty($offset)?'NULL':$offset),
'orientation'=>$objPos->getOrientation(),
'country'=>$object->getCountry()->getCode(),
'modelId'=>$object->getModelId());
'modelId'=>$object->getModelId(),
'usageId'=>$object->getUsageId(),
'tokenId'=>$object->getTokenId());
}

private function arrayRequestObjectUpdate($request) {
Expand All @@ -151,7 +153,9 @@ private function arrayRequestObjectUpdate($request) {
'orientation'=>$newObjPos->getOrientation(),
'country'=>$newObj->getCountry()->getCode(),
'modelId'=>$newObj->getModelId(),
'objectId'=>$newObj->getId());
'objectId'=>$newObj->getId(),
'usageId'=>$newObj->getUsageId(),
'tokenId'=>$newObj->getTokenId());
}

private function arrayRequestObjectDelete($request) {
Expand Down Expand Up @@ -365,7 +369,8 @@ private function getObjectFromRow($addReqArray) {

return $objectFactory->createObject(-1, $addReqArray['modelId'],
$addReqArray['longitude'], $addReqArray['latitude'], $addReqArray['country'],
$addReqArray['offset'], $addReqArray['orientation'], 1, $addReqArray['description']);
$addReqArray['offset'], $addReqArray['orientation'], 1, $addReqArray['description'],
$addReqArray['usageId'], $addReqArray['tokenId']);
}

private function getRequestMassiveObjectsAddFromRow($objRequests) {
Expand All @@ -387,7 +392,8 @@ private function getRequestObjectUpdateFromRow($updReqArray) {

$newObject = $objectFactory->createObject($updReqArray['objectId'], $updReqArray['modelId'],
$updReqArray['longitude'], $updReqArray['latitude'], $updReqArray['country'],
$updReqArray['offset'], $updReqArray['orientation'], 1, $updReqArray['description']);
$updReqArray['offset'], $updReqArray['orientation'], 1, $updReqArray['description'],
$updReqArray['usageId'],$updReqArray['tokenId']);

$requestObjUp = new \model\RequestObjectUpdate();
$requestObjUp->setContributorEmail('');
Expand Down
30 changes: 29 additions & 1 deletion scenemodels/classes/model/TheObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class TheObject {

private $description;
private $groupId;
private $usageId;
private $tokenId;

function __construct() {
$this->position = new Position();
Expand Down Expand Up @@ -92,6 +94,32 @@ public function setLastUpdated($lastUpdated) {
public function getPosition() {
return $this->position;
}
}

public function getUsageId() {
return $this->usageId;
}

public function setUsageId($usageId) {
$this->usageId = $usageId;
}

public function getTokenId() {
return $this->tokenId;
}

public function setTokenId($tokenId) {
$this->tokenId = $tokenId;
}

/**
* static lists of allowed usages and tokens
*/
public static function usages() {
return array("<default>", "StaticAircraft", "ApronVehicles","AIObjects");
}

public static function tokens() {
return array("<default>", "AI_OBJECT");
}
}
?>
10 changes: 9 additions & 1 deletion scenemodels/view/objectview.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<table>
<tr>
<td style="width: 320px" rowspan="9"><img src="app.php?c=Models&amp;a=thumbnail&amp;id=<?php echo $object->getModelId(); ?>" alt="Thumbnail"/></td>
<td style="width: 320px" rowspan="11"><img src="app.php?c=Models&amp;a=thumbnail&amp;id=<?php echo $object->getModelId(); ?>" alt="Thumbnail"/></td>
<td style="width: 320px">Unique ID</td>
<td><?php echo $object->getId(); ?></td>
</tr>
Expand Down Expand Up @@ -53,6 +53,14 @@
<td>Group</td>
<td><?php echo "<a href=\"app.php?c=Objects&amp;a=search&amp;group=".$object->getGroupId()."\">".$group->getName()."</a>"; ?></td>
</tr>
<tr>
<td>Usage</td>
<td><?php echo htmlspecialchars($usages[$object->getUsageId()]); ?></td>
</tr>
<tr>
<td>STG Token</td>
<td><?php echo htmlspecialchars($tokens[$object->getTokenId()]); ?></td>
</tr>
<tr>
<td>Model</td>
<td>
Expand Down
38 changes: 38 additions & 0 deletions scenemodels/view/submission/model/add_model_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,44 @@ function validateTabs()
</select>
</td>
</tr>
<tr>
<td style="width: 200px;">
<label for="ob_usage_id">Model's usage<em>*</em><span>This is the usage of the object you want to add while it defines the scenery export directory ("Objects" will be the default). If unsure, don't select a value (keep &lt;default&gt;).</span></label>
</td>
<td>
<select name="ob_usage_id" id="ob_usage_id">
<?php
for ($index = 0; $index < count($usages); $index++) {
$v = htmlspecialchars($usages[$index]);
if ($index == 0) {
echo "<option value=\"".$index."\" selected=\"selected\">".$v."</option>";
} else {
echo "<option value=\"".$index."\">".$v."</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td style="width: 200px;">
<label for="ob_token_id">Model's STG token<em>*</em><span>This is the STG token assigned to this object and to be used during scenery export. If unsure, don't select a token (keep &lt;default&gt;) which lets the exporter script decide which token to use.</span></label>
</td>
<td>
<select name="ob_token_id" id="ob_token_id">
<?php
for ($index = 0; $index < count($tokens); $index++) {
$v = htmlspecialchars($tokens[$index]);
if ($index == 0) {
echo "<option value=\"".$index."\" selected=\"selected\">".$v."</option>";
} else {
echo "<option value=\"".$index."\">".$v."</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td>
<label for="mo_name">Model name<em>*</em><span>Please add a short (max 100 letters) name of your model (eg : Cornet antenna radome - Brittany - France).</span></label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ function validateForm() {
<td>Family</td>
<td><?php echo $newModelMD->getModelsGroup()->getName(); ?></td>
</tr>
<tr>
<td>Usage</td>
<td><?php echo htmlspecialchars($usages[$newObj->getUsageId()]); ?></td>
</tr>
<tr>
<td>STG Token</td>
<td><?php echo htmlspecialchars($tokens[$newObj->getTokenId()]); ?></td>
</tr>
<tr>
<td>Proposed Path Name</td>
<td><?php echo $newModelMD->getFilename(); ?></td>
Expand Down
41 changes: 41 additions & 0 deletions scenemodels/view/submission/object/update_object_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,47 @@ function validateForm()
?>
</td>
</tr>
<tr>
<td>
<span title="This is the usage of the object you want to update while it defines the scenery export directory ('Objects' will be the default). If unsure, don't select a value (keep &lt;default&gt;)."><label for="new_usage_id">Object's usage<em>*</em></label></span>
</td>
<td><?php echo htmlspecialchars($usages[$objectToUp->getUsageId()]); ?></td>
<td>
<select name="new_usage_id" id="new_usage_id">
<?php
for ($index = 0; $index < count($usages); $index++) {
$v = htmlspecialchars($usages[$index]);
if ($index == $objectToUp->getUsageId()) {
echo "<option value=\"".$index."\" selected=\"selected\">".$v."</option>";
} else {
echo "<option value=\"".$index."\">".$v."</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td>
<span title="This is the STG token assigned to this object and to be used during scenery export. If unsure, don't select a token (keep &lt;default&gt;) which lets the exporter script decide which token to use.">
<label for="new_token_id">Object's STG token<em>*</em></label></span>
</td>
<td><?php echo htmlspecialchars($tokens[$objectToUp->getTokenId()]); ?></td>
<td>
<select name="new_token_id" id="new_token_id">
<?php
for ($index = 0; $index < count($tokens); $index++) {
$v = htmlspecialchars($tokens[$index]);
if ($index == $objectToUp->getTokenId()) {
echo "<option value=\"".$index."\" selected=\"selected\">".$v."</option>";
} else {
echo "<option value=\"".$index."\">".$v."</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td>
<span title="This is the model name of the object you want to update, ie the name as it's supposed to appear in the .stg file.">
Expand Down
13 changes: 13 additions & 0 deletions scenemodels/view/submission/object/validator/object_submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@
echo " style=\"background-color: rgb(255, 200, 0)\"";
}
echo "><td>Object's model</td><td>".htmlspecialchars($oldModelMD->getName())."</td><td>".htmlspecialchars($newModelMD->getName())."</td></tr>";

echo "<tr";
if ($oldObject->getUsageId() != $newObject->getUsageId()) {
echo " style=\"background-color: rgb(255, 200, 0)\"";
}
echo "><td>Object's Usage</td><td>".htmlspecialchars($usages[$oldObject->getUsageId()])."</td><td>".htmlspecialchars($usages[$newObject->getUsageId()])."</td></tr>";

echo "<tr";
if ($oldObject->getTokenId() != $newObject->getTokenId()) {
echo " style=\"background-color: rgb(255, 200, 0)\"";
}
echo "><td>Object's STG token</td><td>".htmlspecialchars($tokens[$oldObject->getTokenId()])."</td><td>".htmlspecialchars($tokens[$newObject->getTokenId()])."</td></tr>";

echo "<tr><td>Thumbnail</td><td><img src='app.php?c=Models&amp;a=thumbnail&amp;id=".$oldModelMD->getId()."' alt=''/></td>".
"<td><img src='app.php?c=Models&amp;a=thumbnail&amp;id=".$newModelMD->getId()."' alt=''/></td></tr>";
echo "<tr";
Expand Down