Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function select_deleteAll($type)//Удаление выбранных продуктов
- {
- $res_varchar = 0;
- $data = array();
- $data_my = array(
- 'warehouse' => array('dbs' => 'myshop_warehouse', 'cmd' => 'warehouse_delete'),
- 'brand' => array('dbs' => 'myshop_brands', 'cmd' => 'brands_delete'),
- 'product' => array(
- 'dbs' => 'myshop_products',
- 'cmd' => 'product_delete',
- 'cycle' => array(
- array(
- 'spec_type' => 'properties_data',
- 'spec_type_data' => 'delete',
- 'first' => 'item_id',
- ),
- ),
- ),
- 'category' => array(
- 'dbs' => 'myshop_category',
- 'cmd' => 'category_delete',
- 'cycle' => array(
- array(
- 'spec_type' => 'product',
- 'spec_type_data' => 'update',
- 'first' => 'category_id',
- 'first_data' => '0',
- ),
- array(
- 'spec_type' => array('update' => 'properties', 'delete' => 'properties_data'),
- 'spec_type_data' => 'update_delete',
- 'first' => 'category',
- 'second' => 'id',
- 'secod_data' => 'properties_id',
- ),
- ),
- ),
- 'banner' => array('dbs' => 'myshop_banners', 'cmd' => 'banner_delete'),
- 'delivery' => array('dbs' => 'myshop_delivery', 'cmd' => 'delivery_delete'),
- 'payment' => array('dbs' => 'myshop_payment', 'cmd' => 'payment_delete'),
- 'properties' => array('dbs' => 'myshop_properties', 'cmd' => 'properties_delete'),
- 'properties_data' => array('dbs' => 'myshop_properties_data', 'cmd' => 'properties_data_delete'),
- );
- if (sizeof($data_my[$type]) < 2) return false;
- $data[$data_my[$type]['cmd']] = true;
- $ids = $this->input->post('ids');
- foreach ($ids as $id)
- {
- if ($id > 0)
- {
- $this->db->where('id', $id);
- $this->db->delete($data_my[$type]['dbs']);
- $data['updated'] = true;
- if (isset($data_my[$type]['cycle']))
- {
- foreach ($data_my[$type]['cycle'] as $prop)
- {
- if ($prop['spec_type_data'] == 'update')
- {
- $data_sync = array(
- $prop['first'] => $prop['first_data'],
- );
- $this->db->where($prop['first'], $id);
- $sync = $data_my[$prop['spec_type']]['dbs'];
- $this->db->update($sync, $data_sync);
- }
- if ($prop['spec_type_data'] == 'delete')
- {
- $this->db->where($prop['first'], $id);
- $db_sync = $data_my[$prop['spec_type']]['dbs'];
- $this->db->delete($db_sync);
- }
- if ($prop['spec_type_data'] === 'update_delete')
- {
- if (isset($prop['spec_type']['update']))
- {
- $this->db->like($prop['first'], $id.',', 'both');
- $sync = $data_my[$prop['spec_type']['update']]['dbs'];
- $sync = $this->db->get($sync)->result();
- foreach ($sync as $db_sync)
- {
- $to_db = preg_replace('@'.$id.',@', '', $db_sync->$prop['first']);
- $res_varchar = $db_sync->$prop['second'];
- if (isset($prop['spec_type']['delete']))
- {
- $this->db->where($prop['secod_data'], $res_varchar);
- $sql = $data_my[$prop['spec_type']['delete']]['dbs'];
- $this->db->delete($sql);
- }
- $data_sync = array($prop['first'] => $to_db);
- $this->db->where($prop['second'], $res_varchar);
- $sql = $data_my[$prop['spec_type']['update']]['dbs'];
- if (strlen($to_db) > 1)
- {
- $this->db->update($sql, $data_sync);
- }
- else
- {
- $this->db->delete($sql);
- }
- }
- }
- }
- }
- }
- }
- }
- $this->template->add_array($data);
- $this->ajax_tpl('ajax');
- }
Advertisement
Add Comment
Please, Sign In to add comment