/**
  * Check if access is allowed given an RFID card identifier.
  *
  * @param   Resource  $resource
  * @param   string    $cardId
  * @return  Response
  */
 public function check(Resource $resource, $cardId)
 {
     $now = Date::now();
     try {
         $card = Card::findOrFail($cardId);
         // @todo: refactor for single responsibility
         $reservation = $resource->reservations()->where('starts_at', '<=', $now)->where('ends_at', '>', $now)->where('user_id', '=', $card->user->id)->first();
         $allow = $reservation ? true : false;
         //
     } catch (ModelNotFoundException $e) {
         $reservation = null;
         $allow = false;
     }
     return ['time' => $now->format('Y-m-d H:i:s'), 'reservation' => $reservation, 'allow' => $allow];
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $resources = array_merge($this->resourceRoutes('users'));
     foreach ($resources as $resource) {
         Resource::create($resource);
     }
 }
Example #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $resource = new Resource();
     $resource->wood = 1000;
     $resource->stone = 1000;
     $resource->gold = 1000;
     $resource->save();
     $population = new Population();
     $population->count = 1000;
     $population->save();
     $city = new City();
     $city->Name = $request->name;
     $city->player()->associate(Auth::user());
     $city->resource()->associate($resource);
     $city->save();
 }
 /**
  * Creates enough resources to ensure that all distros are available as resources.
  */
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 50) as $index) {
         $os = $faker->randomElement(array_keys($this->distros));
         Resource::create(['os' => $os, 'os_version' => $faker->randomElement($this->distros[$os]), 'local_ip' => $faker->localIpv4()]);
     }
 }
Example #5
0
 /**
  * Get a user's search's resource.
  *
  * @param int $userId
  * @param int $searchId
  * @param int $resourceId
  * @return \Illuminate\Http\JsonResponse
  */
 public function show($userId, $searchId, $resourceId)
 {
     $resource = Resource::where(['id' => $resourceId, 'user_id' => $userId, 'search_id' => $searchId])->get();
     if ($resource) {
         return $this->respondWithCollection($resource, new ResourceTransformer(), 'resources');
     }
     return $this->errorNotFound();
 }
 public function postNew(Request $request, Resource $resource)
 {
     //
     $input = $request->all();
     $topics = $input['topics'];
     array_forget($input, 'topics');
     foreach ($input as $k => $v) {
         if ($k != "_token" && $k != "submit") {
             $resource->{$k} = $v;
         }
     }
     // return $resource;
     if ($resource->save()) {
         $resource->topics()->sync($topics);
     }
     // return $resource;
     // return var_dump($input);
     // Resource::create("name"=>);
     return redirect()->back();
 }
Example #7
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Library::truncate();
     $dummy = Faker::create();
     $resources = Resource::all()->lists('id')->toArray();
     foreach ($resources as $resource) {
         foreach (range(5, 30) as $index) {
             Library::create(['author' => $dummy->name, 'title' => $dummy->company, 'resource_id' => $resource, 'publication' => $dummy->catchPhrase, 'quantity' => $dummy->randomDigitNotNull, 'is_active' => $dummy->boolean, 'purchased_at' => date('Y-m-d H:i:s')]);
         }
     }
 }
 /**
  * Creates a new lease and returns some basic details about it.
  * Request might also contain optional $_GET['duration'] parameter, otherwise a default value will be used.
  *
  * @param $string
  * @param Request $request
  * @return mixed
  */
 public function lease($string, Request $request)
 {
     $picker = $this->pickResource($string);
     if ($picker['error']) {
         return $this->respondWithError($picker['error']);
     }
     $resource = Resource::find($picker['resourceId']);
     $leaseParams = Lease::stub($resource->id, null, $request->duration);
     $lease = Lease::create($leaseParams);
     $response = ['leased_at' => Carbon::now(), 'links' => ['rel' => 'details', 'uri' => '/leases/' . $lease->uuid]];
     return $this->respond($response, 201);
 }
Example #9
0
 public function finishEvent()
 {
     $resources = DB::table('events_resources')->where('event_id', $this->id)->get();
     foreach ($resources as $resource) {
         $resourceRecord = Resource::find($resource->resource_id);
         if ($resourceRecord) {
             $resourceRecord->backToInventory($resource->amount);
         }
     }
     $this->active = 0;
     $this->save();
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $resource = Resource::find($id);
     // return var_dump($resource);
     $allTopics = Topic::all()->sortBy('name');
     $topics = [];
     foreach ($allTopics as $topic) {
         $topics += [$topic->id => $topic->name];
         if ($resource->topics->has($topic->id)) {
         }
     }
     // return view('resources.edit')->with('resource', $resource);
     return view('admin.resources.edit')->with('resource', $resource)->with('topics', $topics);
 }
