Commit 246daf5a by Luis Perez

Lista de la compra con borrado de datos.

parent 5388e281
...@@ -67,4 +67,31 @@ class Controller_Listacompra_Index extends \Controller_App{ ...@@ -67,4 +67,31 @@ class Controller_Listacompra_Index extends \Controller_App{
return Response::forge($view); return Response::forge($view);
} }
public function get_delete_all()
{
$recipes = Model_Recipe::get_recipes_current_week();
foreach ($recipes as $recipe)
{
Log::error("ENTRO EN RECETAS!!!");
foreach ($recipe->ingredients as $ingrediente)
{
Log::error("INTENTO BORRAR INGREDIENTE!!! $ingrediente->id");
$ingrediente->delete();
}
}
Session::set_flash('success', "Se han borrado los ingredientes correctamente");
return Response::redirect_back();
}
public function post_delete_ingredients()
{
$ingredients = Input::post('ingredients_ids');
foreach ($ingredients as $ingredient)
{
$ingredient->delete();
}
}
} }
\ No newline at end of file
...@@ -45,7 +45,7 @@ class Controller_Menupersonalizado_Index extends \Controller_App{ ...@@ -45,7 +45,7 @@ class Controller_Menupersonalizado_Index extends \Controller_App{
foreach (\Input::post('input') as $item){ foreach (\Input::post('input') as $item){
array_push($ids_recipes_selected,$this['recipe_id']); array_push($ids_recipes_selected,$item['recipe_id']);
$conditions = array( $conditions = array(
'user_id' => \Session::get('user_id'), 'user_id' => \Session::get('user_id'),
......
...@@ -22,7 +22,7 @@ class Model_Ingredient extends Model{ ...@@ -22,7 +22,7 @@ class Model_Ingredient extends Model{
protected static $_belongs_to = array( protected static $_belongs_to = array(
'recipe' => array( 'recipe' => array(
'key_from' => 'recipe_local_od', 'key_from' => 'recipe_local_id',
'key_to' => 'id', 'key_to' => 'id',
'model_to' => 'Model_Recipe', 'model_to' => 'Model_Recipe',
'cascade_delete' => false 'cascade_delete' => false
......
...@@ -27,7 +27,7 @@ class Model_Recipe extends Model{ ...@@ -27,7 +27,7 @@ class Model_Recipe extends Model{
'model_to' => 'Model_Ingredient', 'model_to' => 'Model_Ingredient',
'cascade_delete' => false, 'cascade_delete' => false,
'conditions' => array( 'conditions' => array(
'where' => array('used' => 0), 'where' => array('used' => 'N'),
'order_by' => array('used' => 'DESC'), 'order_by' => array('used' => 'DESC'),
'group_by' => 'ingredient_id' 'group_by' => 'ingredient_id'
) )
......
...@@ -53,6 +53,7 @@ return array( ...@@ -53,6 +53,7 @@ return array(
'articulo-detalle' => 'articulo/index', 'articulo-detalle' => 'articulo/index',
'lista-compra' => 'listacompra/index', 'lista-compra' => 'listacompra/index',
'lista-compra/delete_all' => 'listacompra/index/delete_all',
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
<div class="container-box-border-box"> <div class="container-box-border-box">
<form class="ac-custom ac-checkbox" autocomplete="off"> <form class="ac-custom ac-checkbox" autocomplete="off">
<ul class="text-left ml0"> <ul class="text-left ml0">
{% if count(ingredients) == 0 %}
<h4>Sin Ingredientes</h4>
{% endif %}
{% for i in ingredients %} {% for i in ingredients %}
<li> <input id="check_{{ i.id }}" name="check_{{ i.id }}" type="checkbox" checked="true"/><label for="check_{{ i.id }}">{{ i.desc }}</label></li> <li> <input id="check_{{ i.id }}" name="check_{{ i.id }}" type="checkbox" checked="true"/><label for="check_{{ i.id }}">{{ i.desc }}</label></li>
{% endfor %} {% endfor %}
...@@ -60,7 +63,8 @@ ...@@ -60,7 +63,8 @@
<!--modal add producto--> <!--modal add producto-->
{% include 'modal_add_product.twig' %} {% include 'modal_add_product.twig' %}
<!--modal delete--> <!--modal delete-->
{% include 'modals/modal_delete.twig' %} {% include 'modal_delete_all.twig' %}
{% include 'modal_delete.twig' %}
{% endblock %} {% endblock %}
......
<!-- Modal DELETE PRODUCTOS -->
<div class="modal fade" id="modalDelete" tabindex="-1" role="dialog" aria-labelledby="modalDelete">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<div class="text-center">
<img src="assets/img/listacompra/delete.png" class="img-responsive-custom"/>
</div>
<h2 class="text-center">¿BORRAR?</h2>
<div class="content text-center pb40">
{{ action }}
</div>
<div class="modal-footer">
<div class="row">
<div class="col-md-6">
<button type="button" class="btn btn-custom btn-other" data-dismiss="modal">Cancelar</button>
</div>
<div class="col-md-6">
<a href="lista-compra/delete_all" type="button" class="btn btn-custom btn-danger">Sí, borrarlos</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment