structure helper

This commit is contained in:
2019-08-25 19:19:07 -05:00
parent 85295cb03f
commit b9fa079eb7

View File

@@ -158,53 +158,109 @@ class StructureHelper {
} }
private function UpdateExistingStructure($structure, $info) { private function UpdateExistingStructure($structure, $info) {
$st = Structure::where(['structure_id' => $structure->structure_id])->first(); //Update the structure id and name
$st->structure_id = $structure->structure_id; Structure::where(['structure_id' => $structure->structure_id])->update([
$st->structure_name = $info->name; 'structure_id' => $structure->structure_id,
'name' => $info->name,
]);
//Update the services
if(isset($structure->services)) { if(isset($structure->services)) {
$st->services = true; $services = true;
Structure::where(['structure_id' => $structure->structure_id])->update([
'services' => $services,
]);
} else { } else {
$st->services = false; $services = false;
Structure::where(['structure_id' => $structure->structure_id])->update([
'services' => $services,
]);
} }
//Update the structure state
if(isset($structure->state)) { if(isset($structure->state)) {
$st->state = $structure->state; Structure::where(['structure_id' => $structure->structure_id])->update([
'state' => $structure->state,
]);
} else { } else {
$st->state = 'None'; Structure::where(['structure_id' => $structure->structure_id])->update([
'state' => 'None',
]);
} }
//Update the state timer start
if(isset($structure->state_timer_start)) { if(isset($structure->state_timer_start)) {
$st->state_timer_start = $this->DecodeDate($structure->state_timer_start); Structure::where(['structure_id' => $structure->structure_id])->update([
'state_timer_start' => $this->DecodeDate($structure->state_timer_start),
]);
} }
//Update the state timer end
if(isset($structure->state_timer_end)) { if(isset($structure->state_timer_end)) {
$st->state_timer_end = $this->DecodeDate($structure->state_timer_end); Structure::where(['structure_id' => $structure->structure_id])->update([
'state_timer_end' => $this->DecodeDate($structure->state_timer_end),
]);
} }
//Update the fuel expires
if(isset($structure->fuel_expires)) { if(isset($structure->fuel_expires)) {
$st->fuel_expires = $this->DecodeDate($structure->fuel_expires); Structure::where(['structure_id' => $structure->structure_id])->update([
'fuel_expires' => $this->DecodeDate($structure->fuel_expires),
]);
} }
$st->profile_id = $structure->profile_id;
$st->position_x = $info->position->x; //Update the profile id, and positions
$st->position_y = $info->position->y; Structure::where(['structure_id' => $structure->structure_id])->update([
$st->position_z = $info->position->z; 'profile_id' => $structure->profile_id,
'position_x' => $info->position->x,
'position_y' => $info->position->y,
'position_z' => $info->position->z,
]);
//Update the next reinforce apply
if(isset($structure->next_reinforce_apply)) { if(isset($structure->next_reinforce_apply)) {
$st->next_reinforce_apply = $this->DecodeDate($structure->next_reinforce_apply); Structure::where(['structure_id' => $structure->structure_id])->update([
'next_reinforce_apply' => $this->DecodeDate($structure->next_reinforce_apply),
]);
} }
//update the next reinforce hour
if(isset($structure->next_reinforce_hour)) { if(isset($structure->next_reinforce_hour)) {
$st->next_reinforce_hour = $structure->next_reinforce_hour; Structure::where(['structure_id' => $structure->structure_id])->update([
'next_reinforce_hour' => $structure->next_reinforce_hour,
]);
} }
//Update next reinforce weekday
if(isset($structure->next_reinforce_weekday)) { if(isset($structure->next_reinforce_weekday)) {
$st->next_reinforce_weekday = $structure->next_reinforce_weekday; Structure::where(['structure_id' => $structure->structure_id])->update([
'next_reinforce_weekday' => $structure->next_reinforce_weekday,
]);
} }
$st->reinforce_hour = $structure->reinforce_hour;
//Update reinforce hour
if(isset($structure->reinforce_hour)) {
Structure::where(['structure_id' => $structure->structure_id])->update([
'reinforce_hour' => $structure->reinforce_hour,
]);
}
//Update reinforce weekday
if(isset($structure->reinforce_weekday)) { if(isset($structure->reinforce_weekday)) {
$st->reinforce_weekday = $structure->reinforce_weekday; Structure::where(['structure_id' => $structure->structure_id])->update([
'reinforce_weekday' => $structure->reinforce_weekday,
]);
} }
//Update the unanchors at field
if(isset($structure->unanchors_at)) { if(isset($structure->unanchors_at)) {
$st->unanchors_at = $structure->unanchors_at; Structure::where(['structure_id' => $structure->structure_id])->update([
'unanchors_at' => $structure->unanchors_at,
]);
} }
//Save the database record
$st->save();
//Update the services for the structure as well //Update the services for the structure as well
if($st->services == true) { if($services == true) {
//Delete the existing services, then add the new services //Delete the existing services, then add the new services
Service::where(['structure_id' => $structure->structure_id, ])->delete(); Service::where(['structure_id' => $structure->structure_id, ])->delete();