Example #11
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     // Add app config values
     config(['app.nonInputFieldTypes' => ['header'], 'app.version' => "v1.0-beta"]);
     Patient::saving(function ($patient) {
         if (Auth::check()) {
             $patient->last_modified_by = Auth::user()->id;
         }
     });
     Resource::creating(function ($resource) {
         if (Auth::check()) {
             $resource->uploaded_by = Auth::user()->id;
         }
     });
 }
 /**
  * Shows a particular resource
  *
  * @param $id
  * @return \Illuminate\View\View
  */
 public function show($id)
 {
     //abort('404');
     //$resource = Resource::find($id);
     // To throw an exception
     //$resource = Resource::findOrFail($id);
     $resource = Resource::find($id);
     if (!$resource) {
         // I think findOPrFail is equivalent
         abort(404);
         # @TODO Check what happens here and compare with the findOrFail
     }
     //dd($resource);
     return view('resources.show', compact('resource'));
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     //
     $latest = Resource::where('approved', '=', true)->orderBy('created_at', 'desc')->take(42)->get();
     $topics = Topic::all()->sortBy('name');
     $wide = false;
     $featured_resources = Resource::getFeatured(5);
     $sidebar_ads['adsense'] = "<script type='text/javascript'>google_ad_client = 'ca-pub-4190828597999315'\\; google_ad_slot = '8479557582'; google_ad_width = 336; google_ad_height = 280;</script><!-- startupwrench-sidebar-top --><script type='text/javascript' src='//pagead2.googlesyndication.com/pagead/show_ads.js'></script>";
     $sidebar_ads['inmotion'] = "<a href='" . url('/go/inmotion') . "'><img src='" . url('/uploads/ih_wordpress-336x280.gif') . "' class='img-responsive'></a>";
     // $side_ads_safe = [$inmotion];
     // $side_ads_all = [$adsense, $inmotion];
     view()->share('latest', $latest);
     view()->share('topics', $topics);
     view()->share('sidebar_ads', $sidebar_ads);
     view()->share('featured_resources', $featured_resources);
 }
Example #14
0
 public function __construct($widget_id)
 {
     // Find or fail widget
     $this->widget = Widget::findOrFail($widget_id);
     $session_id = Session::getId();
     $referrer = filter_var(Request::server('HTTP_REFERER'), FILTER_SANITIZE_URL);
     // Add new resource?
     $this->resource = Resource::firstOrNew(['uri' => $referrer, 'widget_id' => $this->widget->id]);
     $this->resource->uri = $referrer;
     $this->resource->widget_id = $this->widget->id;
     $this->resource->save();
     // Add new visitor?
     $this->visitor = Visitor::firstOrCreate(['session_id' => $session_id]);
     $this->visitor->touch();
     // Add new view?
     $this->view = View::firstOrCreate(['resource_id' => $this->resource->id, 'visitor_id' => $this->visitor->id]);
     $this->view->touch();
 }
