Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

URGENT!!! all required codes to solve the question are provided recipies.json { Poppy seed roll : [ poppyseed , sugar , milk , egg ,

URGENT!!! all required codes to solve the question are provided image text in transcribed
recipies.json
{
"Poppy seed roll": [
"poppyseed",
"sugar",
"milk",
"egg",
"yeast",
"flour"
],
"Gingerbread": [
"flour",
"sugar",
"egg",
"honey",
"butter",
"bakingsoda"
],
"Coconut balls": [
"coconut",
"sugar",
"vanilla",
"butter",
"milk",
"biscuit"
],
"Tiramisu": [
"mascarpone",
"coffee",
"sugar",
"egg",
"cocoa",
"ladyfinger"
],
"Zserb": [
"peach",
"milk",
"sugar",
"yeast",
"flour",
"butter",
"walnut"
]
}
storage.php
interface IFileIO {
function save($data);
function load();
}
abstract class FileIO implements IFileIO {
protected $filepath;
public function __construct($filename) {
if (!is_readable($filename) || !is_writable($filename)) {
throw new Exception("Data source ${filename} is invalid.");
}
$this->filepath = realpath($filename);
}
}
class JsonIO extends FileIO {
public function load($assoc = true) {
$file_content = file_get_contents($this->filepath);
return json_decode($file_content, $assoc) ?: [];
}
public function save($data) {
$json_content = json_encode($data, JSON_PRETTY_PRINT);
file_put_contents($this->filepath, $json_content);
}
}
class SerializeIO extends FileIO {
public function load() {
$file_content = file_get_contents($this->filepath);
return unserialize($file_content) ?: [];
}
public function save($data) {
$serialized_content = serialize($data);
file_put_contents($this->filepath, $serialized_content);
}
}
interface IStorage {
function add($record): string;
function findById(string $id);
function findAll(array $params = []);
function findOne(array $params = []);
function update(string $id, $record);
function delete(string $id);
function findMany(callable $condition);
function updateMany(callable $condition, callable $updater);
function deleteMany(callable $condition);
}
class Storage implements IStorage {
protected $contents;
protected $io;
public function __construct(IFileIO $io, $assoc = true) {
$this->io = $io;
$this->contents = (array)$this->io->load($assoc);
}
public function __destruct() {
$this->io->save($this->contents);
}
public function add($record): string {
$id = uniqid();
if (is_array($record)) {
$record['id'] = $id;
}
else if (is_object($record)) {
$record->id = $id;
}
$this->contents[$id] = $record;
return $id;
}
public function findById(string $id) {
return $this->contents[$id] ?? NULL;
}
public function findAll(array $params = []) {
return array_filter($this->contents, function ($item) use ($params) {
foreach ($params as $key => $value) {
if (((array)$item)[$key] !== $value) {
return FALSE;
}
}
return TRUE;
});
}
public function findOne(array $params = []) {
$found_items = $this->findAll($params);
$first_index = array_keys($found_items)[0] ?? NULL;
return $found_items[$first_index] ?? NULL;
}
public function update(string $id, $record) {
$this->contents[$id] = $record;
}
public function delete(string $id) {
unset($this->contents[$id]);
}
public function findMany(callable $condition) {
return array_filter($this->contents, $condition);
}
public function updateMany(callable $condition, callable $updater) {
array_walk($this->contents, function (&$item) use ($condition, $updater) {
if ($condition($item)) {
$updater($item);
}
});
}
public function deleteMany(callable $condition) {
$this->contents = array_filter($this->contents, function ($item) use ($condition) {
return !$condition($item);
});
}
}
member.php
DOCTYPE html>
html lang="en">
head>
meta charset="UTF-8">
meta http-equiv="X-UA-Compatible" content="IE=edge">
meta name="viewport" content="width=device-width, initial-scale=1.0">
title>Task 3title>
link rel="stylesheet" href="index.css">
head>
body>
h1>Task 3: Gift listh1>
a href="index.php">Back to main pagea>
h2>Ideas for SELECTED FAMILY MEMBERh2>
form action="" method="post">
fieldset>
legend>New idealegend>
Idea: input type="text" name="idea" required>
button name="function-add" type="submit">Add new ideabutton>
fieldset>
form>
details>
summary>
Idea 1 span>span>
summary>
form action="" method="post">
input type="hidden" name="idea-id" value="">
Comment: input type="text" name="comment" required>
button type="submit" name="add-comment">Add commentbutton> br>
form>
form action="" method="post">
input type="hidden" name="idea-id" value="">
button type="submit" name="complete">Completebutton>
button type="submit" name="hide">Hidebutton>
form>
ul>
li>Comment 1li>
li>Comment 2li>
ul>
details>
details>
summary>
Idea 2
summary>
form action="" method="post">
input type="hidden" name="idea-id" value="">
Comment: input type="text" name="comment" required>
button type="submit" name="add-comment">Add commentbutton> br>
form>
form action="" method="post">
input type="hidden" name="idea-id" value="">
button type="submit" name="complete">Completebutton>
button type="submit" name="hide">Hidebutton>
form>
ul>
li>Comment 1li>
li>Comment 2li>
li>Comment 3li>
ul>
details>
body>
html>
Christmas preparations include buying presents. In larger families, however, it can be difficult to keep track of what we will give to whom and in what condition it is (we ordered it, where to go for it, whether we have it or it was a bad idea, etc.). Let us create a PHP application that will help us manage this. We should be able to add family members, record ideas per family member, and add comments to the idea, as well as modify the status of the idea. The idea has two statuses: i.e. the idea is valid or it has been rejected; , i.e. we have some work with the idea, or we can finish dealing with it. The data must be stored in a file, the storage format is up to you. You may use the class shown in the lectures but it's not obligatory. If we store the data in JSON format, one possible storage method is to store the family members in one JSON file and the ideas in another JSON file, and the comments within the ideas. - a. (1 pt) With the help of the form on the page, we should be able to add a new family member! Note: the form does not need to be validated on server side in this task, we assume that it is filled in correctly! - b. (1 pt) List the stored family members on the page! Each family member should have a link that points to the page, passing the ID of the family member in the URL! - c. (1 pt) On the page, write the name of our selected family member in the header! - d. (1 pt) Use the "New idea" form on the page to add a new idea for the given family member! For an idea, we store the name of the idea, the activity of the idea I_ by default true), the state of the idea (ready. false by default), and the comments to it (empty array by default). The form does not need to be validated on the server side. - e. (1 pt) On the page, list the ideas belonging to the given family member and the comments within the ideas! - f. (1 pt) Make it possible to add a new comment to the idea using the form within the idea! The form does not need to be validated on the server side! You can store the ID of the idea, for example, in a hidden field in the form. - g. (1 pt) By clicking on the "Complete" or "Hide" button within the idea, change the state of the given idea to true or the state to false, respectively! Show a checkmark next to the idea if it is ready, and inactive ideas should not be listed! - h. (1 pt) On the page, next to the family members, display how many of the active ideas are ready! (in the format of

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions