/** * Moving an Item from one spot to the other in a Bag */ function game_change($from_bag_id = null, $from_bag_index = null, $to_bag_id = null, $to_bag_index = null) { $this->render(false); App::import('Model', 'Inventory'); $Inventory = new Inventory(); $Inventory->unbindModelAll(); $fromInventory = $Inventory->find('first', array('conditions' => array('Inventory.character_id' => $this->characterInfo['id'], 'Inventory.bag_id' => $from_bag_id, 'Inventory.index' => $from_bag_index))); if (!empty($fromInventory)) { // KLijken of het vakje leeg is waar we heen gaan $toInventory = $Inventory->find('first', array('conditions' => array('Inventory.character_id' => $this->characterInfo['id'], 'Inventory.bag_id' => $to_bag_id, 'Inventory.index' => $to_bag_index))); if (!empty($toInventory)) { // Niks aan de hand, wisselen // to => from $oldIds = $Inventory->find('list', array('conditions' => array('Inventory.character_id' => $this->characterInfo['id'], 'Inventory.bag_id' => $from_bag_id, 'Inventory.index' => $from_bag_index))); $Inventory->updateAll(array('Inventory.bag_id' => $fromInventory['Inventory']['bag_id'], 'Inventory.index' => $fromInventory['Inventory']['index']), array('Inventory.bag_id' => $toInventory['Inventory']['bag_id'], 'Inventory.index' => $toInventory['Inventory']['index'])); // from => to $Inventory->updateAll(array('Inventory.bag_id' => $toInventory['Inventory']['bag_id'], 'Inventory.index' => $toInventory['Inventory']['index']), array('Inventory.id' => $oldIds)); } else { // kijken of er in de nieuwe bag slot wel ruimte is $this->Bag->recursive = 2; $toBag = $this->Bag->find('first', array('conditions' => array('Bag.id' => $to_bag_id, 'Bag.character_id' => $this->characterInfo['id']))); if (!empty($toBag)) { // Kijken of de index lager is dan het aantal vrije slots if ($toBag['Item']['StatNamed']['slots'] >= $to_bag_index) { // Mag naar de lege plek $Inventory->updateAll(array('Inventory.bag_id' => $to_bag_id, 'Inventory.index' => $to_bag_index), array('Inventory.bag_id' => $fromInventory['Inventory']['bag_id'], 'Inventory.index' => $fromInventory['Inventory']['index'])); } } } } $this->redirect('/game/bags/view/' . $to_bag_id); exit; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $collection = Collection::find($id); $inventories = $collection->inventory; $inventory = Inventory::find($id); $this->layout->content = View::make('collections.edit')->with('collection', $collection)->with('inventories', $inventories)->with('inventory', $inventory); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $del = Inventory::find($id)->delete(); if ($del) { echo "Your Item Deleted"; } else { echo "Not Found or Already Deleted"; } }
function test_find() { $item = "POGs"; $item2 = "Pokemon Cards"; $test_item = new Inventory($item); $test_item->save(); $test_item2 = new Inventory($item2); $test_item2->save(); $search_item = $test_item->getItem(); $result = Inventory::find($search_item); $this->assertEquals($test_item, $result); }
function test_find() { $description = "Blue candy"; $description2 = "Light blue candy"; $test_Inventory = new Inventory($description); $test_Inventory->save(); $test_Inventory2 = new Inventory($description2); //Act $id = $test_Inventory->getId(); $result = Inventory::find($id); //Assert $this->assertEquals($test_Inventory, $result); }
public function store($id) { $validator = Validator::make(Input::all(), Comment::$rules); $comment = Inventory::find($id); if ($validator->passes()) { $comment = new Comment(); $comment->content = Input::get('comment'); $comment->user_id = Auth::user()->id; $comment->img_id = $id; $comment->save(); return Redirect::to('/inventory/' . $id); } else { return Redirect::to('inventory')->with('message', 'The following errors occurred')->withErrors($validator)->withInput(); } }
function test_find() { //Arrange $item = "Antique Toothpick Holders"; $item2 = "Ornamental Mouse Traps"; $test_Inventory = new Inventory($item); $test_Inventory->save(); $test_Inventory2 = new Inventory($item2); $test_Inventory2->save(); //Act $id = $test_Inventory->getId(); $result = Inventory::find($id); //Assert $this->assertEquals($test_Inventory, $result); }
/** * Updates a Quest for a Character. If the Quest is completed and turned in * the Character may receive some Quest rewards. * * @param int $quest The ID of the quest * @param int $character_id The ID of the Character * @param boolean $turnIn Whenever this quest is turning in */ function update($quest_id = null, $character_id = null, $turnIn = false) { App::import('Model', 'CharactersQuest'); $CharactersQuest = new CharactersQuest(); $conditions = array(); $conditions['CharactersQuest.completed !='] = 'finished'; if (isset($quest_id)) { $conditions['CharactersQuest.quest_id'] = $quest_id; } if (isset($character_id)) { $conditions['CharactersQuest.character_id'] = $character_id; } $quests = $CharactersQuest->find('all', array('conditions' => array($conditions))); if (!empty($quests)) { // Inventory, Kill maybe needed App::import('Model', 'Inventory'); $Inventory = new Inventory(); App::import('Model', 'Kill'); $Kill = new Kill(); $charactersQuestsData = array(); $i = 0; foreach ($quests as $quest) { $charactersQuestsData[$i]['id'] = $quest['CharactersQuest']['id']; // Get the needed things (items, object, whatever) here $itemsNeeded = $this->ItemsQuest->find('list', array('conditions' => array('ItemsQuest.quest_id' => $quest['CharactersQuest']['quest_id'], 'ItemsQuest.type' => 'needed'), 'fields' => array('ItemsQuest.item_id', 'ItemsQuest.amount'))); $mobsNeeded = $this->MobsQuest->find('list', array('conditions' => array('MobsQuest.quest_id' => $quest['CharactersQuest']['quest_id']), 'fields' => array('MobsQuest.mob_id', 'MobsQuest.amount'))); $itemsRewards = $this->ItemsQuest->find('list', array('conditions' => array('ItemsQuest.quest_id' => $quest['CharactersQuest']['quest_id'], 'ItemsQuest.type' => 'reward'), 'fields' => array('ItemsQuest.item_id', 'ItemsQuest.amount'))); $statsRewards = $this->QuestsStat->find('list', array('conditions' => array('QuestsStat.quest_id' => $quest['CharactersQuest']['quest_id']), 'fields' => array('QuestsStat.stat_id', 'QuestsStat.amount'))); $completed = ''; if (empty($itemsNeeded) && empty($mobsNeeded)) { // Geen items nodig.. Omdat er op het moment niks anders is om te controleren updaten we deze quest... if ($turnIn == true && isset($character_id) && isset($quest_id)) { $charactersQuestsData[$i]['completed'] = 'finished'; } else { $charactersQuestsData[$i]['completed'] = 'yes'; } } else { $completed = 'yes'; // Default it's completed. $itemList = array(); $mobList = array(); foreach ($itemsNeeded as $item_id => $amount) { $itemList[] = $item_id; } foreach ($mobsNeeded as $mob_id => $amount) { $mobList[] = $mob_id; } // Er zijn items nodig voor deze quest.. Kijken of deze al gehaald zijn... // ItemsNeeded: item_id => aantal_needed $characterInventories = $Inventory->find('all', array('conditions' => array('Inventory.character_id' => $quest['CharactersQuest']['character_id'], 'Inventory.item_id' => $itemList), 'fields' => array('Inventory.item_id', 'COUNT(Inventory.item_id) as amount'), 'group' => array('Inventory.item_id'))); // Er zijn mobs nodig voor deze quest. Kijken of ze gekilled zijn NADAT de quest is geaccepteerd... $characterKills = $Kill->find('all', array('conditions' => array('Kill.character_id' => $quest['CharactersQuest']['character_id'], 'Kill.mob_id' => $mobList, 'Kill.type' => 'mob', 'Kill.created >=' => $quest['CharactersQuest']['created']), 'fields' => array('Kill.mob_id', 'COUNT(Kill.target_id) as amount'), 'group' => array('Kill.target_id'))); // We hebben een lijst met items wat nodig is.. // En dit wordt een lijst met wat we hebben... $itemsHave = array(); foreach ($characterInventories as $characterInventory) { $itemsHave[$characterInventory['Inventory']['item_id']] = $characterInventory[0]['amount']; } // Opslaan yes/no of de quest compleet is... foreach ($itemsNeeded as $item_id => $amount) { if (!isset($itemsHave[$item_id]) || isset($itemsHave[$item_id]) && $itemsHave[$item_id] < $itemsNeeded[$item_id]) { $completed = 'no'; } } // We hebben nu een lijst met mobs die nodig zijn, en een lijst met kills $mobsHave = array(); foreach ($characterKills as $characterKill) { $mobsHave[$characterKill['Kill']['mob_id']] = $characterKill[0]['amount']; } // Opslaan yes/no of de quest compleet is... foreach ($mobsNeeded as $mob_id => $amount) { if (!isset($mobsHave[$mob_id]) || isset($mobsHave[$mob_id]) && $mobsHave[$mob_id] < $mobsNeeded[$mob_id]) { $completed = 'no'; } } // Maybe the character is turning in the quest... if ($completed == 'yes' && $turnIn == true && isset($character_id) && isset($quest_id)) { $completed = 'finished'; } // Als de quest 'finished' is, dan moeten eventuele items uit de inventory verwijderd worden... // Dat kan hier. if ($completed == 'finished' && !empty($itemsNeeded)) { foreach ($itemsNeeded as $item_id => $amount) { for ($j = 1; $j <= $amount; $j++) { $Inventory->deleteAll(array('Inventory.character_id' => $quest['CharactersQuest']['character_id'], 'Inventory.item_id' => $item_id)); } } } $charactersQuestsData[$i]['completed'] = $completed; } // En voor het mooi, natuurlijk ook even de rewards geven... if ($completed == 'finished' && !empty($itemsRewards)) { App::import('Model', 'Drop'); $Drop = new Drop(); foreach ($itemsRewards as $item_id => $amount) { for ($j = 1; $j <= $amount; $j++) { $data = array(); // Bagid en index opvragen $bagIndex = $Drop->hasFreeSpace($quest['CharactersQuest']['character_id'], $item_id, true); $data['character_id'] = $quest['CharactersQuest']['character_id']; $data['item_id'] = $item_id; $data['index'] = $bagIndex['index']; $data['bag_id'] = $bagIndex['bag_id']; $Inventory->create(); $Inventory->save($data); } } } if ($completed == 'finished' && !empty($statsRewards)) { App::import('Model', 'CharactersStat'); $CharactersStat = new CharactersStat(); foreach ($statsRewards as $stat_id => $amount) { $statData = array(); $statData['character_id'] = $quest['CharactersQuest']['character_id']; // Kijken of deze stat al in de database bestaat $someStat = $CharactersStat->find('first', array('conditions' => array('CharactersStat.stat_id' => $stat_id, 'CharactersStat.character_id' => $quest['CharactersQuest']['character_id']))); if (!empty($someStat)) { $statData['id'] = $someStat['CharactersStat']['id']; $statData['amount'] = $someStat['CharactersStat']['amount'] + $amount; } else { $statData['amount'] = $amount; $statData['stat_id'] = $stat_id; } $CharactersStat->create(); $CharactersStat->save($statData); } } $i++; } $CharactersQuest->saveAll($charactersQuestsData); } }
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Inventory.php"; $app = new Silex\Application(); $server = 'mysql:host=localhost;dbname=inventory'; $username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig', array('inventory' => Inventory::getAll())); }); $app->post("/create", function () use($app) { $inventory = new Inventory($_POST['item']); $inventory->save(); return $app['twig']->render('index.html.twig', array('inventory' => Inventory::getAll())); }); $app->post("/delete", function () use($app) { Inventory::deleteAll(); return $app['twig']->render('index.html.twig'); }); $app->get("/search", function () use($app) { $search = Inventory::find($_GET['search']); return $app['twig']->render('search.html.twig', array('search' => $search, 'search_term' => $_GET['search'])); }); return $app;
/** * Remove the specified resource from storage. * DELETE /inventories/{id} * * @param int $id * @return Response */ public function destroy($id) { $item = Inventory::find($id); $item->{$delete}(); }
function test_find() { //Arrange $item = 'action figure'; $item2 = 'stuffed animal'; $test_Inventory = new Inventory($item); $test_Inventory->save(); $test_Inventory2 = new Inventory($item2); $test_Inventory2->save(); //Act $result = Inventory::find($test_Inventory->getId()); //Assert $this->assertEquals($test_Inventory, $result); }
/** * Show the form for editing the specified inventory. * * @param int $id * @return Response */ public function edit($id) { $inventory = Inventory::find($id); return View::make('inventories.edit', compact('inventory')); }
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Inventory.php"; $app = new Silex\Application(); $server = 'mysql:host=localhost;dbname=inventory'; $username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig', array('candies' => Inventory::getAll())); }); $app->get("/candies", function () use($app) { return $app['twig']->render('candies.html.twig', array('candies' => Inventory::getAll())); }); $app->post("/candies", function () use($app) { $candy = new Inventory($_POST['name']); $candy->save(); return $app['twig']->render('candies.html.twig', array('candies' => Inventory::getAll())); }); $app->post("/delete_candy", function () use($app) { Inventory::deleteAll(); return $app['twig']->render('index.html.twig'); }); $app->get("/found_candy", function () use($app) { return $app['twig']->render('found_candy.html.twig', array('candies' => Inventory::find($_GET['search']))); }); return $app;
Route::get('/', function () { $t = 1; $inventories = Inventory::all(); return View::make('main/index')->with('inventories', $inventories)->with('t', $t); }); Route::get('/albums', function () { $albums = Collection::all(); return View::make('main/albums')->with('albums', $albums); }); Route::get('/album/{albums}', function ($albums) { $albums = Collection::find($albums); return View::make('main/album')->with(array('albums' => $albums)); }); Route::get('/albums/{album}/image/{image}', function ($album, $image) { $album = Collection::find($album); $image = Inventory::find($image); return View::make('main/image')->with(array('album' => $album, 'image' => $image)); }); Route::get('/login', function () { return View::make('main/login'); }); //// ADMIN ROUTES BELOW Route::resource('inventory', 'InventoryController'); Route::get('/users/{id}/pictures', function ($id) { $user = User::find($id); return View::make('inventories/mypics')->with('images', $user->pictures); }); Route::resource('collection', 'CollectionController'); Route::controller('users', 'UsersController'); Route::post('comment/{id}', 'CommentController@store'); Route::resource('comment', 'CommentController');
function addNewRelease() { $release = Release::create(array('strReleasesID' => Input::get('releaseID'), 'strReleaseBrchID' => Input::get('branchID'), 'strReleaseBy' => Input::get('empID'), 'dtDateReleased' => date('Y-m-d'))); $release->save(); $ids = DB::table('tblReleaseNotes')->select('strReleaseNotesID')->orderBy('updated_at', 'desc')->orderBy('strReleaseNotesID', 'desc')->take(1)->get(); $ID = $ids["0"]->strReleaseNotesID; $newID = $this->smart($ID); $notes = ReleaseNote::create(array('strReleaseNotesID' => $newID, 'strReleaseID' => Input::get('releaseID'), 'strReleaseNotesStat' => 'Pending')); $notes->save(); $item = Input::get('itemsRelease'); // 'strOPOrdersID', 'strOPProdID', 'intOPQuantity' for ($i = 0; $i < count($item); $i++) { $relItem = ReleaseDetail::create(array('strReleaseHeaderID' => Input::get('releaseID'), 'strReleaseProducts' => $item[$i][1], 'intReleaseQty' => $item[$i][3])); $relItem->save(); } $prod = Input::get('itemsRelease'); for ($ctr = 0; $ctr < count($prod); $ctr++) { $qty = $prod[$ctr][3]; //$prodID = $prod[$ctr][1]; // $batch = DB::table('tblInventory') // ->select('strBatchID') // ->where('strProdID','=',$prodID) // ->orderBy('strBatchID', 'asc') // ->take(1) // ->get(); $batch = $prod[$ctr][0]; //$inv = $batch["0"]->strBatchID; $inventory = Inventory::find($batch); $inventory->intAvailQty -= $qty; $inventory->save(); } }
<?php require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../src/Inventory.php'; $app = new Silex\Application(); $app['debug'] = true; $server = 'mysql:host=localhost;dbname=inventory'; $username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig'); }); $app->post("/items", function () use($app) { $item = new Inventory($_POST['item']); $item->save(); return $app['twig']->render('index.html.twig', array('items' => Inventory::getAll())); }); $app->post("/delete_items", function () use($app) { Inventory::deleteAll(); return $app['twig']->render('index.html.twig'); }); $app->post("/search_items", function () use($app) { $results = Inventory::find($_POST['search_item']); return $app['twig']->render('search_results.html.twig', array('results' => $results)); }); return $app;
public function allowInvEditDelete() { $inventory_id = Input::json('id'); $requested_wh_right = "AllowInvEditDelete"; $usergroup = User::find(Auth::id())->usergroup()->first(); $warehouse_id = Inventory::find($inventory_id)->Warehouse_Id; //select form usergroup channel rights where the channel_id and usergroup_id and ch_right $Right_list = DB::select(DB::raw("SELECT ugwhr.* FROM usergroupswhrights ugwhr, warehouserights whr\n\t\t\t\tWHERE ugwhr.Warehouse_Id = " . $warehouse_id . " and ugwhr.UserGroup_Id = " . $usergroup->UserGroup_Id . "\n\t\t\t\t\tand ugwhr.Warehouse_Right_Id = whr.WarehouseRight_Id\n\t\t\t\t\tand whr.Warehouse_Right_Name = '" . $requested_wh_right . "'")); return Response::json(count($Right_list) > 0); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $inventory = Inventory::find($id); $inventory->delete(); if (Input::get('album') == 'true') { return Redirect::action('CollectionController@index'); } else { return Redirect::route('inventory.index'); } }
/** * Check if a character can loot a item * * There are a several conditions before an item can be looted. * If the field `Item.unique` is greater then 0 the item may not be looted if * the character has already the number of `unique` in it's bags. In case of * the field `AreasObstaclesItem.max_drop` is greater than 0 the item may not * be looted again. If `AreasObstaclesItem.player_only` this last conditions is * per Character and not per game. So it is possible to loot an very rarely item * witch can be looted X times in a game. * There is also a field called `AreasObstaclesItem.spawn_time`. This is the time * in seconds between the item can looted. If `AreasObstaclesItem.player_only` is * set to 1 this only counts for the player. * If the character doesn't have enough space in it's back the item cannot be * loaded aswell. * An item can only be looted if the character is at the same location of the item. * Some items can only be looted if the character is on a quest (and not completed). * * @param int $character_id the current character ID * @param int $areas_obstacles_item_id the ID of the Area_Obstacle_Item @see `areas_obstacles_items` * @param int $area_id the current area of the character * @return boolean whenever the character can loot or not */ function canLoot($areas_obstacles_item_id = null, $character_id = null, $area_id = null) { if (!isset($character_id) || !isset($areas_obstacles_item_id)) { return false; } $conditions = array(); $conditions['Drop.character_id'] = $character_id; App::import('Model', 'AreasObstaclesItem'); $AreasObstaclesItem = new AreasObstaclesItem(); $AreasObstaclesItem->contain(array('AreasObstacle')); $drop = $AreasObstaclesItem->find('first', array('conditions' => array('AreasObstaclesItem.id' => $areas_obstacles_item_id))); if ($drop['AreasObstacle']['area_id'] != $area_id) { return false; } if ($drop['AreasObstaclesItem']['quest_id'] != 0) { App::import('Model', 'CharactersQuest'); $CharactersQuest = new CharactersQuest(); $hasQuest = $CharactersQuest->find('first', array('conditions' => array('CharactersQuest.character_id' => $character_id, 'CharactersQuest.quest_id' => $drop['AreasObstaclesItem']['quest_id'], 'CharactersQuest.completed' => 'no'))); if (empty($hasQuest)) { return false; } } if (isset($drop['AreasObstaclesItem']['item_id'])) { $conditions['Drop.item_id'] = $drop['AreasObstaclesItem']['item_id']; } $allDrops = $this->find('count', array('conditions' => array('Drop.character_id' => $character_id, 'Drop.item_id' => $drop['AreasObstaclesItem']['item_id'], 'Drop.areas_obstacle_item_id' => $drop['AreasObstaclesItem']['id']))); App::import('Model', 'Inventory'); $Inventory = new Inventory(); $Inventory->contain(); $hasAmount = $Inventory->find('count', array('conditions' => array('Inventory.character_id' => $character_id, 'Inventory.item_id' => $drop['AreasObstaclesItem']['item_id']))); if (isset($drop['AreasObstaclesItem']['max_drop']) && $drop['AreasObstaclesItem']['max_drop'] > 0) { if ($allDrops >= $drop['AreasObstaclesItem']['max_drop'] && $hasAmount >= $drop['AreasObstaclesItem']['max_drop']) { return false; } } if (isset($drop['AreasObstaclesItem']['spawn_time']) && $drop['AreasObstaclesItem']['spawn_time'] > 0) { $conditions['Drop.created >'] = date('Y-m-d H:i:s', strtotime("-" . $drop['AreasObstaclesItem']['spawn_time'] . " seconds")); } $conditions['Drop.areas_obstacle_item_id'] = $drop['AreasObstaclesItem']['id']; $someDrops = $this->find('first', array('conditions' => $conditions)); if (!$this->hasFreeSpace($character_id, $drop['AreasObstaclesItem']['item_id'])) { return false; } if (empty($someDrops)) { return true; } else { if ($hasAmount < $drop['AreasObstaclesItem']['max_drop']) { return true; } else { return false; } } }