zeloras

Untitled

Mar 12th, 2013
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. public function select_deleteAll($type)//Удаление выбранных продуктов
  2. {
  3. $res_varchar = 0;
  4. $data = array();
  5. $data_my = array(
  6. 'warehouse' => array('dbs' => 'myshop_warehouse', 'cmd' => 'warehouse_delete'),
  7. 'brand' => array('dbs' => 'myshop_brands', 'cmd' => 'brands_delete'),
  8. 'product' => array(
  9. 'dbs' => 'myshop_products',
  10. 'cmd' => 'product_delete',
  11. 'cycle' => array(
  12. array(
  13. 'spec_type' => 'properties_data',
  14. 'spec_type_data' => 'delete',
  15. 'first' => 'item_id',
  16. ),
  17.  
  18. ),
  19. ),
  20.  
  21. 'category' => array(
  22. 'dbs' => 'myshop_category',
  23. 'cmd' => 'category_delete',
  24. 'cycle' => array(
  25. array(
  26. 'spec_type' => 'product',
  27. 'spec_type_data' => 'update',
  28. 'first' => 'category_id',
  29. 'first_data' => '0',
  30. ),
  31.  
  32. array(
  33. 'spec_type' => array('update' => 'properties', 'delete' => 'properties_data'),
  34. 'spec_type_data' => 'update_delete',
  35. 'first' => 'category',
  36. 'second' => 'id',
  37. 'secod_data' => 'properties_id',
  38. ),
  39.  
  40. ),
  41. ),
  42.  
  43. 'banner' => array('dbs' => 'myshop_banners', 'cmd' => 'banner_delete'),
  44. 'delivery' => array('dbs' => 'myshop_delivery', 'cmd' => 'delivery_delete'),
  45. 'payment' => array('dbs' => 'myshop_payment', 'cmd' => 'payment_delete'),
  46. 'properties' => array('dbs' => 'myshop_properties', 'cmd' => 'properties_delete'),
  47. 'properties_data' => array('dbs' => 'myshop_properties_data', 'cmd' => 'properties_data_delete'),
  48.  
  49. );
  50. if (sizeof($data_my[$type]) < 2) return false;
  51. $data[$data_my[$type]['cmd']] = true;
  52. $ids = $this->input->post('ids');
  53. foreach ($ids as $id)
  54. {
  55. if ($id > 0)
  56. {
  57. $this->db->where('id', $id);
  58. $this->db->delete($data_my[$type]['dbs']);
  59. $data['updated'] = true;
  60. if (isset($data_my[$type]['cycle']))
  61. {
  62. foreach ($data_my[$type]['cycle'] as $prop)
  63. {
  64. if ($prop['spec_type_data'] == 'update')
  65. {
  66. $data_sync = array(
  67. $prop['first'] => $prop['first_data'],
  68. );
  69. $this->db->where($prop['first'], $id);
  70. $sync = $data_my[$prop['spec_type']]['dbs'];
  71. $this->db->update($sync, $data_sync);
  72. }
  73.  
  74. if ($prop['spec_type_data'] == 'delete')
  75. {
  76. $this->db->where($prop['first'], $id);
  77. $db_sync = $data_my[$prop['spec_type']]['dbs'];
  78. $this->db->delete($db_sync);
  79. }
  80.  
  81. if ($prop['spec_type_data'] === 'update_delete')
  82. {
  83. if (isset($prop['spec_type']['update']))
  84. {
  85. $this->db->like($prop['first'], $id.',', 'both');
  86. $sync = $data_my[$prop['spec_type']['update']]['dbs'];
  87. $sync = $this->db->get($sync)->result();
  88. foreach ($sync as $db_sync)
  89. {
  90. $to_db = preg_replace('@'.$id.',@', '', $db_sync->$prop['first']);
  91. $res_varchar = $db_sync->$prop['second'];
  92. if (isset($prop['spec_type']['delete']))
  93. {
  94. $this->db->where($prop['secod_data'], $res_varchar);
  95. $sql = $data_my[$prop['spec_type']['delete']]['dbs'];
  96. $this->db->delete($sql);
  97. }
  98. $data_sync = array($prop['first'] => $to_db);
  99. $this->db->where($prop['second'], $res_varchar);
  100. $sql = $data_my[$prop['spec_type']['update']]['dbs'];
  101. if (strlen($to_db) > 1)
  102. {
  103. $this->db->update($sql, $data_sync);
  104. }
  105. else
  106. {
  107. $this->db->delete($sql);
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115. }
  116. $this->template->add_array($data);
  117. $this->ajax_tpl('ajax');
  118. }
Advertisement
Add Comment
Please, Sign In to add comment