From 2c06edba0213d520ce7bb4ee9176e16e6f7db3d7 Mon Sep 17 00:00:00 2001 From: objecttothis Date: Wed, 30 Jan 2019 11:30:28 +0400 Subject: [PATCH] Remove function and combine call to reduce redundant code. --- application/models/Attribute.php | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/application/models/Attribute.php b/application/models/Attribute.php index f03e5b632..c2edfe9b7 100644 --- a/application/models/Attribute.php +++ b/application/models/Attribute.php @@ -57,14 +57,15 @@ class Attribute extends CI_Model } /* - Determines if a given attribute_value exists in the attribute_values table + Determines if a given attribute_value exists in the attribute_values table and returns the attribute_id if it does */ public function value_exists($attribute_value) { + $this->db->distinct('attribute_id'); $this->db->from('attribute_values'); $this->db->where('attribute_value', $attribute_value); - return ($this->db->get()->num_rows() > 0); + return $this->db->get()->row()->attribute_id; } /* @@ -122,18 +123,6 @@ class Attribute extends CI_Model return $this->db->get(); } - /* - Given the attribute_value returns the associated attribute_id - */ - private function get_id_by_value($attribute_value) - { - $this->db->distinct('attribute_id'); - $this->db->from('attribute_values'); - $this->db->where('attribute_value',$attribute_value); - - return $this->db->get()->row()->attribute_id; - } - public function get_attributes_by_item($item_id) { $this->db->from('attribute_definitions'); @@ -422,15 +411,16 @@ class Attribute extends CI_Model { if($definition_type != DATETIME) { - if($this->value_exists($attribute_value)) - { - $attribute_id = $this->get_id_by_value($attribute_value); - } - else + $attribute_id_check = $this->value_exists($attribute_value); + if(empty($attribute_id_check)) { $this->db->insert('attribute_values', array('attribute_value' => $attribute_value)); $attribute_id = $this->db->insert_id(); } + else + { + $attribute_id = $attribute_id_check; + } } else {