/** * @return Pizza */ public function buildPizza() { $pizza = new Pizza($this->getName()); $pizza->addIngredient(new sauce()); $pizza->addIngredient(new cheese()); return $pizza; }
/** * @param $row * @return Order */ private function restoreOrder($row) { $pizza = new Pizza(); $pizza->setIngredient($row['pizza']['ingredient']); $pizza->setSauce($row['pizza']['sauce']); $order = new Order(); $order->setPizzaType($row['type']); $order->setProcessed($row['processed']); $order->setPizza($pizza); return $order; }
/** * Imposta la dimensione delle pizze che fanno parte dell'articolo * @param string $size dimensione * @return boolean true se il valore e' ammissibile ed e' stato aggiornato * correttamente, false altrimenti */ private function setSize($size) { if (strtolower($size) == self::Normale || strtolower($size) == self::Ridotta || strtolower($size) == self::Grande) { $this->size = strtolower($size); switch (strtolower($size)) { case self::Ridotta: $this->prezzo_pizza = $this->pizza->getPrezzo() - self::SizeCost; break; case self::Grande: $this->prezzo_pizza = $this->pizza->getPrezzo() + self::SizeCost; break; default: $this->prezzo_pizza = $this->pizza->getPrezzo(); } return true; } return false; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { // $pizza = Pizza::find($id); $pizza->pizza_name = Input::get('pizza_name'); $base = Input::get('base'); $pizza->ingredients()->attach($base); $cheese = Input::get('cheese'); $pizza->ingredients()->attach($cheese); $meats = Input::get('meats'); if (sizeof($meats) != 0) { foreach ($meats as $meat) { $pizza->ingredients()->attach($meat); } } $pizza->save(); }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { $model = $this->loadModel($id); $model->excluida = 1; $conditions = 'tamanho_tipo_massa_id = ' . $model->id; $pizza = Pizza::model()->find($conditions); if (empty($pizza)) { $model->delete(); } else { $model->save(); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index')); } }
public function ingredientes() { echo "Adicionar calabresa\n"; parent::ingredientes(); }
//Crear la carpeta de avatares si aún no está creada. if (!is_dir($dir_subida)) { mkdir($dir_subida, 0777); } $nombre_nuevo_avatar = basename($_FILES['imagen']['name']); $url_nuevo_avatar = $dir_subida . $nombre_nuevo_avatar; //Comprobar que la imagen se ha subido correctamente y se ha movido a la carpeta de avatares if (@move_uploaded_file($_FILES['imagen']['tmp_name'], $url_nuevo_avatar)) { //Cambiarle los permisos a la imagen para después poder borrarla chmod($url_nuevo_avatar, 0777); } else { //Error al mover el archivo, probablemente por los permisos de la carpeta de destino $errorPermisosImagen = true; } } else { //El formato del archivo es incorrecto, avisar $errorTipoImagen = true; } } //Comprobar los errores y los campos necesarios if (!$errorTipoImagen && !$errorPermisosImagen && !empty($_FILES['imagen']['name']) && !empty($_POST['nombre']) && !empty($_POST['descripcion']) && !empty($_POST['ingredientes'])) { //Crear una instancia de Pizza y meter los datos de la pizza que se esta modificando $pizza = new Pizza(); $pizza->setImagen(basename($_FILES['imagen']['name'])); $pizza->setNombre($_POST['nombre']); $pizza->setDescripcion($_POST['descripcion']); $pizza->setIdsIngredientes($_POST['ingredientes']); //Llamamos a los funcion insertarMasa del modelo. insertarPizza($pizza); } }
/** * Confronta due oggetti di tipo Pizza * @param Pizza $pizza * @return boolean true se le due pizze (param. implicito $this * e param. esplicito $pizza) coincidono, false altrimenti */ public function equals(Pizza $pizza) { if (!isset($pizza)) { return false; } return $this->id == $pizza->getId() && $this->nome == $pizza->getNome(); }
<?php /** * Decorator pattern example. * * Each class is nice and independent from the others, so you don't have to ever change it again, * (except for perhaps the price). Once it is up and running, you can just leave it alone! */ include_once "BusinessInterface.php"; include_once "Pizza.php"; include_once "AddOlives.php"; include_once "AddGreenPeppers.php"; if (isset($_POST['pizza']) && $_POST['pizza']) { $cost = new Pizza(); echo "<br>" . "The pizza costs: " . $cost->buy() . "<br>"; if (isset($_POST['olives']) && $_POST['olives']) { $cost = new AddOlives($cost); echo "Subtotal with olives added is: " . $cost->buy() . "<br>"; } if (isset($_POST['green_peppers']) && $_POST['green_peppers']) { $cost = new AddGreenPeppers($cost); echo "Subtotal with green peppers added is: " . $cost->buy() . "<br>"; } echo "Grand Total: " . $cost->buy() . "<br>"; } else { echo "You did not order a pizza."; }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { Pizza::create($request->all()); Session::flash('message', 'Adicionado Correctamente'); return Redirect::to('/pizza'); }
public function ingredientes() { echo "Adicionar bacon\n"; parent::ingredientes(); }
//~ ); //~ } //~ } //~ $pizzaSalami = new PizzaSalami (); //~ var_dump ( $pizzaSalami ); interface CrustInterface { } interface ToppingInterface { } class CrustWheatFlour implements CrustInterface { } class ToppingSalami implements ToppingInterface { } class Pizza { public function __construct(CrustInterface $crust) { $this->crust = $crust; } public function addTopping(ToppingInterface $topping) { $this->toppings[] = $topping; } } $pizzaSalami = new Pizza(new CrustWheatFlour()); $pizzaSalami->addTopping(new ToppingSalami()); echo 0;
session_start(); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <?php include_once 'Pizza.php'; if (!isset($_SESSION[margarita])) { $_SESSION[margarita] = serialize(new Pizza('Margarita', 'mediana', 'pedida')); $_SESSION[cuatroQuesos] = serialize(new Pizza('Funghi', 'familiar', 'pedida')); $_SESSION[funghi] = serialize(new Pizza('Cuatro Quesos', 'mediana', 'pedida')); } $margarita = unserialize($_SESSION[margarita]); $cuatroQuesos = unserialize($_SESSION[cuatroQuesos]); $funghi = unserialize($_SESSION[funghi]); $margarita->sirve(); echo $margarita; echo $cuatroQuesos; echo $funghi; echo Pizza::getNumPedidas(); echo Pizza::getNumServidas(); ?> </body> </html>
$nuevoPedido->setIdMasa($_POST['masa']); $nuevoPedido->setNombreMasa(getNombreMasa($_POST['masa'])); $nuevoPedido->setIdsIngredientes($idIngredientes); $nuevoPedido->setUnidades($_POST['cantidad']); $nuevoPedido->setPrecioTotal((getPrecioMasa($_POST['masa']) + $nuevoPedido->getNumIng()) * $_POST['cantidad']); /** * Añadir el pedido al carrito, serializando el objeto * * Sacado de StackOverflow; * http://stackoverflow.com/a/1442271/710274 */ $_SESSION['user']['pedidos'][$idUnicoPedido] = serialize($nuevoPedido); } else { if (isset($_POST['cambiarStock']) && isset($_POST['idPizza'])) { //Poner o quitar la pizza del stock cambiarStockPizza($_POST['idPizza'], $_POST['stock']); } $result = getPizzas(); //Array de todas las pizzas de la BD $arrayPizzas = array(); while ($row = $result->fetch_assoc()) { $pizza = new Pizza(); $pizza->setIdPizza($row['id_pizza']); $pizza->setNombre($row['nombrePizza']); $pizza->setDescripcion($row['descripcion']); $pizza->setIdsIngredientes($row['ingredientes']); $pizza->setImagen($row['imagen']); $pizza->setStock($row['stock']); $arrayPizzas[] = $pizza; } }
public function afterSave() { $retorno = parent::afterSave(); if (!$this->isNewRecord) { return $retorno; } if (isset($this->_produtos)) { foreach ($this->_produtos as $produto) { $modelProdutoPedido = new ProdutoPedido(); $modelProdutoPedido->attributes = $produto; $modelProdutoPedido->pedido_id = $this->id; $modelProdutoPedido->save(); } } if (isset($this->_pizzas)) { foreach ($this->_pizzas as $pizza) { $modelPizza = new Pizza(); $modelPizza->attributes = $pizza; $modelPizza->pedido_id = $this->id; $modelPizza->_sabores = $pizza['sabores']; $modelPizza->_adicionais = isset($pizza['adicionais']) ? $pizza['adicionais'] : null; $modelPizza->save(); } } if (isset($this->_combinados)) { foreach ($this->_combinados as $combinado) { $modelCombinadoPedido = new CombinadoPedido(); $modelCombinadoPedido->preco = $combinado['preco']; $modelCombinadoPedido->combinado_id = $combinado['combinado_id']; $modelCombinadoPedido->pedido_id = $this->id; $modelCombinadoPedido->_item_combinado = $combinado['itens_combinado']; $modelCombinadoPedido->save(); } } $retorno = false; return $retorno; }
<?php require_once "modelo/gestionPizzas.php"; require_once "modelo/gestionIngredientes.php"; require_once "modelo/clases/Pizza.php"; //Si no se viene desde la página de gestión de usuarios, o no se está enviando el formulario de modificacion, redireccionar a gestión de usuarios if (!isset($_POST['editar']) && !isset($_POST['enviar'])) { header('Location: gestion-pizzas.php'); } $errorTipoImagen = false; $errorPermisosImagen = false; if (isset($_POST['editar']) || isset($_POST['enviar'])) { $result = getPizza($_POST['idPizza']); //Crear instancias de Pizza a modificar a partir de los datos de la BD $datosPizza = $result->fetch_assoc(); $pizza = new Pizza(); $pizza->setIdPizza($datosPizza['id_pizza']); $pizza->setNombre($datosPizza['nombrePizza']); $pizza->setDescripcion($datosPizza['descripcion']); $pizza->setIdsIngredientes($datosPizza['ingredientes']); $pizza->setImagen($datosPizza['imagen']); $pizza->setStock($datosPizza['stock']); } if (isset($_POST['enviar'])) { //Comprobar si se quiere cambiar la imagen de la pizza if (!empty($_FILES['imagen']['name'])) { /** * El siguiente código comprueba el MIME TYPE del archivo para comprobar que es una imagen * * Código modificado a partir de un snippet sacado de PHP.NET; *
public function makePizza() { $pizza = new Pizza(); $pizza->setIngredient(PIZZA_MUSHROOM); return $pizza; }
$this->width = $width; $this->height = $height; $this->weight = $weight; } function volume() { $volume = $this->length * $this->width * $this->height; return $volume; } function costToShip() { $cost = $this->volume() + $this->weight / 2; return $cost; } } $pizza1 = new Pizza($_GET["length"], $_GET["width"], $_GET["height"], $_GET["weight"]); //collect user input here instead of hardcoding in numbers if (empty($_GET["length"] && $_GET["width"] && $_GET["height"] && $_GET["weight"])) { echo "Your pizza is imaginary. Please enter real dimensions and/or weight"; exit; } ?> <!DOCTYPE html> <html> <head> <title>Your Car Dealership's Homepage</title> </head> <body> <h1>Here is the cost of shipping your pizza</h1> <ul>
<html> <head> <title>Hello</title> </head> <body> <?php interface Food { function buy(); function pay($amount); } class Pizza implements Food { function buy() { echo 'buying food...<br/>'; } function pay($amount) { echo 'Paying $' . $amount . '<br/>'; } } $p1 = new Pizza(); $p1->buy(); ?> </body> </html>
/** * Crea una pizza da una riga del db * @param type $row * @param boolean $flag true con immagine, altrimenti senza * @return \Pizza */ public function creaPizzaDaArray($row, $flag) { $pizza = new Pizza(); $pizza->setId($row['id']); $pizza->setNome($row['nome']); $pizza->setIngredientiExtra($row['ingredienti_extra']); $pizza->setPrezzo($row['prezzo']); if ($flag) { $pizza->setUrlImage($row['image_url']); } return $pizza; }