Added the creation and removal of ospos_category attribute

- Added undelete function in Attribute model which could be useful for
adding the ability to restore attributes once deleted.
- Added business logic to Config controller save_general to
create/remove the attribute when the box is checked or unchecked.
This commit is contained in:
objecttothis
2020-05-04 16:45:58 +04:00
parent 231fe483d9
commit 96bfa330ba
3 changed files with 38 additions and 6 deletions

View File

@@ -56,7 +56,7 @@ class Attributes extends Secure_Controller
echo json_encode(array('success' => $success));
}
public function save_definition($definition_id = -1)
public function save_definition($definition_id = 0)
{
$definition_flags = 0;

View File

@@ -299,7 +299,22 @@ class Config extends Secure_Controller
);
$this->Module->set_show_office_group($this->input->post('show_office_group') != NULL);
if($batch_save_data['category_dropdown'] == 1)
{
$definition_data['definition_name'] = 'ospos_category';
$definition_data['definition_flags'] = 0;
$definition_data['definition_type'] = 'DROPDOWN';
$definition_data['definition_id'] = -1;
$definition_data['deleted'] = 0;
$this->Attribute->save_definition($definition_data, -1);
}
else if($batch_save_data['category_dropdown'] == 0)
{
$this->Attribute->delete_definition(-1);
}
$result = $this->Appconfig->batch_save($batch_save_data);
$success = $result ? TRUE : FALSE;

View File

@@ -418,16 +418,23 @@ class Attribute extends CI_Model
/*
Inserts or updates a definition
*/
public function save_definition(&$definition_data, $definition_id = -1)
public function save_definition(&$definition_data, $definition_id = 0)
{
//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 === -1 || !$this->exists($definition_id))
if($definition_id === 0 || !$this->exists($definition_id))
{
$success = $this->db->insert('attribute_definitions', $definition_data);
$definition_data['definition_id'] = $this->db->insert_id();
if($this->exists($definition_id,TRUE))
{
$success = $this->undelete($definition_id);
}
else
{
$success = $this->db->insert('attribute_definitions', $definition_data);
$definition_data['definition_id'] = $this->db->insert_id();
}
}
//Definition already exists
@@ -667,4 +674,14 @@ class Attribute extends CI_Model
return $this->db->update('attribute_definitions', array('deleted' => 1));
}
/*
Undeletes one attribute definition
*/
public function undelete($definition_id)
{
$this->db->where('definition_id', $definition_id);
return $this->db->update('attribute_definitions', array('deleted'=>0));
}
}