_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q257600
GameServer.updatePlayers
test
public function updatePlayers($rconPassword = null) { $this->handleResponseForRequest(self::REQUEST_PLAYER); if(!$this->rconAuthenticated) { if($rconPassword == null) { return; } $this->rconAuth($rconPassword); } $players = []; foreach(explode("\n", $this->rconExec('status')) as $line) { if(strpos($line, '#') === 0 && $line != '#end') { $players[] = trim(substr($line, 1)); } } $attributes = $this->getPlayerStatusAttributes(array_shift($players)); foreach($players as $player) { $playerData = $this->splitPlayerStatus($attributes, $player); if(array_key_exists($playerData['name'], $this->playerHash)) { $this->playerHash[$playerData['name']]->addInformation($playerData); } } }
php
{ "resource": "" }
q257601
SteamPlayer.addInformation
test
public function addInformation($playerData) { if($playerData['name'] != $this->name) { throw new SteamCondenserException('Information to add belongs to a different player.'); } $this->extended = true; $this->connectionId = intval($playerData['userid']); if(array_key_exists('state', $playerData)) { $this->state = $playerData['state']; } $this->steamId = $playerData['uniqueid']; if(!$this->isBot()) { $this->loss = intval($playerData['loss']); $this->ping = intval($playerData['ping']); if(array_key_exists('adr', $playerData)) { $address = explode(':', $playerData['adr']); $this->ipAddress = $address[0]; $this->clientPort = intval($address[1]); } if(array_key_exists('rate', $playerData)) { $this->rate = $playerData['rate']; } } }
php
{ "resource": "" }
q257602
GameLeaderboard.getLeaderboard
test
public static function getLeaderboard($gameName, $id) { $leaderboards = self::getLeaderboards($gameName); if (is_int($id)) { if (array_key_exists($id, $leaderboards)) { return $leaderboards[$id]; } else { return null; } } else { foreach(array_values($leaderboards) as $board) { if($board->getName() == $id) { return $board; } } } }
php
{ "resource": "" }
q257603
GameLeaderboard.getLeaderboards
test
public static function getLeaderboards($gameName) { if(!array_key_exists($gameName, self::$leaderboards)) { self::loadLeaderboards($gameName); } return self::$leaderboards[$gameName]; }
php
{ "resource": "" }
q257604
GameLeaderboard.loadLeaderboards
test
private static function loadLeaderboards($gameName) { $url = "http://steamcommunity.com/stats/$gameName/leaderboards/?xml=1"; $boardsData = new \SimpleXMLElement(file_get_contents($url)); if(!empty($boardsData->error)) { throw new SteamCondenserException((string) $boardsData->error); } self::$leaderboards[$gameName] = []; foreach($boardsData->leaderboard as $boardData) { $leaderboard = new GameLeaderboard($boardData); self::$leaderboards[$gameName][$leaderboard->getId()] = $leaderboard; } }
php
{ "resource": "" }
q257605
GameLeaderboard.getEntryForSteamId
test
public function getEntryForSteamId($steamId) { if (is_object($steamId)) { $id = $steamId->getSteamId64(); } else { $id = $steamId; } $xml = $this->loadDataForSteamId($id); foreach($xml->entries->entry as $entryData) { if($entryData->steamid == $id) { return new GameLeaderboardEntry($entryData, $this); } } return null; }
php
{ "resource": "" }
q257606
GameLeaderboard.getEntryRange
test
public function getEntryRange($first, $last) { if($last < $first) { throw new SteamCondenserException('First entry must be prior to last entry for leaderboard entry lookup.'); } if(($last - $first) > 5000) { throw new SteamCondenserException('Leaderboard entry lookup is currently limited to a maximum of 5001 entries per request.'); } $xml = $this->loadData(['start' => $first, 'end' => $last]); return $this->parseEntries($xml); }
php
{ "resource": "" }
q257607
GameLeaderboard.loadData
test
protected function loadData(array $params) { $url = $this->url; if (!empty($params)) { $url_params = []; foreach($params as $k => $v) { $url_params[] = "$k=$v"; } $url .= '&' . join('&', $url_params); } $xml = new \SimpleXMLElement(file_get_contents($url)); if (!empty($xml->error)) { throw new SteamCondenserException((string) $xml->error); } return $xml; }
php
{ "resource": "" }
q257608
GameLeaderboard.loadDataForSteamId
test
protected function loadDataForSteamId($steamId) { if (is_object($steamId)) { $id = $steamId->getSteamId64(); } else { $id = $steamId; } return $this->loadData(['steamid' => $id]); }
php
{ "resource": "" }
q257609
GameLeaderboard.parseEntries
test
protected function parseEntries(\SimpleXMLElement $xml) { $entries = []; foreach($xml->entries->entry as $entryData) { $rank = (int) $entryData->rank; $entries[$rank] = new GameLeaderboardEntry($entryData, $this); } return $entries; }
php
{ "resource": "" }
q257610
SteamGame.create
test
public static function create(\stdClass $gameData) { if(array_key_exists($gameData->appid, self::$games)) { return self::$games[$gameData->appid]; } else { return new SteamGame($gameData); } }
php
{ "resource": "" }
q257611
SteamGame.checkUpToDate
test
public static function checkUpToDate($appId, $version) { $params = ['appid' => $appId, 'version' => $version]; $result = WebApi::getJSONObject('ISteamApps', 'UpToDateCheck', 1, $params); $result = $result->response; if(!$result->success) { throw new SteamCondenserException($result->error); } return $result->up_to_date; }
php
{ "resource": "" }
q257612
SteamGame.getPlayerCount
test
public function getPlayerCount() { $params = ['appid' => $this->appId]; $result = WebApi::getJSONObject('ISteamUserStats', 'GetNumberOfCurrentPlayers', 1, $params); return $result->response->player_count; }
php
{ "resource": "" }
q257613
SteamGame.getUserStats
test
public function getUserStats($steamId) { if(!$this->hasStats()) { return null; } return GameStats::create($steamId, $this->appId); }
php
{ "resource": "" }
q257614
WorkOrderPartProcessor.index
test
public function index($workOrderId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $parts = $this->presenter->table($workOrder); $inventory = $this->presenter->tableInventory($workOrder, $this->inventory); $navbarParts = $this->presenter->navbarParts($workOrder); $navbarInventory = $this->presenter->navbarInventory(); return view('work-orders.parts.index', compact('parts', 'inventory', 'workOrder', 'navbarParts', 'navbarInventory')); }
php
{ "resource": "" }
q257615
Controller.store
test
public function store(Request $request) { $event = $this->event->create($request); if ($event) { $message = 'Successfully created event.'; return redirect()->route('maintenance.events.index')->withSuccess($message); } else { $message = 'There was an issue creating an event. Please try again.'; return redirect()->route('maintenance.events.create')->withErrors($message); } }
php
{ "resource": "" }
q257616
Controller.show
test
public function show($id) { $event = $this->event->find($id); $apiObject = $this->event->findApiObject($event->api_id); if ($apiObject) { return view('events.show', compact('event', 'apiObject')); } abort(404); }
php
{ "resource": "" }
q257617
Controller.update
test
public function update(Request $request, $id) { $event = $this->event->update($request, $id); if ($event) { $message = 'Successfully updated event.'; return redirect()->route('maintenance.events.show', [$event->id])->withSuccess($message); } else { $message = 'There was an issue updating this event. Please try again.'; return redirect()->route('maintenance.events.create')->withErrors($message); } }
php
{ "resource": "" }
q257618
Controller.destroy
test
public function destroy($id) { if ($this->event->delete($id)) { $message = 'Successfully deleted event'; return redirect()->route('maintenance.events.index')->withSuccess($message); } else { $message = 'There was an error trying to delete this event. Please try again.'; return redirect()->route('maintenance.events.show', [$id])->withErrors($message); } }
php
{ "resource": "" }
q257619
WorkOrderProcessor.show
test
public function show($id) { $workOrder = $this->workOrder->findOrFail($id); $sessions = $this->presenter->tableSessions($workOrder); $history = $this->presenter->tableHistory('work-orders', $workOrder->revisions()); $navbar = $this->presenter->navbarShow($workOrder); $formComment = $this->presenter->formComment($workOrder, $workOrder->comments()->getRelated()); return view('work-orders.show', compact('workOrder', 'sessions', 'history', 'navbar', 'formComment')); }
php
{ "resource": "" }
q257620
WorkOrderProcessor.edit
test
public function edit($id) { $workOrder = $this->workOrder->findOrFail($id); $form = $this->presenter->form($workOrder); return view('work-orders.edit', compact('form')); }
php
{ "resource": "" }
q257621
WorkOrderProcessor.update
test
public function update(WorkOrderRequest $request, $id) { $workOrder = $this->workOrder->findOrFail($id); return $this->dispatch(new Update($request, $workOrder)); }
php
{ "resource": "" }
q257622
WorkOrderPartStockController.getTake
test
public function getTake($workOrderId, $itemId, $stockId) { return $this->processor->getTake($workOrderId, $itemId, $stockId); }
php
{ "resource": "" }
q257623
WorkOrderPartStockController.postTake
test
public function postTake(PartTakeRequest $request, $workOrderId, $itemId, $stockId) { try { if ($this->processor->postTake($request, $workOrderId, $itemId, $stockId)) { flash()->success('Success!', 'Successfully added parts to work order.'); return redirect()->route('maintenance.work-orders.parts.index', [$workOrderId]); } else { flash()->error('Error!', 'There was an issue adding parts to this work order. Please try again.'); return redirect()->route('maintenance.work-orders.parts.stocks.take', [$workOrderId, $itemId, $stockId]); } } catch (NotEnoughStockException $e) { flash()->error('Not Enough Stock', "There isn't enough stock available to take the requested quantity."); return redirect()->route('maintenance.work-orders.parts.stocks.take', [$workOrderId, $itemId, $stockId]); } }
php
{ "resource": "" }
q257624
WorkOrderPartStockController.getPut
test
public function getPut($workOrderId, $inventoryId, $stockId) { return $this->processor->getPut($workOrderId, $inventoryId, $stockId); }
php
{ "resource": "" }
q257625
WorkOrderPartStockController.postPut
test
public function postPut(PartReturnRequest $request, $workOrderId, $inventoryId, $stockId) { if ($this->processor->postPut($request, $workOrderId, $inventoryId, $stockId)) { flash()->success('Success!', 'Successfully returned parts to the inventory.'); return redirect()->route('maintenance.work-orders.parts.index', [$workOrderId]); } else { flash()->error('Error!', 'There was an issue returning parts into the inventory. Please try again.'); return redirect()->route('maintenance.work-orders.parts.stocks.put', [$workOrderId]); } }
php
{ "resource": "" }
q257626
Controller.show
test
public function show($id) { $workRequest = $this->workRequest->model()->findOrFail($id); return view('client.work-requests.show', compact('workRequest')); }
php
{ "resource": "" }
q257627
Controller.edit
test
public function edit($id) { $workRequest = $this->workRequest->model()->findOrFail($id); return view('client.work-requests.edit', compact('workRequest')); }
php
{ "resource": "" }
q257628
Controller.update
test
public function update(WorkRequest $request, $id) { $workRequest = $this->workRequest->update($request, $id); if ($workRequest) { $message = 'Successfully updated work request.'; return redirect()->route('maintenance.client.work-requests.show', [$workRequest->id])->withSuccess($message); } else { $message = 'There was an issue updating your work request. Please try again.'; return redirect()->route('maintenance.client.work-requests.edit', [$id])->withErrors($message); } }
php
{ "resource": "" }
q257629
Controller.destroy
test
public function destroy($id) { $workRequest = $this->workRequest->model()->findOrFail($id); if ($workRequest->delete()) { $message = 'Successfully deleted work request.'; return redirect()->route('maintenance.client.work-requests.index')->withSuccess($message); } else { $message = 'There was an issue deleting this work request. Please try again.'; return redirect()->route('maintenance.client.work-requests.show', [$id])->withErrors($message); } }
php
{ "resource": "" }
q257630
HasLocationTrait.scopeLocation
test
public function scopeLocation($query, $locationId = null) { if (!is_null($locationId)) { // Get descendants and self inventory category nodes $locations = Location::find($locationId)->getDescendantsAndSelf(); // Perform a sub-query on main query $query->where(function ($query) use ($locations) { // For each category, apply a orWhere query to the sub-query foreach ($locations as $location) { $query->orWhere('location_id', $location->id); } }); } return $query; }
php
{ "resource": "" }
q257631
ReportController.store
test
public function store(ReportRequest $request, $eventId) { $report = $this->event->createReport($request, $eventId); if ($report) { $message = 'Successfully created event report.'; return redirect()->route('maintenance.events.show', [$eventId, '#tab-report'])->withSuccess($message); } else { $message = 'There was an issue creating a report for this event. Please try again.'; return redirect()->route('maintenance.events.show', [$eventId, '#tab-report'])->withErrors($message); } }
php
{ "resource": "" }
q257632
WorkOrderAttachmentProcessor.create
test
public function create($workOrderId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $form = $this->presenter->form($workOrder, $workOrder->attachments()->getRelated()); return view('work-orders.attachments.create', compact('form')); }
php
{ "resource": "" }
q257633
WorkOrderAttachmentProcessor.store
test
public function store(AttachmentRequest $request, $workOrderId) { $workOrder = $this->workOrder->findOrFail($workOrderId); return $this->dispatch(new Store($request, $workOrder->attachments())); }
php
{ "resource": "" }
q257634
WorkOrderAttachmentProcessor.show
test
public function show($workOrderId, $attachmentId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $attachment = $workOrder->attachments()->findOrFail($attachmentId); return view('work-orders.attachments.show', compact('workOrder', 'attachment')); }
php
{ "resource": "" }
q257635
WorkOrderAttachmentProcessor.edit
test
public function edit($workOrderId, $attachmentId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $attachment = $workOrder->attachments()->findOrFail($attachmentId); $form = $this->presenter->form($workOrder, $attachment); return view('work-orders.attachments.edit', compact('form')); }
php
{ "resource": "" }
q257636
WorkOrderAttachmentProcessor.update
test
public function update(AttachmentUpdateRequest $request, $workOrderId, $attachmentId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $attachment = $workOrder->attachments()->findOrFail($attachmentId); return $this->dispatch(new Update($request, $attachment)); }
php
{ "resource": "" }
q257637
WorkOrderAttachmentProcessor.destroy
test
public function destroy($workOrderId, $attachmentId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $attachment = $workOrder->attachments()->findOrFail($attachmentId); return $this->dispatch(new Destroy($attachment)); }
php
{ "resource": "" }
q257638
WorkOrderReportPresenter.form
test
public function form(WorkOrder $workOrder, WorkOrderReport $report) { return $this->form->of('work-orders.report', function (FormGrid $form) use ($workOrder, $report) { if ($report->exists) { $method = 'PATCH'; $url = route('maintenance.work-orders.report.update', [$workOrder->getKey(), $report->getKey()]); $form->submit = 'Save'; } else { $method = 'POST'; $url = route('maintenance.work-orders.report.store', [$workOrder->getKey()]); $form->submit = 'Create'; } $form->attributes(compact('method', 'url')); $form->with($report); $form->fieldset(function (Fieldset $fieldset) use ($workOrder) { $fieldset ->control('select', 'status') ->options(function () { $statuses = Status::all()->pluck('name', 'id'); $statuses[0] = 'None'; return $statuses; }) ->value(function () use ($workOrder) { if ($workOrder->status instanceof Status) { return $workOrder->status->getKey(); } }) ->attributes([ 'class' => 'select2', ]); $fieldset->control('input:textarea', 'description'); }); }); }
php
{ "resource": "" }
q257639
Notification.getIconAttribute
test
public function getIconAttribute() { $class = $this->attributes['notifiable_type']; /* * Resolve the configuration service from the IoC since * we don't want to override the Notification models constructor * to inject the service */ $config = App::make(ConfigService::class); // Make sure we have an instance of the ConfigService returned by the IoC if ($config instanceof ConfigService) { $icon = $config->setPrefix('maintenance')->get("notifications.icons.$class"); // Return the models notification icon if it's found if (is_string($icon) && !empty($icon)) { return $icon; } /* * Looks like the notification icon could not be * found, we'll return the default notification icon */ $defaultIcon = $config->setPrefix('maintenance')->get('notifications.icons.default'); return $defaultIcon; } return; }
php
{ "resource": "" }
q257640
StockMovementController.index
test
public function index($inventory_id, $stock_id) { $item = $this->inventory->find($inventory_id); $stock = $this->inventoryStock->find($stock_id); $data = $this->inputAll(); $data['stock_id'] = $stock->id; $movements = $this->inventoryStockMovement->setInput($data)->getByPageWithFilter(); return view('inventory.stocks.movements.index', [ 'title' => "Viewing Stock Movements for Item: $item->name in Location: ".renderNode($stock->location), 'item' => $item, 'stock' => $stock, 'movements' => $movements, ]); }
php
{ "resource": "" }
q257641
StockMovementController.show
test
public function show($inventory_id, $stock_id, $movement_id) { $item = $this->inventory->find($inventory_id); $stock = $this->inventoryStock->find($stock_id); $movement = $this->inventoryStockMovement->find($movement_id); return view('inventory.stocks.movements.show', [ 'title' => 'Viewing Movement: '.$movement->id, 'item' => $item, 'stock' => $stock, 'movement' => $movement, ]); }
php
{ "resource": "" }
q257642
StockMovementController.rollback
test
public function rollback($inventory_id, $stock_id, $movement_id) { $item = $this->inventory->find($inventory_id); $stock = $this->inventoryStock->find($stock_id); $movement = $this->inventoryStockMovement->find($movement_id); if ($stock->rollback($movement)) { $this->message = 'Successfully rolled back movement'; $this->messageType = 'success'; $this->redirect = routeBack('maintenance.inventory.stock.movements.index', [ $item->id, $stock->id, ]); } else { $this->message = 'There was an error trying to roll back this movement. Please try again.'; $this->messageType = 'success'; $this->redirect = routeBack('maintenance.inventory.stock.movements.index', [ $item->id, $stock->id, ]); } return $this->response(); }
php
{ "resource": "" }
q257643
WorkOrder.getRevisedStatusAttribute
test
public function getRevisedStatusAttribute($id) { if ($id) { $status = $this->status()->find($id); if ($status instanceof Status) { return $status->getLabel(); } } return; }
php
{ "resource": "" }
q257644
WorkOrder.getRevisedPriorityAttribute
test
public function getRevisedPriorityAttribute($id) { if ($id) { $priority = $this->priority()->find($id); if ($priority instanceof Priority) { return $priority->getLabel(); } } return; }
php
{ "resource": "" }
q257645
WorkOrder.closeSessions
test
public function closeSessions() { $closed = []; foreach ($this->sessions as $session) { if ($session instanceof WorkOrderSession && is_null($session->out)) { $session->out = $this->freshTimestamp(); if ($session->save()) { $closed[] = $session; } } } return $closed; }
php
{ "resource": "" }
q257646
WorkOrder.userCheckedIn
test
public function userCheckedIn() { $session = $this->getCurrentSession(); if ($session instanceof WorkOrderSession) { return $session->in && is_null($session->out); } return false; }
php
{ "resource": "" }
q257647
WorkOrder.getStartedAtLabel
test
public function getStartedAtLabel() { if ($this->started_at) { $class = 'label label-success'; $icon = 'fa fa-check'; $message = $this->started_at; } else { $class = 'label label-danger'; $icon = 'fa fa-times'; $message = 'Has not been started.'; } $icon = HTML::create('i', '', ['class' => $icon]); return HTML::raw("<span class='$class'>$icon $message</span>"); }
php
{ "resource": "" }
q257648
WorkOrder.getCompletedAtLabel
test
public function getCompletedAtLabel() { if ($this->isComplete()) { $class = 'label label-success'; $icon = 'fa fa-check'; $message = $this->completed_at; } else { $class = 'label label-danger'; $icon = 'fa fa-times'; $message = 'No report has been created.'; } $icon = HTML::create('i', '', ['class' => $icon]); return HTML::raw("<span class='$class'>$icon $message</span>"); }
php
{ "resource": "" }
q257649
WorkOrder.complete
test
public function complete($statusId) { if (is_null($this->started_at)) { $this->started_at = $this->freshTimestamp(); } $this->completed_at = $this->freshTimestamp(); $this->status_id = $statusId; return $this->save(); }
php
{ "resource": "" }
q257650
WorkOrderStatusPresenter.table
test
public function table(Status $status) { return $this->table->of('work-orders.statuses', function (TableGrid $table) use ($status) { $table->with($status)->paginate($this->perPage); $table->column('Status', function (Column $column) { $column->value = function (Status $status) { return link_to_route('maintenance.work-orders.statuses.edit', $status->getLabel(), [$status->getKey()]); }; }); $table->column('created_at'); $table->column('created_by', function (Column $column) { $column->value = function (Status $status) { if ($status->user instanceof User) { return $status->user->getRecipientName(); } else { return HTML::create('em', 'None'); } }; }); }); }
php
{ "resource": "" }
q257651
WorkOrderStatusPresenter.form
test
public function form(Status $status) { return $this->form->of('work-orders.statuses', function (FormGrid $form) use ($status) { if ($status->exists) { $method = 'PATCH'; $url = route('maintenance.work-orders.statuses.update', [$status->getKey()]); $form->submit = 'Save'; } else { $method = 'POST'; $url = route('maintenance.work-orders.statuses.store', [$status->getKey()]); $form->submit = 'Create'; } $colors = config('maintenance.colors', []); $form->with($status); $form->attributes(compact('method', 'url')); $form->fieldset(function (Fieldset $fieldset) use ($colors) { $fieldset ->control('input:text', 'name') ->attributes([ 'placeholder' => 'ex. Awaiting Parts / Supplies', ]); $fieldset ->control('select', 'color') ->options($colors) ->value(function (Status $status) { return $status->color; }) ->attributes([ 'class' => 'select2-color', ]); }); }); }
php
{ "resource": "" }
q257652
WorkOrderPriorityProcessor.index
test
public function index() { $priorities = $this->presenter->table($this->priority); $navbar = $this->presenter->navbar(); return view('work-orders.priorities.index', compact('priorities', 'navbar')); }
php
{ "resource": "" }
q257653
WorkOrderPriorityProcessor.store
test
public function store(PriorityRequest $request) { $priority = $this->priority->newInstance(); return $this->dispatch(new Store($request, $priority)); }
php
{ "resource": "" }
q257654
WorkOrderPriorityProcessor.edit
test
public function edit($id) { $priority = $this->priority->findOrFail($id); $form = $this->presenter->form($priority); return view('work-orders.priorities.edit', compact('form')); }
php
{ "resource": "" }
q257655
WorkOrderPriorityProcessor.update
test
public function update(PriorityRequest $request, $id) { $priority = $this->priority->findOrFail($id); return $this->dispatch(new Update($request, $priority)); }
php
{ "resource": "" }
q257656
Inventory.scopeStock
test
public function scopeStock($query, $operator = null, $stock = null) { if ($operator && $stock) { return $query->whereHas('stocks', function ($query) use ($operator, $stock) { if ($output = $this->getOperator($operator)) { return $query->where('quantity', $output[0], $stock); } else { return $query; } }); } return $query; }
php
{ "resource": "" }
q257657
Inventory.scopeSku
test
public function scopeSku($query, $sku = null) { if ($sku) { return $query->whereHas('sku', function ($query) use ($sku) { return $query->where('code', 'LIKE', '%'.$sku.'%'); }); } return $query; }
php
{ "resource": "" }
q257658
Inventory.getCurrentStockAttribute
test
public function getCurrentStockAttribute() { $stock = $this->getTotalStock(); if ($this->hasMetric()) { return sprintf('%s %s', $stock, $this->getMetricSymbol()); } return $stock; }
php
{ "resource": "" }
q257659
Inventory.getRevisedMetricAttribute
test
public function getRevisedMetricAttribute($id) { if ($id) { $metric = $this->metric()->find($id); if ($metric) { return $metric->name; } } return; }
php
{ "resource": "" }
q257660
Model.getOperator
test
protected function getOperator($string) { $allowed_operators = ['>', '<', '=', '>=', '<=']; $output = preg_split("/[\[\]]/", $string); if (is_array($output)) { if (array_key_exists('1', $output) && array_key_exists('2', $output)) { if (in_array($output[1], $allowed_operators)) { return [$output[1], $output[2]]; } } else { return $output; } } return false; }
php
{ "resource": "" }
q257661
Model.scopeSort
test
public function scopeSort($query, $field = null, $sort = null) { /* * Make sure both the field and sort variables are present */ if ($field && $sort) { /* * Retrieve all column names for the current model table */ $columns = Schema::getColumnListing($this->getTable()); /* * Make sure the field inputted is available on the current table */ if (in_array($field, $columns)) { /* * Make sure the sort input is equal to asc or desc */ if ($sort === 'asc' || $sort === 'desc') { /* * Return the query sorted */ return $query->orderBy($field, $sort); } } } /* * Default to latest scope */ return $query->latest(); }
php
{ "resource": "" }
q257662
Attachment.getFullPathAttribute
test
public function getFullPathAttribute() { $config = sprintf('filesystems.%s.root', $this->getDisk()); $default = storage_path('app'); $basePath = config($config, $default); return $basePath.DIRECTORY_SEPARATOR.$this->file_path; }
php
{ "resource": "" }
q257663
WorkOrderStatusProcessor.index
test
public function index() { $statuses = $this->presenter->table($this->status); $navbar = $this->presenter->navbar(); return view('work-orders.statuses.index', compact('statuses', 'navbar')); }
php
{ "resource": "" }
q257664
WorkOrderStatusProcessor.store
test
public function store(StatusRequest $request) { $status = $this->status->newInstance(); return $this->dispatch(new Store($request, $status)); }
php
{ "resource": "" }
q257665
WorkOrderStatusProcessor.edit
test
public function edit($id) { $status = $this->status->findOrFail($id); $form = $this->presenter->form($status); return view('work-orders.statuses.edit', compact('form')); }
php
{ "resource": "" }
q257666
WorkOrderStatusProcessor.update
test
public function update(StatusRequest $request, $id) { $status = $this->status->findOrFail($id); return $this->dispatch(new Update($request, $status)); }
php
{ "resource": "" }
q257667
InventoryVariantProcessor.create
test
public function create($itemId) { $item = $this->inventory->findOrFail($itemId); $form = $this->presenter->form($item, $variant = true); return view('inventory.variants.create', compact('form')); }
php
{ "resource": "" }
q257668
InventoryVariantProcessor.store
test
public function store(InventoryRequest $request, $itemId) { $item = $this->inventory->findOrFail($itemId); $variant = $item->newVariant(); $variant->name = $request->input('name', $item->name); $variant->category_id = $request->input('category', $item->category_id); $variant->metric_id = $request->input('metric', $item->metric_id); return $variant->save(); }
php
{ "resource": "" }
q257669
WorkOrderReportProcessor.create
test
public function create($workOrderId) { $workOrder = $this->workOrder->findOrFail($workOrderId); if ($workOrder->isComplete()) { throw new ReportExistsException(); } $form = $this->presenter->form($workOrder, $this->report); return view('work-orders.report.create', compact('form')); }
php
{ "resource": "" }
q257670
WorkOrderReportProcessor.store
test
public function store(ReportRequest $request, $workOrderId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $report = $this->report->newInstance(); return $this->dispatch(new Store($request, $workOrder, $report)); }
php
{ "resource": "" }
q257671
WorkOrderPresenter.table
test
public function table($workOrder) { return $this->table->of('work-orders', function (TableGrid $table) use ($workOrder) { $table->with($workOrder)->paginate($this->perPage); $table->attributes([ 'class' => 'table table-hover table-striped', ]); $table->column('ID', 'id'); $table->column('subject', function (Column $column) { $column->value = function (WorkOrder $workOrder) { return link_to_route('maintenance.work-orders.show', $workOrder->subject, [$workOrder->getKey()]); }; }); $table->column('Created At', 'created_at'); $table->column('created_by', function (Column $column) { $column->value = function (WorkOrder $workOrder) { return $workOrder->user->fullname; }; }); $table->column('priority', function (Column $column) { $column->value = function (WorkOrder $workOrder) { if ($workOrder->priority instanceof Priority) { return $workOrder->priority->getLabel(); } return HTML::create('em', 'None'); }; }); $table->column('status', function (Column $column) { $column->value = function (WorkOrder $workOrder) { if ($workOrder->status instanceof Status) { return $workOrder->status->getLabel(); } return HTML::create('em', 'None'); }; }); }); }
php
{ "resource": "" }
q257672
WorkOrderPresenter.tableAssigned
test
public function tableAssigned($workOrder) { $workOrder = $workOrder->whereHas('assignments', function (Builder $query) { $query->where('to_user_id', auth()->id()); }); return $this->table($workOrder); }
php
{ "resource": "" }
q257673
WorkOrderPresenter.tableSessions
test
public function tableSessions(WorkOrder $workOrder) { $presenter = new WorkOrderSessionPresenter($this->form, $this->table); return $presenter->tablePerWorker($workOrder); }
php
{ "resource": "" }
q257674
WorkOrderPresenter.form
test
public function form(WorkOrder $workOrder) { return $this->form->of('work-orders', function (FormGrid $form) use ($workOrder) { if ($workOrder->exists) { $method = 'PATCH'; $url = route('maintenance.work-orders.update', [$workOrder->getKey()]); $form->submit = 'Save'; } else { $method = 'POST'; $url = route('maintenance.work-orders.store'); $form->submit = 'Create'; } $form->with($workOrder); $form->attributes(compact('method', 'url')); $form->fieldset(function (Fieldset $fieldset) { $fieldset ->control('select', 'category') ->value(function (WorkOrder $workOrder) { return $workOrder->category_id; }) ->options(function () { return Category::getSelectHierarchy('work-orders'); }); $fieldset ->control('select', 'location') ->value(function (WorkOrder $workOrder) { return $workOrder->location_id; }) ->options(function () { return Location::getSelectHierarchy(); }); $fieldset ->control('select', 'status') ->options(function () { $statuses = Status::all()->pluck('name', 'id'); $statuses[0] = 'None'; return $statuses; }); $fieldset ->control('select', 'priority') ->value(function (WorkOrder $workOrder) { return $workOrder->priority_id; }) ->options(function () { $priorities = Priority::all()->pluck('name', 'id'); $priorities[0] = 'None'; return $priorities; }); $fieldset ->control('select', 'assets[]') ->label('Assets') ->options(function () { return Asset::all()->pluck('name', 'id'); }) ->attributes([ 'class' => 'select2', 'multiple' => true, ]); $fieldset ->control('input:text', 'subject') ->attributes([ 'placeholder' => 'ex. Worked on HVAC', ]); $fieldset->control('input:textarea', 'description'); }); }); }
php
{ "resource": "" }
q257675
WorkOrderPresenter.formComment
test
public function formComment(WorkOrder $workOrder, Comment $comment) { $presenter = new WorkOrderCommentPresenter($this->form, $this->table); return $presenter->form($workOrder, $comment); }
php
{ "resource": "" }
q257676
Store.handle
test
public function handle(Filesystem $filesystem) { $files = $this->request->file('files'); if (is_array($files)) { $uploaded = []; foreach ($files as $file) { // Double check that we have an uploaded file instance. if ($file instanceof UploadedFile) { // Generates the unique file name. $name = implode('.', [uuid(), $file->getClientOriginalExtension()]); // Generates the complete storage path. $path = implode(DIRECTORY_SEPARATOR, [$this->path, $name]); // Try and move the uploaded file into storage. if ($filesystem->put($path, file_get_contents($file->getRealPath()))) { // Successfully moved uploaded file, create the record. $attributes = [ 'user_id' => auth()->id(), 'name' => $file->getClientOriginalName(), 'file_name' => $name, 'file_path' => $path, ]; $uploaded[] = $this->relation->create($attributes); } } } return $uploaded; } return false; }
php
{ "resource": "" }
q257677
AssetPresenter.table
test
public function table(Asset $asset) { return $this->table->of('assets', function (TableGrid $table) use ($asset) { $table->with($asset)->paginate($this->perPage); $table->attributes([ 'class' => 'table table-hover table-striped', ]); $table->column('tag'); $table->column('name', function (Column $column) { $column->value = function (Asset $asset) { return link_to_route('maintenance.assets.show', $asset->name, [$asset->getKey()]); }; }); $table->column('category', function (Column $column) { $column->value = function (Asset $asset) { return $asset->category->trail; }; }); $table->column('location', function (Column $column) { $column->value = function (Asset $asset) { return $asset->location->trail; }; }); $table->column('created_at'); }); }
php
{ "resource": "" }
q257678
AssetPresenter.form
test
public function form(Asset $asset) { return $this->form->of('assets', function (FormGrid $form) use ($asset) { if ($asset->exists) { $method = 'PATCH'; $route = route('maintenance.assets.update', [$asset->getKey()]); $form->submit = 'Save'; } else { $method = 'POST'; $route = route('maintenance.assets.store'); $form->submit = 'Create'; } $categories = Category::getSelectHierarchy('assets'); $locations = Location::getSelectHierarchy(); $form->resource($this, $route, $asset, compact('method')); $form->fieldset(function (Fieldset $fieldset) use ($categories, $locations) { $fieldset ->control('input:text', 'tag') ->attributes([ 'placeholder' => 'ex. 100010', ]); $fieldset ->control('input:text', 'name') ->attributes([ 'placeholder' => 'ex. Ford F150', ]); $fieldset ->control('select', 'category') ->options($categories) ->value(function (Asset $asset) { return $asset->category_id; }); $fieldset ->control('select', 'location') ->options($locations) ->value(function (Asset $asset) { return $asset->location_id; }); $fieldset->control('input:textarea', 'description'); $fieldset->control('select', 'condition') ->options(trans('assets.conditions')) ->value(function (Asset $asset) { return $asset->condition_number; }); $fieldset->control('input:text', 'vendor') ->attributes([ 'placeholder' => 'ex. Ford', ]); $fieldset->control('input:text', 'make') ->attributes([ 'placeholder' => 'ex. F', ]); $fieldset->control('input:text', 'model') ->attributes([ 'placeholder' => 'ex. 150', ]); $fieldset->control('input:text', 'serial') ->attributes([ 'placeholder' => 'ex. 153423-13432432-2342423', ]); $fieldset->control('input:text', 'size') ->attributes([ 'placeholder' => 'ex. 1905 x 2463', ]); $fieldset->control('input:text', 'weight') ->attributes([ 'placeholder' => 'ex. 1 Ton', ]); $fieldset->control('input:text', 'acquired_at') ->attributes([ 'class' => 'pickadate', 'placeholder' => 'Click to Select a Date', ]); $fieldset->control('input:text', 'end_of_life') ->attributes([ 'class' => 'pickadate', 'placeholder' => 'Click to Select a Date', ]); }); }); }
php
{ "resource": "" }
q257679
InventoryPresenter.table
test
public function table($item) { return $this->table->of('inventory', function (TableGrid $table) use ($item) { $table->with($item)->paginate($this->perPage); $table->attributes([ 'class' => 'table table-hover table-striped', ]); $table->column('ID', 'id'); $table->column('sku', function (Column $column) { $column->label = 'SKU'; $column->value = function (Inventory $item) { return $item->getSku(); }; }); $table->column('name', function (Column $column) { $column->value = function (Inventory $item) { return link_to_route('maintenance.inventory.show', $item->name, [$item->getKey()]); }; }); $table->column('category', function (Column $column) { $column->value = function (Inventory $item) { return $item->category->trail; }; }); $table->column('current_stock', function (Column $column) { $column->value = function (Inventory $item) { return $item->getTotalStock(); }; }); }); }
php
{ "resource": "" }
q257680
InventoryPresenter.tableStocks
test
public function tableStocks(Inventory $item) { return (new InventoryStockPresenter($this->form, $this->table))->table($item); }
php
{ "resource": "" }
q257681
InventoryPresenter.form
test
public function form(Inventory $inventory, $variant = false) { return $this->form->of('inventory', function (FormGrid $form) use ($inventory, $variant) { if ($inventory->exists) { if ($variant === true) { // If the inventory item exists and we're looking to create a form // for a variant, we'll set the forms options accordingly. $method = 'POST'; $url = route('maintenance.inventory.variants.store', [$inventory->getKey()]); $form->submit = 'Create'; } else { // Otherwise we'll set the options to update the specified inventory item. $method = 'PATCH'; $url = route('maintenance.inventory.update', [$inventory->getKey()]); $form->submit = 'Save'; } } else { $method = 'POST'; $url = route('maintenance.inventory.store'); $form->submit = 'Create'; } $form->with($inventory); $form->attributes(compact('method', 'url')); $categories = Category::getSelectHierarchy('inventories'); $metrics = Metric::all()->pluck('name', 'id'); $metrics->put(0, 'None'); $form->fieldset(function (Fieldset $fieldset) use ($categories, $metrics) { $fieldset ->control('select', 'category') ->value(function (Inventory $item) { return $item->category_id; }) ->options($categories); $fieldset ->control('select', 'metric') ->value(function (Inventory $item) { return $item->metric_id; }) ->options($metrics); $fieldset ->control('input:text', 'name') ->attributes([ 'placeholder' => 'ex. Nails', ]); $fieldset->control('input:textarea', 'description'); }); }); }
php
{ "resource": "" }
q257682
InventoryPresenter.navbarStocks
test
public function navbarStocks(Inventory $item) { return (new InventoryStockPresenter($this->form, $this->table))->navbar($item); }
php
{ "resource": "" }
q257683
WorkOrderAttachmentController.store
test
public function store(AttachmentRequest $request, $workOrderId) { if ($uploaded = $this->processor->store($request, $workOrderId)) { $count = (is_array($uploaded) ? count($uploaded) : 0); flash()->success('Success!', "Successfully uploaded $count file(s)."); return redirect()->route('maintenance.work-orders.attachments.index', [$workOrderId]); } else { flash()->error('Error!', 'There was an issue uploading the files you selected. Please try again.'); return redirect()->route('maintenance.work-orders.attachments.create', [$workOrderId]); } }
php
{ "resource": "" }
q257684
WorkOrderAttachmentController.update
test
public function update(AttachmentUpdateRequest $request, $workOrderId, $attachmentId) { if ($this->processor->update($request, $workOrderId, $attachmentId)) { flash()->success('Success!', 'Successfully updated attachment.'); return redirect()->route('maintenance.work-orders.attachments.show', [$workOrderId, $attachmentId]); } else { flash()->error('Error!', 'There was an issue updating this attachment. Please try again.'); return redirect()->route('maintenance.work-orders.attachments.edit', [$workOrderId, $attachmentId]); } }
php
{ "resource": "" }
q257685
MetricPresenter.table
test
public function table(Metric $metric) { return $this->table->of('metrics', function (TableGrid $table) use ($metric) { $table->with($metric)->paginate($this->perPage); $table->column('name'); $table->column('symbol'); $table->column('Created', 'created_at'); }); }
php
{ "resource": "" }
q257686
Presenter.tableHistory
test
public function tableHistory($for, MorphMany $revisions) { return $this->table->of("$for.revisions", function (TableGrid $table) use ($revisions) { $table->with($revisions)->paginate($this->perPage); $table->pageName = 'history'; $table->column('user_responsible', function (Column $column) { $column->value = function (Revision $revision) { $user = $revision->getUserResponsible(); if ($user instanceof User) { return $user->getRecipientName(); } return HTML::create('em', 'None'); }; }); $table->column('changed', function (Column $column) { $column->value = function (Revision $revision) { return $revision->getColumnName(); }; }); $table->column('from', function (Column $column) { $column->value = function (Revision $revision) { $old = $revision->getOldValue(); if (is_null($old)) { return HTML::create('em', 'None'); } return $old; }; }); $table->column('to', function (Column $column) { $column->value = function (Revision $revision) { $new = $revision->getNewValue(); if (is_null($new)) { return HTML::create('em', 'None'); } return $new; }; }); $table->column('On', 'created_at'); }); }
php
{ "resource": "" }
q257687
ImageController.store
test
public function store(ImageRequest $request, $id) { $asset = $this->asset->find($id); $attachments = $this->image->upload($request, $asset, $asset->images()); if ($attachments) { $message = 'Successfully uploaded files.'; return redirect()->route('maintenance.assets.images.index', [$asset->id])->withSuccess($message); } else { $message = 'There was an issue uploading the files you selected. Please try again.'; return redirect()->route('maintenance.assets.images.create', [$id])->withErrors($message); } }
php
{ "resource": "" }
q257688
ImageController.show
test
public function show($id, $imageId) { $asset = $this->asset->find($id); $image = $asset->images()->find($imageId); if ($image) { return view('assets.images.show', compact('asset', 'image')); } abort(404); }
php
{ "resource": "" }
q257689
ImageController.update
test
public function update(AttachmentUpdateRequest $request, $id, $imageId) { $asset = $this->asset->find($id); $image = $this->image->update($request, $asset->images(), $imageId); if ($image) { $message = 'Successfully updated image.'; return redirect()->route('maintenance.assets.images.show', [$asset->id, $image->id])->withSuccess($message); } else { $message = 'There was an issue updating this image. Please try again.'; return redirect()->route('maintenance.assets.images.show', [$id, $imageId])->withErrors($message); } }
php
{ "resource": "" }
q257690
MetricProcessor.index
test
public function index() { $metrics = $this->presenter->table($this->metric); $navbar = $this->presenter->navbar(); return view('metrics.index', compact('metrics', 'navbar')); }
php
{ "resource": "" }
q257691
MetricProcessor.store
test
public function store(MetricRequest $request) { $metric = $this->metric->newInstance(); return $this->dispatch(new Store($request, $metric)); }
php
{ "resource": "" }
q257692
MetricProcessor.edit
test
public function edit($id) { $metric = $this->metric->findOrFail($id); $form = $this->presenter->form($metric); return view('metrics.edit', compact('form')); }
php
{ "resource": "" }
q257693
AssetProcessor.index
test
public function index() { $navbar = $this->presenter->navbar(); $assets = $this->presenter->table($this->asset); return view('assets.index', compact('assets', 'navbar')); }
php
{ "resource": "" }
q257694
AssetProcessor.store
test
public function store(AssetRequest $request) { $asset = $this->asset->newInstance(); $asset->user_id = $this->guard->id(); $asset->tag = $request->input('tag'); $asset->category_id = $request->input('category'); $asset->location_id = $request->input('location'); $asset->name = $request->input('name'); $asset->condition = $request->input('condition'); $asset->vendor = $request->input('vendor'); $asset->make = $request->input('make'); $asset->model = $request->input('model'); $asset->size = $request->input('size'); $asset->weight = $request->input('weight'); $asset->serial = $request->input('serial'); $asset->acquired_at = $request->formatDateWithTime($request->input('acquired_at')); $asset->end_of_life = $request->formatDateWithTime($request->input('end_of_life')); return $asset->save(); }
php
{ "resource": "" }
q257695
AssetProcessor.edit
test
public function edit($id) { $asset = $this->asset->findOrFail($id); $form = $this->presenter->form($asset); return view('assets.edit', compact('form')); }
php
{ "resource": "" }
q257696
AssetProcessor.update
test
public function update(AssetRequest $request, $id) { $asset = $this->asset->findOrFail($id); $asset->tag = $request->input('tag'); $asset->category_id = $request->input('category'); $asset->location_id = $request->input('location'); $asset->name = $request->input('name'); $asset->condition = $request->input('condition'); $asset->vendor = $request->input('vendor'); $asset->make = $request->input('make'); $asset->model = $request->input('model'); $asset->size = $request->input('size'); $asset->weight = $request->input('weight'); $asset->serial = $request->input('serial'); $asset->acquired_at = $request->formatDateWithTime($request->input('acquired_at')); $asset->end_of_life = $request->formatDateWithTime($request->input('end_of_life')); return $asset->save(); }
php
{ "resource": "" }
q257697
HasScopeIdTrait.scopeId
test
public function scopeId($query, $id = null) { if (!is_null($id)) { $query->where('id', $id); } return $query; }
php
{ "resource": "" }
q257698
Controller.response
test
public function response() { if ($this->isAjax()) { if ($this->errors) { return $this->responseJson([ 'errors' => $this->errors, ]); } else { return $this->responseJson([ 'message' => $this->message, 'messageType' => $this->messageType, 'redirect' => $this->redirect, ]); } } else { if ($this->errors) { return redirect($this->redirect) ->withInput() ->withErrors($this->errors); } else { return redirect($this->redirect) ->withInput() ->with('message', $this->message) ->with('messageType', $this->messageType); } } }
php
{ "resource": "" }
q257699
Controller.input
test
protected function input($name, $clean = false) { if ($this->inputHas($name)) { if ($clean) { return $this->clean(Input::get($name)); } else { return Input::get($name); } } return; }
php
{ "resource": "" }