Beispiel #1
0
 public function createAction()
 {
     F::$app->getUser()->accessDenied();
     if (F::$app->getRequest()->getIsPost()) {
         $item = new Item();
         $item->title = $_POST['title'];
         $item->description = $_POST['description'];
         $item->date_created = time();
         if ($item->save()) {
             F::$app->getResponse()->redirect(['items/index']);
         } else {
             return "Item was not added";
         }
     }
     return $this->render('create');
 }
 public function getItem($itemid)
 {
     $item = Item::where('id', $itemid)->first();
     if ($item != null) {
         $array = array('success' => true, 'item' => $item);
         return json_encode($array);
     } else {
         $array = array('success' => false, 'message' => 'Item not found');
         return json_encode($array);
     }
 }
     $item = new Item();
     $event = new Event();
     //determine currently logged in user//
     $userid = $resourceServer->getAccessToken()->getSession()->getOwnerId();
     //verify the logged in user owns the event that the item will be added to//
     if ($event->verifyHost($eventid, $userid)) {
         $json = $item->getItems($eventid);
         echo $json;
     } else {
         $array = array('success' => false, 'message' => 'Failed to find event');
         echo json_encode($array);
     }
 });
 //get specific item//
 $app->get('/:itemid/', $authorize(), function ($itemid) use($app, $resourceServer) {
     $item = new Item();
     $json = $item->getItem($itemid);
     echo $json;
 });
 //determine prize winner//
 $app->post('/winner/', $authorize(), function () use($app, $resourceServer) {
     $winner = new Winner();
     $item = new Item();
     $itemid = $app->request->post('itemid');
     $item = $item->getItem($itemid);
     $item = json_decode($item);
     //check that item exists//
     if ($item->success) {
         $ticket = new Ticket();
         $item = $item->item;
         //get all the tickets for the event and perform messy json conversions -_- //