Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. //Controller: administracao.php
  2. function update_ordenacao(){
  3. $this->load->model("administracao_model");
  4.  
  5. $ordemCat = array (
  6. // coluna // campo form
  7. "id_categoria_anuncio" => $this->input->post("id_categoria_anuncio"),
  8. "page_id_categoria_anuncio" => $this->input->post("ordenacao"),
  9. );
  10.  
  11. $sucesso = $this->administracao_model->ordenacaoCats($ordemCat);
  12.  
  13. if($sucesso) {
  14. $this->session->set_flashdata("success", "Ordem alterada com sucesso!");
  15. redirect("administracao/ver_cat_anuncios");
  16. } else {
  17. $this->session->set_flashdata("danger", "A ordem das categorias não pode ser alterada!");
  18. redirect("administracao/ver_cat_anuncios");
  19. }
  20.  
  21.  
  22. }
  23.  
  24. // Model: administracao_model.php
  25. function ordenacaoCats($ordemCat){
  26.  
  27. $data = array(
  28. array(
  29. 'id_categoria_anuncio' => $ordemCat['id_categoria_anuncio'] ,
  30. 'page_id_categoria_anuncio' => $ordemCat['page_id_categoria_anuncio']
  31. )
  32. );
  33.  
  34. $this->db->update_batch('categorias_anuncios', $data, 'id_categoria_anuncio');
  35. //echo $this->db->last_query();
  36.  
  37.  
  38. }
  39.  
  40. //View: ver_cat_anuncios.php
  41.  
  42. <?php echo form_open("administracao/update_ordenacao", array('id' =>'categorias-dos-anuncios')); ?>
  43. <table class="table table-striped">
  44. <tr>
  45. <th>#</th>
  46. <th>Nome da Categoria</th>
  47. <th>Ordenação <?php echo form_button(array( "class" => "btn-ordenacao fa fa-floppy-o", "content" => "", "type" => "submit" )); ?></th>
  48. <th>Status</th>
  49. <th>Ações</th>
  50. </tr>
  51.  
  52. <?php if (count($categorias)) : foreach ($categorias as $categoria) :?>
  53. <tr>
  54. <td><?=$categoria['id_categoria_anuncio']; ?></td>
  55. <?php ($categoria['is_parent_categoria_anuncio'] !== "0") ? $espacamento = " " : $espacamento = "- "; ?>
  56.  
  57. <td><?= anchor('administracao/edit_cat_anuncios/' .$categoria['id_categoria_anuncio'], $espacamento.$categoria['titulo_categoria_anuncio']);?></td>
  58. <td>
  59. <div class="form-group">
  60. <?= form_hidden('id_categoria_anuncio', $categoria['id_categoria_anuncio']);?>
  61. <?= form_input(array(
  62. "name" => "ordenacao",
  63. "value" => $categoria['page_id_categoria_anuncio'],
  64. "id" => "ordenacao",
  65. "class" => "form-control",
  66. "maxlength" => "3",
  67. "style" => "width: 60px; text-align: center;"
  68. )); ?>
  69. </div>
  70. </td>
  71. <td><?php if($categoria['show_menu_categoria_anuncio'] == 1) {echo "<span style="color: #009202; font-weight: bold;">Ativado</span>";} else {echo "<span style="color: #e10707; font-weight: bold;">Desativado</span>";} ?> </td>
  72. <td>
  73. <div class="btn-group" role="group" aria-label="Ações">
  74. <?= btn_edit('administracao/edit_cat_anuncios/'. $categoria['id_categoria_anuncio'] );?>
  75. <?= btn_delete('administracao/deleta_cat_anuncios/'. $categoria['id_categoria_anuncio'] );?>
  76. </div>
  77. </td>
  78. </tr>
  79. <?php endforeach; ?>
  80. <?php else: ?>
  81. <tr>
  82. <td colspan="5"><p class="text-info">Não há nenhuma categoria no sistema!</p></td>
  83. </tr>
  84.  
  85. <?php endif;?>
  86. </table>
  87. <?php echo form_close(); ?>
  88.  
  89. $data = array(
  90. array(
  91. 'title' => 'My title' ,
  92. 'name' => 'My Name 2' ,
  93. 'date' => 'My date 2'
  94. ),
  95. array(
  96. 'title' => 'Another title' ,
  97. 'name' => 'Another Name 2' ,
  98. 'date' => 'Another date 2'
  99. )
  100. );
  101.  
  102. $this->db->update_batch('mytable', $data, 'title');
  103.  
  104. // Produces:
  105. // UPDATE `mytable` SET `name` = CASE
  106. // WHEN `title` = 'My title' THEN 'My Name 2'
  107. // WHEN `title` = 'Another title' THEN 'Another Name 2'
  108. // ELSE `name` END,
  109. // `date` = CASE
  110. // WHEN `title` = 'My title' THEN 'My date 2'
  111. // WHEN `title` = 'Another title' THEN 'Another date 2'
  112. // ELSE `date` END
  113. // WHERE `title` IN ('My title','Another title')
  114.  
  115. <?= form_input(array(
  116. "name" => "ordenacao[]",
  117. "value" => $categoria['page_id_categoria_anuncio'],
  118. "id" => "ordenacao[]",
  119. "class" => "form-control",
  120. "maxlength" => "3",
  121. "style" => "width: 60px; text-align: center;"
  122. )); ?>
  123.  
  124. function ordenacaoCats($ordemCat){
  125.  
  126. $data = array();
  127.  
  128. foreach ($ordemCat['page_id_categoria_anuncio'] as $ord) {
  129. $data[] = array(
  130. 'id_categoria_anuncio' => $ordemCat['id_categoria_anuncio'] ,
  131. 'page_id_categoria_anuncio' => $ord
  132. );
  133. }
  134.  
  135. $this->db->update_batch('categorias_anuncios', $data, 'id_categoria_anuncio');
  136. //echo $this->db->last_query();
  137.  
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement