Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
2018_web_app
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
inutralia
2018_web_app
Commits
e141011e
Commit
e141011e
authored
Dec 11, 2018
by
David Villalba
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modificar menus personalizados.
parent
bfbb32b7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
31 deletions
+58
-31
index.php
fuel/app/classes/controller/menupersonalizado/index.php
+34
-18
recipe.php
fuel/app/classes/model/recipe.php
+16
-5
index.twig
fuel/app/views/menupersonalizado/index.twig
+8
-8
No files found.
fuel/app/classes/controller/menupersonalizado/index.php
View file @
e141011e
...
...
@@ -36,39 +36,55 @@ class Controller_Menupersonalizado_Index extends \Controller_App{
$view
->
auto_filter
(
false
);
// $view->M
odel_Recipe = new Model_Recipe();
$view
->
m
odel_Recipe
=
new
Model_Recipe
();
return
Response
::
forge
(
$view
);
}
public
function
post_update
(){
$ids_recipes_selected
=
array
();
try
{
foreach
(
\Input
::
post
(
'input'
)
as
$item
){
DB
::
start_transaction
();
array_push
(
$ids_recipes_selected
,
$item
[
'recipe_id'
]
);
$ids_recipes_selected
=
array
(
);
$conditions
=
array
(
'user_id'
=>
\Session
::
get
(
'user_id'
),
'year'
=>
date
(
'Y'
),
'week_year'
=>
date
(
"W"
),
'recipe_id'
=>
$item
[
'recipe_id'
],
'option'
=>
$item
[
'option'
],
'day_week'
=>
$item
[
'day_week'
],
);
foreach
(
\Input
::
post
(
'input'
)
as
$item
){
$query
=
Model_Recipe
::
find
(
'all'
,
array
(
'where'
=>
$conditions
));
array_push
(
$ids_recipes_selected
,
$item
[
'recipe_id'
]);
$conditions
=
array
(
'user_id'
=>
\Session
::
get
(
'user_id'
),
'year'
=>
date
(
'Y'
),
'week_year'
=>
date
(
"W"
),
'recipe_id'
=>
$item
[
'recipe_id'
],
'option'
=>
$item
[
'option'
],
'day_week'
=>
$item
[
'day_week'
],
);
$query
=
Model_Recipe
::
find
(
'all'
,
array
(
'where'
=>
$conditions
));
if
(
!
$query
){
Model_Recipe
::
forge
(
$conditions
)
->
save
();
}
if
(
!
$query
){
Model_Recipe
::
forge
(
$conditions
)
->
save
();
}
// 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
);
}
// // Borramos las que no esten seleccionadas.
// \Model_Recipe::recipes_current_week()->where('recipe_id','NOT IN', $ids_recipes_selected)->delete();
//
}
...
...
fuel/app/classes/model/recipe.php
View file @
e141011e
...
...
@@ -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
Mode
l
* @return
boo
l
*/
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
fuel/app/views/menupersonalizado/index.twig
View file @
e141011e
...
...
@@ -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
}}
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment