Adds code to create relationship between logbook and location
这个提交包含在:
父节点
efac6b8d80
当前提交
56e7827fe7
共有 3 个文件被更改,包括 57 次插入 和 7 次删除
|
|
@ -59,6 +59,7 @@ class Logbooks extends CI_Controller {
|
|||
$station_logbook_id = $this->security->xss_clean($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_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";
|
||||
|
||||
foreach ($this->input->post('SelectedStationLocations') as $selectedOption){
|
||||
echo $selectedOption."\n";
|
||||
|
||||
// Check if theres already a link between logbook and location
|
||||
|
||||
// If no link exisits create
|
||||
if($this->logbooks_model->relationship_exists($this->input->post('station_logbook_id'), $selectedOption) != TRUE) {
|
||||
// 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
|
||||
}
|
||||
|
||||
//redirect('logbooks');
|
||||
redirect('logbooks');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,5 +53,51 @@ class Logbooks_model extends CI_Model {
|
|||
$this->db->where('logbook_id', $clean_id);
|
||||
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>
|
||||
<select name="SelectedStationLocations[]" class="form-control" id="StationLocationsSelect" multiple aria-describedby="StationLocationSelectHelp">
|
||||
<?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 } ?>
|
||||
</select>
|
||||
<small id="StationLocationSelectHelp" class="form-text text-muted">Hold down the Ctrl (windows) or Command (Mac) button to select multiple options.</small>
|
||||
|
|
@ -55,9 +55,10 @@
|
|||
</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>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
正在加载…
在新工单中引用