cloudlog/application/models/Options_model.php
Peter Goodhall e34afd51eb Allow partial option saves and surface save errors
Change success logic in Options controller to treat the save as successful if any individual option update persisted (use OR instead of AND), preventing a single-failure from marking the whole operation as failed. Fix Options_model to return TRUE after inserting a new option so inserts are reported as successful. Add a saveFailed flash message display in the email options view so users see explicit failure alerts when appropriate.
2026-04-26 18:04:58 +01:00

94 lines
2 KiB
PHP

<?php
/*
Class: Options_model
This model handles all database interactions for the options table
used for global settings within cloudlog.
*/
class Options_model extends CI_Model {
// Returns all options that are autoload yes
function get_autoloads() {
$this->db->where('autoload', "yes");
return $this->db->get('options');
}
// Return option value for an option
function item($option_name) {
$this->db->where('option_name', $option_name);
$query = $this->db->get('options');
$row = $query->row();
if (isset($row->option_value)) {
return $row->option_value;
}
return null;
}
/*
*
* Saves an option to the database
*
* Parameters
* - option_name: name of the option with no spaces
* - option_value: the value of the option name
* - autoload: this is whether it needs to be loaded every page load set to yes or no
*/
function save($option_name, $option_value, $autoload) {
$this->db->where('option_name', $option_name);
$query = $this->db->get('options');
if($query->num_rows() > 0) {
// Update the Entry
return FALSE;
} else {
$data = array(
'option_name' => $option_name,
'option_value' => $option_value,
'autoload' => $autoload,
);
// Save to database
$this->db->insert('options', $data);
return TRUE;
}
}
/*
*
* Saves an update to option
*
* Parameters
* - option_name: name of the option with no spaces
* - option_value: the value of the option name
*/
function update($option_name, $option_value, $auto_load = NULL) {
$this->db->where('option_name', $option_name);
$query = $this->db->get('options');
$data = array(
'option_name' => $option_name,
'option_value' => $option_value,
'autoload' => $auto_load,
);
if($query->num_rows() > 0) {
// Update the Entry
$this->db->where('option_name', $option_name);
$this->db->update('options', $data);
return TRUE;
} else {
// Save to database
$this->db->insert('options', $data);
return TRUE;
}
}
}
?>