public function create(Category $category, $name, $price, $stock, $image, $description) { $errors = array(); $item = new Item($this->db); try { $item->setCategory($category); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $item->setName($name); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $item->setPrice($price); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $item->setStock($stock); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $item->setImage($image); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $item->setDescription($description); } catch (Exception $e) { $errors[] = $e->getMessage(); } if (count($errors) == 0) { $name = $this->db->quote($item->getName()); $price = $this->db->quote($item->getPrice()); $stock = $this->db->quote($item->getStock()); $image = $this->db->quote($item->getImage()); $description = $this->db->quote($item->getDescription()); $idCategory = $item->getCategory()->getId(); $query = ' INSERT INTO item (id_category, name, price, stock, image, description) VALUES(' . $idCategory . ',' . $name . ',' . $price . ',' . $stock . ',' . $image . ',' . $description . ')'; $res = $this->db->exec($query); if ($res) { $id = $this->db->lastInsertId(); if ($id) { return $this->readByID($id); } else { throw new Exception('Internal server Error'); } } } }
public function testSetGetAllergyCategory() { // Arrange $item = new Item(); $item->setCategory(1); $expectedResult = 1; // Act $result = $item->getCategory(); // Assert $this->assertEquals($result, $expectedResult); }
function autoMail() { global $database; //$itemsArr = array(); $today = date("Y-m-d"); $this->query = "select * from items where BidEndOn ='{$today}' AND highest_bid!=0"; $result = mysql_query($this->query); while ($row = mysql_fetch_array($result)) { $item = new Item(); $item->setItemId($row["ItemID"]); $item->setTitle($row["Title"]); $item->setMinPrice($row["min_price"]); $item->setCategory($row["Category"]); $item->setOwnerId($row["OwnerID"]); $ad = date("Y-m-d H:i:s", strtotime($row['addedOn'])); $item->setHighestBid($row["highest_bid"]); $item->setAddedOn($ad); $item->setBiddingEndOn($row["BidEndOn"]); $item->setDesc($row["Description"]); $item->setStatus($row["Status"]); $this->query = "SELECT PicDate,PicPath FROM itempics WHERE OwnId = " . $item->ownerId . " AND PicDate = '" . $ad . "'"; $res = mysql_query($this->query); $r = mysql_fetch_array($res); $item->setPicPath($r['PicPath']); $this->query = "select email from user where UserID={$item->ownerId}"; $res = mysql_query($this->query); $r = mysql_fetch_row($res); $OwnerEmail = $r[0]; $this->query = "select bids.BidderID from items INNER JOIN bids ON items.highest_bid=bids.amount where items.ItemID ={$item->itemId}"; $res = mysql_query($this->query); $r = mysql_fetch_row($res); $bidderId = $r[0]; $this->query = "select email from user where UserID={$bidderId}"; $res = mysql_query($this->query); $r = mysql_fetch_row($res); $WinnerEmail = $r[0]; echo "\nOwner email:" . $OwnerEmail . "\n"; echo "\nWinner email:" . $WinnerEmail . "\n"; $this->query = "update account set balance=balance+{$item->highestBid} where UserID={$item->ownerId}"; mysql_query($this->query); $this->query = "delete from bids where ItemID={$item->itemId}"; mysql_query($this->query); $this->query = "update items set OwnerId ={$bidderId}, status='sold' where ItemID={$item->itemId}"; mysql_query($this->query); $this->query = "insert into WonItems (winnerId,ownerId) values ({$bidderId}, {$item->ownerId} )"; mailForOwner($OwnerEmail, $item); mailForWinner($WinnerEmail, $item); } }
function getItem($id) { global $database; $item = new Item(); $this->query = "select * from items where ItemID='{$id}'"; $result = mysql_query($this->query); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_row($result); $item->setItemId($row[0]); $item->setTitle($row[1]); $item->setMinPrice($row[2]); $item->setHighestBid($row[3]); $item->setCategory($row[4]); $item->setOwnerId($row[5]); $item->setAddedOn($row[6]); $item->setBiddingEndOn($row[7]); $item->setDesc($row[8]); $item->setStatus($row[9]); } return $item; }
function createAction(Request $request, Application $app) { if (null === ($user = $app['session']->get('user'))) { return $app->redirect('/login'); } $newItem = new Item(); $newItem->setName($request->get('name')); $newItem->setDescription($request->get('description')); $newItem->setPrice($request->get('price')); $newItem->setCalories($request->get('calories')); $newItem->setAllergyInformation($request->get('allergyInformation')); $em = $app['orm.em']; $categoryRepository = $em->getRepository('Category'); $Category = $categoryRepository->find($request->get('category')); $newItem->setCategory($Category); $file = $request->files->get('photo'); $newItem->setPhoto($file->getClientOriginalName()); $file = $request->files->get('photo'); $file->move(__DIR__ . '/../public/img', $file->getClientOriginalName()); $em->persist($newItem); $em->flush(); return $app->redirect('/itemAdmin'); }
function autoMail() { global $database; //$itemsArr = array(); $today = date("Y-m-d"); $this->query = "select * from items where BidEndOn ='{$today}' AND highest_bid!=0 AND status != 'sold'"; $result = mysql_query($this->query); while ($row = mysql_fetch_array($result)) { $item = new Item(); $item->setItemId($row["ItemID"]); $item->setTitle($row["Title"]); $item->setMinPrice($row["min_price"]); $item->setCategory($row["Category"]); $item->setOwnerId($row["OwnerID"]); $ad = date("Y-m-d H:i:s", strtotime($row['addedOn'])); $item->setHighestBid($row["highest_bid"]); $item->setAddedOn($ad); $item->setBiddingEndOn($row["BidEndOn"]); $item->setDesc($row["Description"]); $item->setStatus($row["Status"]); print_r($item); $this->query = "SELECT PicDate,PicPath FROM itempics WHERE OwnId = " . $item->ownerId . " AND PicDate = '" . $ad . "'"; $res = mysql_query($this->query); $r = mysql_fetch_array($res); $item->setPicPath($r['PicPath']); $this->query = "select email from user where UserID={$item->ownerId}"; $res = mysql_query($this->query); $r = mysql_fetch_row($res); $OwnerEmail = $r[0]; $ul = new UserLogic(); $ownuser = $ul->getUser($item->ownerId); $this->query = "select bids.BidderID from items INNER JOIN bids ON items.highest_bid=bids.amount where bids.ItemID ={$item->itemId}"; $res = mysql_query($this->query); $r = mysql_fetch_row($res); $bidderId = $r[0]; echo $bidderId; $winuser = $ul->getUser($r[0]); $this->query = "select email from user where UserID={$bidderId}"; $res = mysql_query($this->query); $r = mysql_fetch_row($res); $WinnerEmail = $r[0]; echo "\nOwner email:" . $OwnerEmail . "\n"; echo "\nWinner email:" . $WinnerEmail . "\n"; require "fbmain.php"; if ($facebook) { if ($ownuser->fb_id) { try { $wallpostpage = $facebook->api('/' . $ownuser->fb_id . '/feed', 'post', array('message' => 'Your item ' . $item->title . '. has been sold at price ' . $item->highestBid . '$. ', 'picture' => 'http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1324.snc4/161996_166764056682774_6216247_q.jpg ', 'link' => 'http://www.facebook.com/apps/application.php?id=166764056682774', 'name' => 'eVeiling.com', 'cb' => '')); } catch (FacebookApiException $e) { print_r($o); } } if ($winuser->fb_id) { try { $wallpostpage = $facebook->api('/' . $winuser->fb_id . '/feed', 'post', array('message' => 'You have won the auction of ' . $item->title . ' at ' . $item->highestBid . '$.', 'picture' => 'http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1324.snc4/161996_166764056682774_6216247_q.jpg ', 'link' => 'http://www.facebook.com/apps/application.php?id=166764056682774', 'name' => 'eVeiling.com', 'cb' => '')); } catch (FacebookApiException $e) { print_r($o); } } } $this->query = "update account set balance=balance+{$item->highestBid} where UserID={$item->ownerId}"; mysql_query($this->query); $this->query = "delete from bids where ItemID={$item->itemId}"; mysql_query($this->query); $this->query = "update items set OwnerId ={$bidderId}, status='sold' where ItemID={$item->itemId}"; mysql_query($this->query); $this->query = "insert into WonItems (winnerId,ownerId,ItemId) values ({$bidderId}, {$item->ownerId},{$item->itemId} )"; mysql_query($this->query); mailForOwner($OwnerEmail, $item); mailForWinner($WinnerEmail, $item); } }
FROM post LEFT JOIN category ON category_id = post_category_id WHERE post_valid=1 LIMIT 10'); while ($row = mysql_fetch_object($request)) { // Creating a new feed item $rssItem = new Item(); $rssItem->setTitle($row->post_title); $rssItem->setDescription($row->post_description); $rssItem->setLink('http://www.mywebsite.com/blog/post.php?id=' . $row->post_id); $rssItem->setGuid('http://www.mywebsite.com/blog/post.php?id=' . $row->post_id, true); $rssItem->setComments('http://www.mywebsite.com/blog/post.php?id=' . $row->post_id . '#comments'); $rssItem->setAuthor($row->post_author_email, $row->post_author_name); $rssItem->setPubDate($row->post_date); $rssItem->setSource($row->post_source_uri, $row->post_source_name); $rssItem->setEnclosure('http://www.mywebsite.com/blog/images/nopicture.jpg', 2800, 'image/jpg'); $rssItem->setCategory('http://www.mywebsite.com/blog/category.php.idCat=' . $row->category_id, $row->category_name); // Add the item to the feed $rssFeed->appendItem($rssItem); } // Save the feed $rssFeed->save(); // SQL connection closing mysql_close(); // Send headers to the browser header('Content-Type: text/xml; charset=utf-8'); // Display the feed $rssFeed->display(); } catch (RSSFeedException $e) { echo $e->getErrorMessage(); }
<?php session_start(); require_once 'Logic/ItemLogic.php'; $title = $_POST['title']; $minPrice = $_POST['minPrice']; $category = $_POST['category']; $Enddate = $_POST['inputDate']; $desc = $_POST['desc']; $item = new Item(); $item->setTitle($title); $item->setMinPrice($minPrice); $item->setCategory($category); $item->setBiddingEndOn($Enddate); $item->setDesc($desc); $item->setOwnerId($_SESSION['user']); //($_SESSION['user']); $item->setStatus("available"); $itemLogic = new ItemLogic(); $itemLogic->insertItem($item); ?> <script type="text/javascript"> </script> <div class="c"> <form id="abc" method="post"> <div id="file-uploader-demo1"> <noscript> <p>Please enable JavaScript to use file uploader.</p>
function getPostedItems($id) { global $database; $itemsArr = array(); $this->query = "select * from items where ownerid={$id}"; $result = mysql_query($this->query); if ($result) { while ($row = mysql_fetch_array($result)) { $item = new Item(); $item->setItemId($row["ItemID"]); $item->setTitle($row["Title"]); $item->setMinPrice($row["min_price"]); $item->setCategory($row["Category"]); $item->setOwnerId($row["OwnerID"]); $ad = date("Y-m-d H:i:s", strtotime($row['addedOn'])); $item->setHighestBid($row["highest_bid"]); $item->setAddedOn($ad); $item->setBiddingEndOn($row["BidEndOn"]); $item->setDesc($row["Description"]); $item->setStatus($row["Status"]); $this->query = "SELECT PicDate,PicPath FROM itempics WHERE OwnId = " . $item->ownerId . " AND PicDate = '" . $ad . "'"; $res = mysql_query($this->query); $r = mysql_fetch_array($res); $item->setPicPath($r['PicPath']); array_push($itemsArr, $item); } return $itemsArr; } }