Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Juan Montilla
/
TBW2223_equipo12
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a5baaf48
authored
May 06, 2023
by
Juan Montilla
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Fotos en base de datos y subida de recetas
parent
68b0e6fe
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
142 additions
and
60 deletions
app/Config/Routes.php
app/Controllers/InsertRecipeController.php
app/Controllers/RecipesController.php
app/Views/pages/home.php
app/Views/pages/recipe_view.php
app/Views/user/list.php
public/js/insert.js
app/Config/Routes.php
View file @
a5baaf48
...
...
@@ -38,9 +38,10 @@ $routes->match(['get', 'post'], '/registerAjax', [User::class, 'registerAjax']);
$routes
->
match
([
'get'
],
'/home'
,
[
User
::
class
,
'user_ok'
]);
$routes
->
get
(
'recipes/image/(:num)'
,
'RecipesController::getImage/$1'
);
// Ruta para obtener una imagen de una receta dado un id
$routes
->
get
(
'recipe/image/(:num)'
,
'RecipesController::show_image/$1'
);
// Rutas para formulario de ingresar
tare
as
// Rutas para formulario de ingresar
recet
as
$routes
->
get
(
'/insert_recipe'
,
'InsertRecipeController::index'
);
$routes
->
match
([
'get'
,
'post'
],
'/search_ingredient'
,
'InsertRecipeController::search_ingredient'
);
$routes
->
post
(
'/insert_recipe'
,
'InsertRecipeController::insert_recipe'
);
...
...
app/Controllers/InsertRecipeController.php
View file @
a5baaf48
...
...
@@ -40,6 +40,13 @@ class InsertRecipeController extends Controller
// Eliminar el elemento 'selected_ingredients' de los datos de la receta
unset
(
$recipeData
[
'selected_ingredients'
]);
// Manejar el archivo de imagen
$photo
=
$this
->
request
->
getFile
(
'photo'
);
if
(
$photo
->
isValid
()
&&
!
$photo
->
hasMoved
())
{
$photoBlob
=
file_get_contents
(
$photo
->
getRealPath
());
$recipeData
[
'photo'
]
=
$photoBlob
;
}
// Insertar la receta en la tabla 'recipes'
$recipeId
=
$recipeModel
->
insert
(
$recipeData
);
...
...
@@ -55,4 +62,5 @@ class InsertRecipeController extends Controller
// Redireccionar a la página principal (o cualquier otra página que desees)
return
redirect
()
->
to
(
'/home'
);
}
}
app/Controllers/RecipesController.php
View file @
a5baaf48
...
...
@@ -3,6 +3,7 @@
namespace
App\Controllers
;
use
App\Models\RecipesModel
;
use
App\Models\RecipesIngredientModel
;
use
CodeIgniter\Controller
;
class
RecipesController
extends
Controller
...
...
@@ -23,10 +24,26 @@ class RecipesController extends Controller
'ingredients'
=>
$ingredients
,
];
return
view
(
'templates/header'
,
$data
)
.
view
(
'pages/recipe_view'
,
$data
)
return
view
(
'templates/header'
,
$data
)
.
view
(
'pages/recipe_view'
,
$data
)
.
view
(
'templates/footer'
);
}
}
public
function
show_image
(
$id
)
{
$recipesModel
=
new
\App\Models\RecipesModel
();
$recipe
=
$recipesModel
->
find
(
$id
);
if
(
$recipe
)
{
$photo
=
$recipe
->
photo
;
$finfo
=
new
\finfo
(
FILEINFO_MIME_TYPE
);
$mimeType
=
$finfo
->
buffer
(
$photo
);
$this
->
response
->
setHeader
(
'Content-Type'
,
$mimeType
);
$this
->
response
->
setBody
(
$photo
);
$this
->
response
->
send
();
}
}
}
\ No newline at end of file
app/Views/pages/home.php
View file @
a5baaf48
...
...
@@ -187,8 +187,7 @@
<div
class=
"card info-card sales-card"
>
<div
class=
"row"
>
<div
class=
"col-md-3 imagen-container"
>
<img
src=
"imagenes/platos/
<?php
echo
$row
->
photo
;
?>
"
alt=
""
class=
"img-fluid rounded-start"
>
<img
src=
"
<?php
echo
base_url
(
'recipe/image/'
.
$row
->
id
);
?>
"
alt=
""
class=
"img-fluid rounded-start"
>
</div>
<div
class=
"col-md-9"
>
...
...
@@ -226,11 +225,6 @@
</a>
</div>
<!-- Fin de la tarjeta de la receta -->
<?php
}
}
...
...
app/Views/pages/recipe_view.php
View file @
a5baaf48
...
...
@@ -76,16 +76,16 @@ function getYoutubeVideoId($url) {
}
</style>
<main
id=
"main"
class=
"mainview"
>
<main
id=
"main
view
"
class=
"mainview"
>
<section
class=
"section dashboard"
>
<div
class=
"container"
>
<div
class=
"recipe-header"
>
<h1>
Receta:
</h1>
<h1>
<?php
echo
$recipe
->
name
;
?>
</h1>
<img
src=
"
../imagenes/platos/
<?php
echo
$recipe
->
photo
;
?>
"
alt=
"
<?php
echo
$recipe
->
name
;
?>
"
/>
<img
src=
"
<?php
echo
base_url
(
'recipe/image/'
.
$recipe
->
id
)
;
?>
"
alt=
"
<?php
echo
$recipe
->
name
;
?>
"
/>
</div>
<p>
<?php
echo
$recipe
->
description
;
?>
</p>
...
...
app/Views/user/list.php
View file @
a5baaf48
<h1>
User list
</h1>
<h1>
Admin Page
</h1>
<h2>
Lista de usuarios
</h2>
<!-- LISTA DE USUARIOS -->
<?php
if
(
sizeof
(
$users
)
>
0
)
{
foreach
(
$users
as
$row
)
{
...
...
@@ -9,4 +11,75 @@ if (sizeof($users) > 0) {
}
}
else
{
echo
"No user"
;
}
\ No newline at end of file
}
?>
<h2>
Recetas
</h2>
<!-- LISTA DE RECETAS -->
<?php
$recipesModel
=
new
\App\Models\RecipesModel
();
$recipes
=
$recipesModel
->
findAll
();
?>
<table
class=
"table"
>
<thead>
<tr>
<th>
ID
</th>
<th>
Nombre
</th>
<th>
Temporada
</th>
<th>
Origen
</th>
<th>
Foto
</th>
<th>
Vegano
</th>
<th>
Descripción
</th>
<th>
Instrucciones
</th>
<th>
Enlace
</th>
<th>
Acciones
</th>
</tr>
</thead>
<tbody>
<?php
foreach
(
$recipes
as
$row
)
:
?>
<tr>
<td>
<?=
$row
->
id
;
?>
</td>
<td>
<?=
$row
->
name
;
?>
</td>
<td>
<?=
$row
->
season
;
?>
</td>
<td>
<?=
$row
->
origin
;
?>
</td>
<td>
<img
src=
"
<?=
base_url
(
'recipe/image/'
.
$row
->
id
);
?>
"
alt=
""
class=
"img-thumbnail"
style=
"width: 100px;"
>
</td>
<td>
<?=
$row
->
is_vegan
?
'Sí'
:
'No'
;
?>
</td>
<td>
<?=
mb_strimwidth
(
$row
->
description
,
0
,
10
,
"..."
);
?>
</td>
<td>
<?=
mb_strimwidth
(
$row
->
instructions
,
0
,
10
,
"..."
);
?>
</td>
<td>
<?=
$row
->
link
;
?>
</td>
<td>
<button
class=
"btn btn-danger"
onclick=
"deleteRecipe(
<?=
$row
->
id
;
?>
)"
>
Borrar
</button>
</td>
</tr>
<?php
endforeach
;
?>
</tbody>
</table>
<script>
function
borrarReceta
(
recipeId
)
{
//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa
}
</script>
\ No newline at end of file
public/js/insert.js
View file @
a5baaf48
...
...
@@ -109,50 +109,38 @@ function removeIngredient(ingredient) {
function
updateSelectedIngredients
()
{
// Limpiar el campo de selección
selectedIngredients
.
innerHTML
=
''
;
// Agregar cada ingrediente seleccionado al campo de selección
ingredients
.
forEach
(
function
(
ingredient
)
{
const
ingredientElement
=
document
.
createElement
(
'div'
);
ingredientElement
.
classList
.
add
(
'selected-ingredient'
);
ingredientElement
.
setAttribute
(
'data-id'
,
ingredient
.
id
);
// Crear el elemento de imagen para el icono del ingrediente
const
iconElement
=
document
.
createElement
(
'img'
);
iconElement
.
classList
.
add
(
'ingredient-icon'
);
iconElement
.
src
=
'../imagenes/ingredientes/'
+
ingredient
.
icon
;
ingredientElement
.
appendChild
(
iconElement
);
const
ingredientNameAndQuantity
=
document
.
createTextNode
(
`
${
ingredient
.
name
}
(
${
ingredient
.
quantity
}
)`
);
ingredientElement
.
appendChild
(
ingredientNameAndQuantity
);
const
removeBtn
=
document
.
createElement
(
'button'
);
removeBtn
.
classList
.
add
(
'btn'
,
'btn-danger'
,
'btn-sm'
);
removeBtn
.
textContent
=
'x'
;
removeBtn
.
addEventListener
(
'click'
,
function
()
{
removeIngredient
(
ingredient
);
});
ingredientElement
.
appendChild
(
removeBtn
);
selectedIngredients
.
appendChild
(
ingredientElement
);
// Crear un campo oculto para almacenar el ID y la cantidad del ingrediente seleccionado
const
hiddenInputId
=
document
.
createElement
(
'input'
);
hiddenInputId
.
setAttribute
(
'type'
,
'hidden'
);
hiddenInputId
.
setAttribute
(
'name'
,
'selected_ingredient_ids[]'
);
hiddenInputId
.
setAttribute
(
'value'
,
ingredient
.
id
);
ingredientElement
.
appendChild
(
hiddenInputId
);
const
hiddenInputQuantity
=
document
.
createElement
(
'input'
);
hiddenInputQuantity
.
setAttribute
(
'type'
,
'hidden'
);
hiddenInputQuantity
.
setAttribute
(
'name'
,
'selected_ingredient_quantities[]'
);
hiddenInputQuantity
.
setAttribute
(
'value'
,
ingredient
.
quantity
);
ingredientElement
.
appendChild
(
hiddenInputQuantity
);
selectedIngredients
.
appendChild
(
ingredientElement
);
const
ingredientElement
=
document
.
createElement
(
'div'
);
ingredientElement
.
classList
.
add
(
'selected-ingredient'
);
ingredientElement
.
setAttribute
(
'data-ingredient-id'
,
ingredient
.
id
);
// Crear el elemento de imagen para el icono del ingrediente
const
iconElement
=
document
.
createElement
(
'img'
);
iconElement
.
classList
.
add
(
'ingredient-icon'
);
iconElement
.
src
=
'../imagenes/ingredientes/'
+
ingredient
.
icon
;
ingredientElement
.
appendChild
(
iconElement
);
// Agregar el nombre del ingrediente y la cantidad
const
ingredientNameAndQuantity
=
document
.
createElement
(
'span'
);
ingredientNameAndQuantity
.
textContent
=
`
${
ingredient
.
name
}
(
${
ingredient
.
quantity
}
)`
;
ingredientNameAndQuantity
.
classList
.
add
(
'ingredient-amount'
);
ingredientElement
.
appendChild
(
ingredientNameAndQuantity
);
// Agregar el botón para eliminar el ingrediente
const
removeBtn
=
document
.
createElement
(
'button'
);
removeBtn
.
classList
.
add
(
'btn'
,
'btn-danger'
,
'btn-sm'
);
removeBtn
.
textContent
=
'x'
;
removeBtn
.
addEventListener
(
'click'
,
function
()
{
removeIngredient
(
ingredient
);
});
ingredientElement
.
appendChild
(
removeBtn
);
selectedIngredients
.
appendChild
(
ingredientElement
);
});
}
}
...
...
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