public function put($data, $id) { $obj = Package::find($id); if ($obj == null) { $obj = new Package(); } if (@isset($data['package_id']) && $data['package_id'] != null) { $obj->package_id = Crypt::encrypt(str_pad(trim($data['package_id']), 4, $this->blankSpace, STR_PAD_RIGHT)); } if (@isset($data['source']) && $data['source'] != null) { $obj->source = Crypt::encrypt(str_pad(trim($data['source']), 15, $this->blankSpace, STR_PAD_RIGHT)); } if (@isset($data['destination']) && $data['destination'] != null) { $obj->destination = Crypt::encrypt(str_pad(trim($data['destination']), 15, $this->blankSpace, STR_PAD_RIGHT)); } if (@isset($data['port']) && $data['port'] != null) { $obj->port = Crypt::encrypt(str_pad(trim($data['port']), 4, $this->blankSpace, STR_PAD_RIGHT)); } if (@isset($data['protocol']) && $data['protocol'] != null) { $obj->protocol = Crypt::encrypt(str_pad(trim($data['protocol']), 4, $this->blankSpace, STR_PAD_RIGHT)); } if (@isset($data['data']) && $data['data'] != null) { $obj->data = Crypt::encrypt(str_pad(trim($data['data']), 50, $this->blankSpace, STR_PAD_RIGHT)); } return $obj; }
/** * @param PackageCourseRequest $request * @return \Illuminate\Http\JsonResponse */ public function store(PackageCourseRequest $request) { $package = Package::find($request->get('package_id')); $inputs = $request->except(['package_id', '_token', '_method']); $packageCourses = $package->courses()->save(new PackageCourse($inputs)); return response()->json(['message' => 'Successfully Save!', 'data' => $packageCourses]); }
/** * Save the associated image for the package. * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function media(Request $request) { $package = Package::find($request->get('package_id')); $file = $request->file('file'); $name = time() . $file->getClientOriginalName(); $path = "/packages/" . $package->id . "/photos/{$name}"; $file->move('packages/' . $package->id . "/photos", $name); if ($package->photo()->count()) { $package->photo()->update(['path' => $path]); } else { $package->photo()->create(['path' => $path]); } return response()->json(['message' => 'Successfully Uploaded', 'file_path' => $path]); }
/** * Seeks for followers, activated by a package. * * @param Request $request * @return \Illuminate\Http\Response */ public function seekFollower(Request $request) { $user = User::find(User::getCurrentUserId()); //Check if the user is already under a campaign if ($user->followers_left > 0) { return response()->json(['success' => false, 'message' => "Already under one campaign. Finish current campaign, then add credit."]); } $rules = ['package_id' => 'exists:packages,id']; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return response()->json(['success' => false, 'message' => "Failed", 'error' => $validator->errors()->all()]); } //Check if the package is a Follow package. if (!Package::find($request->get('package_id'))->isFollowPackage()) { return response()->json(['success' => false, 'message' => "Not a valid package. Use a Follow Package"]); } $package = Package::find($request->package_id); //decrease credit if (User::find(User::getCurrentUserId())->decreaseCredit($package->cost)) { //Add number of followers left $user->followers_left = $package->return; $user->show_to = $request->get('show_to'); $user->save(); return response()->json(['success' => true, 'message' => "Successfully added number of requested followers", 'user' => User::find(User::getCurrentUserId())]); } else { return response()->json(['success' => false, 'message' => "Failed. Not enough credit"]); } }
public function create($request) { /** * ACS requires the following for deployVirtualMachine(): * serviceofferingid * templateid * zoneid * account * domainid * name * keypair (if needed) * rootdisksize (if allowed) * hypervisor (if specifying rootdisksize) */ $instanceData = []; // Get site configuration. We're looking for hypervisor, rootdiskresize, and domainId. $cfg = SiteConfig::all()->makeKVArray(); // Did we receive a package or a custom configuration? if (isset($request['package'])) { $pkg = Package::find($request['package']); $instanceData['serviceofferingid'] = $this->findServiceOffering(['cpu' => $pkg->cpu_number, 'memory' => $pkg->ram, 'diskType' => $pkg->diskType->tags]); } else { $instanceData['serviceofferingid'] = $this->findServiceOffering(['cpu' => $request->coreSlider, 'memory' => $request->ramSlider * 1024, 'diskType' => $request->diskType]); } // If we can't find a service offering, error out. if (empty($instanceData['serviceofferingid'])) { abort(500); } if (isset($request->myTemplate)) { // Template is one created by the user. $instanceData['templateid'] = $request->myTemplate; } else { // Find the template we need. $templateGroup = TemplateGroup::find($request['template']); if ('FALSE' == $cfg['rootdiskresize']) { // Size can come from a package or a custom size slider. $disk_size = isset($request['package']) ? $pkg->disk_size : stristr($request['hdSlider'], ' ', true); // Find the specific size of template $templateGroup->templates->each(function ($tpl) use($disk_size, &$instanceData) { if ($tpl->size == $disk_size) { $instanceData['templateid'] = $tpl->template_id; } }); } else { if ('TRUE' == $cfg['rootdiskresize']) { // We don't care about template size. We resize whatever we need. // Grab the template ID of the first (only) template in the group. $instanceData['templateid'] = $templateGroup->templates->first()->template_id; // If we have a package get the disk size from there. If not we have a custom size. $instanceData['rootdisksize'] = isset($request['package']) ? $pkg->disk_size : $request['disk_size']; // We also need to set the hypervisor type. $instanceData['hypervisor'] = $cfg['hypervisor']; } } } // Error out if we don't find a template if (empty($instanceData['templateid'])) { abort(500); } // Get the user object $user = Auth::User(); // Add a network interface to the system $networks = $this->acs->listNetworks(['canusefordeploy' => 'true', 'account' => $user->email, 'domainid' => $cfg['domainId']]); // !!REVISE!! $instanceData['networkids'] = $networks[0]->id; // Select a security group for the instance $instanceData['securitygroupids'] = $request->secGroup; // Name the new instance $instanceData['name'] = $request['name']; // Add user data to the request $instanceData['account'] = $user->email; $instanceData['domainid'] = $cfg['domainId']; // What zone is being deployed to? $instanceData['zoneid'] = $request['zone']; // Do we need to add a keypair to the system? if (isset($request['keypair'])) { $instanceData['keypair'] = $request['keypair']; } return $this->acs->deployVirtualMachine($instanceData); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id, $token) { try { // remove static keyword from token $token = str_replace('mlm', '', $token); $token = str_replace('ppa', '', $token); $id = str_replace($token, '', $id); $package = Package::find($id); $package->status = '0'; $package->save(); return Redirect::to('admin/package')->with('flush_message', 'Package deleted!'); } catch (Exception $e) { return Redirect::to('admin/package')->with('flush_message', 'There is an error in application'); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { try { if (intval($id) > 0) { $data = Package::find($id); if ($data != null) { $data->delete(); return redirect('packages'); } } return redirect('packages/create')->withErrors('Could not delete the package:' . $id)->withInput(); } catch (\Exception $e) { return $e->getMessage(); } }
protected function createMedia(array $data) { $package = Package::find($data['package_id']); return Media::create(['url' => $data['url'], 'show_to' => $data['show_to'], 'user_id' => User::getCurrentUserId(), 'likes_left' => $package->return]); }
/** * Show the form for editing the specified resource. * * @param $Notification * @return Response */ public function getEdit($id) { $notification = Notification::find($id); $package = Package::find($notification->package_id)->first(); return view('admin.notifications.create_edit', compact('notification', 'package')); }