Commit e141011e by David Villalba

Modificar menus personalizados.

parent bfbb32b7
......@@ -36,13 +36,17 @@ class Controller_Menupersonalizado_Index extends \Controller_App{
$view->auto_filter(false);
// $view->Model_Recipe = new Model_Recipe();
$view->model_Recipe = new Model_Recipe();
return Response::forge($view);
}
public function post_update(){
try{
DB::start_transaction();
$ids_recipes_selected = array();
foreach (\Input::post('input') as $item){
......@@ -66,9 +70,21 @@ class Controller_Menupersonalizado_Index extends \Controller_App{
}
// // Borramos las que no esten seleccionadas.
// \Model_Recipe::recipes_current_week()->where('recipe_id','NOT IN', $ids_recipes_selected)->delete();
//
// Borramos las que no esten seleccionadas.
\Model_Recipe::recipes_current_week()->where('recipe_id','NOT IN', $ids_recipes_selected)->delete();
DB::commit_transaction();
return json_encode(true);
}catch (\Exception $e){
\Fuel\Core\Log::error("Error al guardar el menu personalizado --> ".$e->getMessage().' - '.$e->getFile() .' - '. $e->getLine() );
DB::rollback_transaction();
return json_encode(false);
}
}
......
......@@ -34,6 +34,15 @@ class Model_Recipe extends Model{
),
);
protected static $_observers = array(
'Orm\\Observer_CreatedAt'=> array(
'events' => array('before_insert'),
'mysql_timestamp' => true,
'property' => 'created_at',
'overwrite' => true
)
);
public static function get_recipes_current_week()
{
//Devolvemos recetas guardadas en la base de datos que correspondan a esta vista.
......@@ -102,16 +111,17 @@ class Model_Recipe extends Model{
/**
*
* Comprueba si exite una receta.
* Comprueba si tiene seleccinoada una receta.
*
* @param $recipe_id
* @return Model
* @return bool
*/
public static function exist_recipe($id){
public static function exist_recipe($recipe_id){
$return = self::recipes_current_week()->where('recipe_id',$recipe_id)->get_one();
// return self::recipes_current_week()->where('recipe_id',$recipe_id)->get_one();
return self::recipes_current_week()->get_one();
return $return ? true : false;
}
}
\ No newline at end of file
......@@ -60,7 +60,7 @@
<a href="{{ url('receta-detalle/update/'~day.lunchFirst[0].id) }}" target="_blank">
<div class="row">
<div class="col-xs-11 plr0">
<input
<input {% if model_Recipe.exist_recipe(day.lunchFirst[0].id) %} checked {% endif %}
id="{{ day.lunchFirst[0].id }}"
name="{{ day.ds }}_lunchFirst"
value="{{ day.lunchFirst[0].id }}"
......@@ -77,7 +77,7 @@
<a href="{{ url('receta-detalle/update/'~day.lunchFirst[1].id) }}" target="_blank">
<div class="row mt20">
<div class="col-xs-11 plr0">
<input
<input {% if model_Recipe.exist_recipe(day.lunchFirst[1].id) %} checked {% endif %}
id="{{ day.lunchFirst[1].id }}"
name="{{ day.ds }}_lunchFirst"
value="{{ day.lunchFirst[1].id }}"
......@@ -106,7 +106,7 @@
<a href="{{ url('receta-detalle/update/'~day.lunchSecond[0].id) }}" target="_blank">
<div class="row">
<div class="col-xs-11 plr0">
<input
<input {% if model_Recipe.exist_recipe(day.lunchSecond[0].id) %} checked {% endif %}
id="{{ day.lunchSecond[0].id }}"
name="{{ day.ds }}_lunchSecond"
value="{{ day.lunchSecond[0].id }}"
......@@ -124,7 +124,7 @@
<a href="{{ url('receta-detalle/update/'~day.lunchSecond[1].id) }}" target="_blank">
<div class="row mt20">
<div class="col-xs-11 plr0">
<input
<input {% if model_Recipe.exist_recipe(day.lunchSecond[1].id) %} checked {% endif %}
id="{{ day.lunchSecond[1].id }}"
name="{{ day.ds }}_lunchSecond"
value="{{ day.lunchSecond[1].id }}"
......@@ -157,7 +157,7 @@
<a href="{{ url('receta-detalle/update/'~day.dinnerFirst[0].id) }}" target="_blank">
<div class="row">
<div class="col-xs-11 plr0">
<input
<input {% if model_Recipe.exist_recipe(day.dinnerFirst[0].id) %} checked {% endif %}
id="{{ day.dinnerFirst[0].id }}"
name="{{ day.ds }}_dinnerFirst"
value="{{ day.dinnerFirst[0].id }}"
......@@ -175,7 +175,7 @@
<a href="{{ url('receta-detalle/update/'~day.dinnerFirst[1].id) }}" target="_blank">
<div class="row mt20">
<div class="col-xs-11 plr0">
<input
<input {% if model_Recipe.exist_recipe(day.dinnerFirst[1].id) %} checked {% endif %}
id="{{ day.dinnerFirst[1].id }}"
name="{{ day.ds }}_dinnerFirst"
value="{{ day.dinnerFirst[1].id }}"
......@@ -204,7 +204,7 @@
<a href="{{ url('receta-detalle/update/'~day.dinnerSecond[0].id) }}" target="_blank">
<div class="row">
<div class="col-xs-11 plr0">
<input
<input {% if model_Recipe.exist_recipe(day.dinnerSecond[0].id) %} checked {% endif %}
id="{{ day.dinnerSecond[0].id }}"
name="{{ day.ds }}_dinnerSecond"
value="{{ day.dinnerSecond[0].id }}"
......@@ -222,7 +222,7 @@
<a href="{{ url('receta-detalle/update/'~day.dinnerSecond[1].id) }}" target="_blank">
<div class="row mt20">
<div class="col-xs-11 plr0">
<input
<input {% if model_Recipe.exist_recipe(day.dinnerSecond[1].id) %} checked {% endif %}
id="{{ day.dinnerSecond[1].id }}"
name="{{ day.ds }}_dinnerSecond"
value="{{ day.dinnerSecond[1].id }}"
......
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