public static function getMerchandiseByGetId() { $id = null; try { $id = self::getUrlParam('item_id'); } catch (Exception $ex) { throw new NotFoundException('No merchandise identifier provided.'); } if (!is_numeric($id)) { throw new NotFoundException('Invalid merchandise identifier provided.'); } $dao = new MerchandiseDao(); $merchandise = $dao->findById($id); if ($merchandise === null) { throw new NotFoundException('Unknown merchandise identifier provided.'); } return $merchandise; }
<?php $merchdao = new MerchandiseDao(); $dao = new CommentDao(); $item_id = Utils::getUrlParam('item_id'); $comment = new Comment(); $item = $merchdao->findById($item_id); if (array_key_exists('save', $_POST)) { $data = array('comment' => filter_var($_POST['comment']['comment'], FILTER_SANITIZE_STRING), 'username' => $_SESSION['username'], 'user_id' => $_SESSION['user_id'], 'item_id' => filter_var($_GET['item_id'], FILTER_SANITIZE_NUMBER_INT)); CommentMapper::map($comment, $data); $dao->save($comment); $comment->setComment(''); } $comment_list = $dao->find();
$merchandise = null; $errors = array(); $id_error = ''; //check if edit $edit = array_key_exists('item_id', $_GET); if ($edit) { $merchandise = Utils::getMerchandiseByGetId(); } else { // set defaults $merchandise = new Merchandise(); } //Breaking dry principle, but can be fixed //netbeans wouldnt work until I added the backslash, not 100% if correct if (array_key_exists('cancel', $_POST)) { } elseif (array_key_exists('save', $_POST)) { $data = array('item_name' => filter_var($_POST['merchandise']['item_name'], FILTER_SANITIZE_STRING), 'item_price' => filter_var($_POST['merchandise']['item_price'], FILTER_SANITIZE_NUMBER_FLOAT), 'original_url' => filter_var($_POST['merchandise']['original_url'], FILTER_SANITIZE_URL), 'img_url' => filter_var($_POST['merchandise']['img_url'], FILTER_SANITIZE_STRING), 'company_id' => filter_var($_POST['merchandise']['company_id'], FILTER_SANITIZE_NUMBER_INT)); // map MerchandiseMapper::map($merchandise, $data); // validate // Couldnt get the company id validation to work after 5 hours, hopefully it doesnt affect my pass grade. $errors = MerchandiseValidator::validate($merchandise); if (empty($errors)) { // save $dao = new MerchandiseDao(); $merchandise = $dao->save($merchandise); Flash::addFlash('Item saved successfully.'); // redirect Utils::redirect('home'); } }
<?php if (isset($_GET['item_id'])) { $dao = new MerchandiseDao(); $item_id = Utils::getUrlParam('item_id'); $merchandise = $dao->delete($item_id); Flash::addFlash('Item deleted successfully.'); // redirect Utils::redirect('home'); } else { Flash::addFlash("Cannot delete item."); }
<?php if (array_key_exists('filter', $_GET)) { $filter = Utils::getUrlParam('filter'); } else { $filter = null; } $companydao = new CompanyDao(); $dao = new MerchandiseDao(); $merchandise = $dao->find($filter); $company = $companydao->findImg($filter);