Adds code to create relationship between logbook and location

这个提交包含在:
Peter Goodhall 2021-09-07 17:42:35 +01:00
父节点 efac6b8d80
当前提交 56e7827fe7
共有 3 个文件被更改,包括 57 次插入7 次删除

查看文件

@ -59,6 +59,7 @@ class Logbooks extends CI_Controller {
$station_logbook_id = $this->security->xss_clean($id); $station_logbook_id = $this->security->xss_clean($id);
$station_logbook_details_query = $this->logbooks_model->logbook($station_logbook_id); $station_logbook_details_query = $this->logbooks_model->logbook($station_logbook_id);
$data['station_locations_array'] = $this->logbooks_model->list_logbook_relationships($station_logbook_id);
$data['station_logbook_details'] = $station_logbook_details_query->row(); $data['station_logbook_details'] = $station_logbook_details_query->row();
$data['station_locations_list'] = $this->stations->all(); $data['station_locations_list'] = $this->stations->all();
@ -80,16 +81,18 @@ class Logbooks extends CI_Controller {
$data['notice'] = "Station Logbooks ".$this->security->xss_clean($this->input->post('station_logbook_name', true))." Updated"; $data['notice'] = "Station Logbooks ".$this->security->xss_clean($this->input->post('station_logbook_name', true))." Updated";
foreach ($this->input->post('SelectedStationLocations') as $selectedOption){ foreach ($this->input->post('SelectedStationLocations') as $selectedOption){
echo $selectedOption."\n";
// Check if theres already a link between logbook and location // Check if theres already a link between logbook and location
if($this->logbooks_model->relationship_exists($this->input->post('station_logbook_id'), $selectedOption) != TRUE) {
// If no link exisits create // If no link exisits create
$this->logbooks_model->create_logbook_location_link($this->input->post('station_logbook_id'), $selectedOption);
} else {
echo "Already Linked";
}
// Delete link if removed // Delete link if removed
} }
//redirect('logbooks'); redirect('logbooks');
} }
} }

查看文件

@ -53,5 +53,51 @@ class Logbooks_model extends CI_Model {
$this->db->where('logbook_id', $clean_id); $this->db->where('logbook_id', $clean_id);
return $this->db->get('station_logbooks'); return $this->db->get('station_logbooks');
} }
// Creates relationship between a logbook and a station location
function create_logbook_location_link($logbook_id, $location_id) {
// Create data array with field values
$data = array(
'station_logbook_id' => $logbook_id,
'station_location_id' => $location_id,
);
// Insert Record
$this->db->insert('station_logbooks_relationship', $data);
}
function relationship_exists($logbook_id, $location_id) {
$this->db->where('station_logbook_id', $logbook_id);
$this->db->where('station_location_id', $location_id);
$query = $this->db->get('station_logbooks_relationship');
if ($query->num_rows() > 0){
return true;
}
else{
return false;
}
}
function list_logbook_relationships($logbook_id) {
$relationships_array = array();
$this->db->where('station_logbook_id', $logbook_id);
$query = $this->db->get('station_logbooks_relationship');
if ($query->num_rows() > 0){
foreach ($query->result() as $row)
{
array_push($relationships_array, $row->station_location_id);
}
return $relationships_array;
}
else{
return false;
}
}
} }
?> ?>

查看文件

@ -45,7 +45,7 @@
<label for="StationLocationsSelect">Select Available Station Locations</label> <label for="StationLocationsSelect">Select Available Station Locations</label>
<select name="SelectedStationLocations[]" class="form-control" id="StationLocationsSelect" multiple aria-describedby="StationLocationSelectHelp"> <select name="SelectedStationLocations[]" class="form-control" id="StationLocationsSelect" multiple aria-describedby="StationLocationSelectHelp">
<?php foreach ($station_locations_list->result() as $row) { ?> <?php foreach ($station_locations_list->result() as $row) { ?>
<option value=" <?php echo $row->station_id;?>"><?php echo $row->station_profile_name;?> (Callsign: <?php echo $row->station_callsign;?> DXCC: <?php echo $row->station_country;?>)</option> <option value="<?php echo $row->station_id;?>" <?php if (in_array($row->station_id, $station_locations_array)) { echo "selected"; } ?>><?php echo $row->station_profile_name;?> (Callsign: <?php echo $row->station_callsign;?> DXCC: <?php echo $row->station_country;?>)</option>
<?php } ?> <?php } ?>
</select> </select>
<small id="StationLocationSelectHelp" class="form-text text-muted">Hold down the Ctrl (windows) or Command (Mac) button to select multiple options.</small> <small id="StationLocationSelectHelp" class="form-text text-muted">Hold down the Ctrl (windows) or Command (Mac) button to select multiple options.</small>
@ -55,6 +55,7 @@
</div> </div>
</div> </div>
<input type="hidden" class="form-control" name="station_logbook_id" value="<?php echo $station_logbook_details->logbook_id; ?>" required>
<button type="submit" class="btn btn-primary"><i class="fas fa-plus-square"></i> Update Station Logbook</button> <button type="submit" class="btn btn-primary"><i class="fas fa-plus-square"></i> Update Station Logbook</button>