コード例 #1
0
ファイル: merchandiseDao.php プロジェクト: Wooddu/MMNZ
 public function find($filter = null)
 {
     $result = array();
     $suffix = '';
     if ($filter) {
         $suffix = ' WHERE company_id = ' . $filter;
     }
     $sql = 'SELECT item_id, item_name, item_price, img_url, company_id FROM merchandise' . $suffix;
     foreach ($this->query($sql) as $row) {
         $merchandise = new Merchandise();
         MerchandiseMapper::map($merchandise, $row);
         $result[$merchandise->getItem_id()] = $merchandise;
     }
     return $result;
 }
コード例 #2
0
ファイル: add-edit-script.php プロジェクト: Wooddu/MMNZ
$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');
    }
}