Example #15
0
 /**
  * creates a city and the belonging models (BuildingSlot, Resource, HumanResource)
  * saves the city in the map
  *
  * @param User   $user     The user to whom the city belongs
  * @param bool   $capital  Is the city a capital
  * @param int    $hex_id   the id of the hex on which the city is located
  * @param string $name     the name of the city
  */
 public static function create(array $attributes)
 {
     /** @var City $city */
     $city = parent::create($attributes);
     /** @var BuildingSlot $slot */
     $slot = BuildingSlot::create(['city_id' => $city->id]);
     Resource::create(['city_id' => $city->id]);
     HumanResource::create(['city_id' => $city->id]);
     $city->building_slot = $slot->id;
     $city->save();
     /** @var Building $wall */
     $wall = Building::create(['city_id' => $city->id, 'slot' => $slot->id, 'nation' => $attributes['nation'], 'type' => 9, 'finished_at' => Carbon::now()]);
     $slot->wall = $wall->id;
     $slot->save();
     /** @var Grid $hex */
     $hex = Grid::find($hex_id);
     $hex->update(['owner_id' => $attributes['owner'], 'city_id' => $city->id]);
     $hex->setNeighborsOwner($attributes['owner']);
 }
 public function postResources()
 {
     $id = \Input::get('pk');
     $name = \Input::get('name');
     $value = \Input::get('value');
     $resource = Resource::find($id);
     if ($resource->setVal($name, $value)) {
         return \Response::json(['status' => 1]);
     } else {
         return \Response::json(['status' => 0]);
     }
     // $topic = App\Topic::find(\Input::get('pk'));
     // $topic->name = Input::get('value');
     // if($topic->save()){
     //  return Response::json(['status' => 1, 'name' => $topic->name]);
     // } else {
     //  return Response::json(['status' => 0]);
     // }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Resource $resource)
 {
     $resource->delete();
     return redirect()->route('admin.resources.index');
 }
Example #18
0
$app->put('/:resource/:id(/)', function ($resource, $id = null) {
    $resource = \App\Resource::load($resource);
    if ($resource === null) {
        \App\Resource::response(\App\Resource::STATUS_NOT_FOUND);
    } else {
        $resource->put($id);
    }
});
// Delete
$app->delete('/:resource/:id(/)', function ($resource, $id = null) {
    $resource = \App\Resource::load($resource);
    if ($resource === null) {
        \App\Resource::response(\App\Resource::STATUS_NOT_FOUND);
    } else {
        $resource->delete($id);
    }
});
// Options
$app->options('/:resource(/)', function ($resource, $id = null) {
    $resource = \App\Resource::load($resource);
    if ($resource === null) {
        \App\Resource::response(\App\Resource::STATUS_NOT_FOUND);
    } else {
        $resource->options();
    }
});
// Not found
$app->notFound(function () {
    \App\Resource::response(\App\Resource::STATUS_NOT_FOUND);
});
$app->run();
Example #19
0
 public function getAll()
 {
     $resources = Resource::with('category')->with('user')->with('city')->paginate(5);
     return View::make('backend.pages.resource-all')->withResources($resources);
 }
Example #20
0
 public function payForUnits($unitsToBuy, $army, $city)
 {
     $prices = ResourceController::getPricesForUnits($army->units, $city);
     $unitsToBuy = $this->getBuyCount($army->units, $unitsToBuy);
     foreach ($prices as $price) {
         foreach ($unitsToBuy as $unit) {
             if ($price['id'] == $unit['resource_id']) {
                 $price->multiplyResource($unit['countToBuy']);
             }
         }
     }
     $resource = Resource::find($city->resource->id);
     $resource->substractResourceArray($prices);
     $resource->save();
 }
 public static function getPricesForBuildings($buildings, $city)
 {
     $basePrices = array();
     foreach ($buildings as $building) {
         array_push($basePrices, $building->resource_id);
     }
     $basePrices = \App\Resource::whereIn('Id', $basePrices)->get();
     return \App\CityEffectApplier::modifyBuildingPricesByCity($basePrices, $city);
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Event::created(function ($event) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha registrado el evento id: ' . $event->id;
         Logger::create(['message' => $message]);
     });
     Event::updating(function ($event) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha actualizado el evento id: ' . $event->id;
         Logger::create(['message' => $message]);
     });
     Event::deleting(function ($event) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha eliminado el evento id: ' . $event->id;
         Logger::create(['message' => $message]);
     });
     Member::created(function ($member) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha registrado al miembro id: ' . $member->id;
         Logger::create(['message' => $message]);
     });
     Member::updating(function ($member) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha actualizado al miembro id: ' . $member->id;
         Logger::create(['message' => $message]);
     });
     Member::deleting(function ($member) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha eliminado al miembro id: ' . $member->id;
         Logger::create(['message' => $message]);
     });
     Resource::created(function ($resource) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha registrado el recurso id: ' . $resource->id;
         Logger::create(['message' => $message]);
     });
     Resource::updating(function ($resource) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha actualizado el recurso id: ' . $resource->id;
         Logger::create(['message' => $message]);
     });
     Resource::deleting(function ($resource) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha eliminado el recurso id: ' . $resource->id;
         Logger::create(['message' => $message]);
     });
     User::created(function ($user) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha registrado al usuario id: ' . $user->id;
         Logger::create(['message' => $message]);
     });
     User::updating(function ($user) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha actualizado al usuario id: ' . $user->id;
         Logger::create(['message' => $message]);
     });
     User::deleting(function ($user) {
         $user = Auth::user();
         $message = 'El usuario ' . $user->name . ' ha eliminado al usuario id: ' . $user->id;
         Logger::create(['message' => $message]);
     });
 }
 /**
  * Attach the resource categories, tags and misc
  * variables to the necessary views.
  */
 private function attachResourceFields()
 {
     View::composer('resources._form', function ($view) {
         $view->with(['categories' => ResourceCategory::orderBy('name', 'ASC')->lists('name', 'id'), 'tags' => ResourceTag::orderBy('name', 'ASC')->lists('name', 'id'), 'access' => Resource::getAccessList()]);
     });
     View::composer(['resources.index', 'resources.list', 'resources.partials.search_inputs'], function ($view) {
         $categories = ResourceCategory::orderBy('name', 'ASC')->get();
         $tags = ResourceTag::orderBy('name', 'ASC')->get();
         $view->with(['all_categories' => $categories, 'all_tags' => $tags]);
     });
 }
 /**
  * @param $id
  * @return mixed
  */
 private function getResourceWithAccess($id)
 {
     // Get the resource
     $resource = Resource::findOrFail($id);
     // Check the access priviledges
     if (!$resource->canAccess($this->user)) {
         App::abort(403);
         return $resource;
     }
     // Check the source is accessible
     if ($resource->isFile() && !file_exists($resource->getFilePath())) {
         App::abort(404);
     }
     return $resource;
 }
 public function seedResources()
 {
     Resource::create(['name' => 'Sala riunioni']);
     Resource::create(['name' => 'Coworking']);
 }
