Create Global Constants to clarify code

This commit is contained in:
objecttothis
2020-05-19 18:06:20 +04:00
parent 35023e648f
commit f5424a3ed2
2 changed files with 10 additions and 7 deletions

View File

@@ -56,7 +56,7 @@ class Attributes extends Secure_Controller
echo json_encode(array('success' => $success));
}
public function save_definition($definition_id = 0)
public function save_definition($definition_id = NO_DEFINITION_ID)
{
$definition_flags = 0;
@@ -140,7 +140,7 @@ class Attributes extends Secure_Controller
return $definition_flag_names;
}
public function view($definition_id = 0)
public function view($definition_id = NO_DEFINITION_ID)
{
$info = $this->Attribute->get_info($definition_id);
foreach(get_object_vars($info) as $property => $value)

View File

@@ -6,6 +6,9 @@ define('DECIMAL', 'DECIMAL');
define('DATE', 'DATE');
define('TEXT', 'TEXT');
define('CHECKBOX', 'CHECKBOX');
define(NO_DEFINITION_ID,0);
define(CATEGORY_DEFINITION_ID,-1);
const DEFINITION_TYPES = [GROUP, DROPDOWN, DECIMAL, TEXT, DATE, CHECKBOX];
@@ -167,13 +170,13 @@ class Attribute extends CI_Model
return array();
}
public function get_definitions_by_type($attribute_type, $definition_id = 0)
public function get_definitions_by_type($attribute_type, $definition_id = NO_DEFINITION_ID)
{
$this->db->from('attribute_definitions');
$this->db->where('definition_type', $attribute_type);
$this->db->where('deleted', 0);
if($definition_id != -1)
if($definition_id != CATEGORY_DEFINITION_ID)
{
$this->db->where('definition_id != ', $definition_id);
}
@@ -224,7 +227,7 @@ class Attribute extends CI_Model
{
$attribute_values = [];
if($definition_id > 0 || $definition_id == -1)
if($definition_id > 0 || $definition_id == CATEGORY_DEFINITION_ID)
{
$this->db->from('attribute_links');
$this->db->join('attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id');
@@ -418,13 +421,13 @@ class Attribute extends CI_Model
/*
Inserts or updates a definition
*/
public function save_definition(&$definition_data, $definition_id = 0)
public function save_definition(&$definition_data, $definition_id = NO_DEFINITION_ID)
{
//Run these queries as a transaction, we want to make sure we do all or nothing
$this->db->trans_start();
//Definition doesn't exist
if($definition_id === 0 || !$this->exists($definition_id))
if($definition_id === NO_DEFINITION_ID || !$this->exists($definition_id))
{
if($this->exists($definition_id,TRUE))
{