Example #26
0
 /**
  * Handles interaction with file resources
  *
  * @return \Illuminate\Http\Response
  */
 public function resources(Request $request, $method)
 {
     switch ($method) {
         case 'upload':
             $i = 0;
             $files = array();
             $message = array();
             while ($request->has('file-' . $i)) {
                 $key = time() . "-" . mt_rand();
                 $inputName = 'file-' . $i;
                 $files[$key] = $request->input($inputName);
                 $i++;
             }
             foreach ($files as $fileKey => $fileData) {
                 $splitTypeAndBase64 = explode(";", $fileData);
                 \Log::debug($splitTypeAndBase64);
                 $dataType = explode(":", $splitTypeAndBase64[0]);
                 $splitType = explode("/", $dataType[1]);
                 $base64 = explode(",", $splitTypeAndBase64[1]);
                 $base64 = $base64[1];
                 $resource = new Resource();
                 $resource->type = $dataType[1];
                 $resource->base64 = $base64;
                 $resource->save();
                 $message[$resource->id] = array("type" => $resource->type, "data" => $splitType[0] == "image" ? $this->constructBase64File($resource) : null);
             }
             return response()->json(["status" => "success", "message" => $message]);
             break;
         case "fetch":
             if ($request->has('id')) {
                 $resource = Resource::where('id', $request->id);
                 if ($resource->count() > 0) {
                     $resource = $resource->first(["id", "type", "base64"]);
                     return response()->json(["status" => "success", "type" => $resource->type, "base64" => $this->constructBase64File($resource)]);
                 }
             } else {
                 return response()->json(["status" => "failure", "message" => "Missing ID parameter."]);
             }
             break;
         default:
             return response()->json(["status" => "failure", "message" => "Unknown method"]);
             break;
     }
 }
 /**
  * Show the form for editing the specified reservation.
  *
  * @param  Reservation  $reservation
  * @return Response
  */
 public function edit(Reservation $reservation)
 {
     $users = User::lists('name', 'id');
     $resources = Resource::lists('name', 'id');
     return view('admin.reservations.edit', compact('reservation', 'users', 'resources'));
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit(Role $role)
 {
     $users = User::all();
     $resources = Resource::all();
     return view('roles.edit', compact('role', 'users', 'resources'));
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     //
     $latest = \App\Resource::all()->sortByDesc('created_at')->take(42);
     view()->share('latest', $latest);
 }
 public function destroy($id)
 {
     if (!Auth::check()) {
         return response()->json($this->notLoginJson, 401);
     } else {
         $user = Auth::user();
         if (!$user->hasRole('admin')) {
             return response()->json($this->needPermissionsJson, 401);
         }
     }
     $resource = Resource::find($id);
     if ($resource) {
         $resource->delete();
         return response()->json(['message' => 'Recurso ha sido eliminado']);
     } else {
         return response()->json($this->resourceNotFound, 404);
     }
 }