Inheritance: extends Illuminate\Database\Eloquent\Model
示例#1
0
 public function edit(Product $product)
 {
     //GENERAL
     $textures = Texture::with("colours")->get();
     $categories = [];
     foreach (MainCategory::with('sub_categories')->get() as $val) {
         array_push($categories, $val);
     }
     $colours = ProductColour::all();
     $colourArray = [];
     foreach ($colours as $colour) {
         $colourArray[] = "'" . $colour->code . "'";
     }
     //
     $detail_preview_img = ProductPhoto::where("product_id", "=", $product->id)->where("is_preview", "=", 1)->first();
     $tmp_array = [];
     $colour_photos = ProductPhoto::where("product_id", "=", $product->id)->where("is_colour_img", "=", 1)->get();
     foreach ($colour_photos as $item) {
         $pivot = DB::table('photos_colours')->where("photo_id", "=", $item->id)->first();
         $item->colour = ProductColour::find($pivot->colour_id);
         $tmp_array[] = $item;
     }
     $product->colour_images = $tmp_array;
     $edit_textures = DB::table('product_textures')->where("product_id", "=", $product->id)->get();
     $textures_edit_array = [];
     foreach ($edit_textures as $item) {
         $result = Texture::with("colours")->where("id", "=", $item->texture_id)->get();
         $textures_edit_array[] = $result;
     }
     $preview_images = ProductPhoto::where("product_id", "=", $product->id)->where("is_detail_preview", "=", 1)->get();
     $product->sub_categories;
     //        $product["textures"] = $product->product_textures()->get();
     return view('cms/product/product/edit')->with(array('item' => $product, "categories" => $categories, "textures" => $textures, "colours" => $colourArray, "rawColours" => json_encode($colours), "detail_preview_img" => $detail_preview_img, "preview_images" => $preview_images, "edit_textures" => $textures_edit_array));
 }
示例#2
0
 /**
  * Get specific texture of player.
  *
  * @param  string $type steve|alex|cape
  * @return string       Sha256-hash of texture file.
  */
 public function getTexture($type)
 {
     if ($type == "skin") {
         $type = $this->getPreference() == "default" ? "steve" : "alex";
     }
     if (in_array($type, self::$models)) {
         return Texture::find($this["tid_{$type}"])['hash'];
     }
     return false;
 }
 public function remove(Request $request)
 {
     $this->validate($request, ['tid' => 'required|integer']);
     if ($this->closet->remove($request->tid)) {
         $t = Texture::find($request->tid);
         $t->likes = $t->likes - 1;
         $t->save();
         return json(trans('user.closet.remove.success'), 0);
     } else {
         return json(trans('user.closet.remove.non-existent'), 0);
     }
 }
示例#4
0
 public function detail(Product $product)
 {
     $breadcrumbs = [["name" => "home", "url" => "/"], ["name" => "producten", "url" => "/producten"], ["name" => $product->title, "url" => "/producten/" . $product->id]];
     $detail_preview_photos = DB::table('product_photos')->where("product_id", "=", $product->id)->where("is_detail_preview", "=", 1)->get();
     //if product has preview photos, show first preview photo on initial load. Else show colour images
     if (count($detail_preview_photos) > 0) {
         $product->colour_img = $detail_preview_photos[0];
     } else {
         $firstColourImg = DB::table('product_photos')->where("product_id", "=", $product->id)->where("is_colour_img", "=", 1)->first();
         //COLOUR IMAGE
         if ($firstColourImg) {
             $privot_photo_colour_first = DB::table('photos_colours')->where("photo_id", "=", $firstColourImg->id)->first();
             $product->colour_img = $firstColourImg;
             $firstColour = ProductColour::find($privot_photo_colour_first->colour_id);
             $product->colour = $firstColour;
             //TEXTURE
             $textures = DB::table('textures')->where("colour_id", "=", $firstColour->id)->get();
             if ($textures) {
                 foreach ($textures as $texture) {
                     $tmp = DB::table('product_textures')->where("product_id", "=", $product->id)->where('texture_id', '=', $texture->id)->get();
                     if ($tmp) {
                         $product->texture = Texture::find($tmp[0]->texture_id);
                         break;
                     }
                 }
             }
         }
     }
     if ($detail_preview_photos) {
         $product->detail_preview_photos = $detail_preview_photos;
     }
     //get all available colours for this product through colour images
     $available_colours_array = [];
     $colourImagesOfProduct = DB::table('product_photos')->where("product_id", "=", $product->id)->where("is_colour_img", "=", 1)->get();
     foreach ($colourImagesOfProduct as $colourImage) {
         $privot_photo_colour_first = DB::table('photos_colours')->where("photo_id", "=", $colourImage->id)->first();
         $colour = ProductColour::find($privot_photo_colour_first->colour_id);
         $available_colours_array[] = $colour;
     }
     //all font colour
     $font_colours = ["#252b5a", "#293477", "#3f509e", "#4a69b1", "#273575", "#262d5f", "#191b36", "#f18515", "#f49919", "#fab432", "#f2a202", "#b96b15", "#c49209", "#d1870c", "#fcc72f", "#edd48c", "#fdc50a", "#ffda10", "#fae514", "#aa8b12", "#433014", "#671725", "#c53c3d", "#f08176", "#f4a3ac", "#d1312f", "#ed6f24", "#9a2417", "#032f2d", "#1d411d", "#95c15f", "#275c29", "#498331", "#0f754b", "#5fb87f", "#1d4b4e", "#8cc9ba", "#0a8880", "#319abb", "#2680a2", "#8fb6e2", "#c83256", "#eb5a6a", "#c83159", "#ea5093", "#ef7fa1", "#ef81a4", "#932162", "#65236a", "#b596c6", "#7b4594", "#6c2477", "#412b86", "#322873", "#777dbb", "#8e70a6", "#767cbb", "#431d4b", "#27170d", "#8c6215", "c8b26f", "#422529", "#aa9796", "#c0b9b5", "#75463d", "#6b3e46", "#999083", "#e3a365", "#973d15", "#492911", "#dddccf", "#dbdbda", "#989799", "#1d1d1b"];
     return view('products/detail')->with(array("product" => $product, "breadcrumbs" => $breadcrumbs, "available_colours" => $available_colours_array, "font_colours" => $font_colours));
 }
示例#5
0
 /**
  * Check if given tid is valid.
  *
  * @param  int $tid
  * @return bool
  */
 private function checkTextureExist($tid)
 {
     return !Texture::where('tid', $tid)->isEmpty();
 }
 public function raw($tid)
 {
     if ($t = Texture::find($tid)) {
         if (Storage::disk('textures')->has($t->hash)) {
             return Response::png(Storage::disk('textures')->get($t->hash));
         } else {
             abort(404, '请求的材质文件已经被删除');
         }
     } else {
         abort(404, '材质不存在');
     }
 }
 /**
  * A wrapper of Player::setTexture()
  */
 public function setTexture(Request $request)
 {
     foreach ($request->input('tid') as $key => $value) {
         if (!($texture = Texture::find($value))) {
             return json(trans('skinlib.un-existent'), 6);
         }
         $field_name = "tid_{$texture->type}";
         $this->player->setTexture([$field_name => $value]);
     }
     return json(trans('user.player.set.success', ['name' => $this->player->player_name]), 0);
 }
 /**
  * Set Avatar for User
  *
  * @param Request $request
  */
 public function setAvatar(Request $request)
 {
     $this->validate($request, ['tid' => 'required|integer']);
     $result = Texture::find($request->input('tid'));
     if ($result) {
         if ($result->type == "cape") {
             return json(trans('user.profile.avatar.wrong-type'), 1);
         }
         if ($this->user->setAvatar($request->input('tid'))) {
             return json(trans('user.profile.avatar.success'), 0);
         }
     } else {
         return json(trans('user.profile.avatar.non-existent'), 1);
     }
 }
示例#9
0
 public function delete(Texture $product)
 {
     $product->delete();
     return redirect('/cms/texture');
 }
 /**
  * Handle ajax request from /admin/players
  */
 public function playerAjaxHandler(Request $request, UserRepository $users)
 {
     $action = isset($_GET['action']) ? $_GET['action'] : "";
     $player = Player::find($request->input('pid'));
     if (!$player) {
         abort(404, trans('general.unexistent-player'));
     }
     if ($action == "preference") {
         $this->validate($request, ['preference' => 'required|preference']);
         if ($player->setPreference($request->input('preference'))) {
             return json('角色 ' . $player->player_name . ' 的优先模型已更改至 ' . $request->input('preference'), 0);
         }
     } elseif ($action == "texture") {
         $this->validate($request, ['model' => 'required|model', 'tid' => 'required|integer']);
         if (!Texture::find($request->tid)) {
             return json("材质 tid.{$request->tid} 不存在", 1);
         }
         if ($player->setTexture(['tid_' . $request->model => $request->tid])) {
             return json("角色 {$player->player_name} 的材质修改成功", 0);
         }
     } elseif ($action == "owner") {
         $this->validate($request, ['pid' => 'required|integer', 'uid' => 'required|integer']);
         $user = $users->get($request->input('uid'));
         if (!$user) {
             return json('不存在的用户', 1);
         }
         if ($player->setOwner($request->input('uid'))) {
             return json("角色 {$player->player_name} 已成功让渡至 " . $user->getNickName(), 0);
         }
     } elseif ($action == "delete") {
         if ($player->delete()) {
             return json('角色已被成功删除', 0);
         }
     } else {
         return json('非法参数', 1);
     }
 }
 public function rename(Request $request)
 {
     $this->validate($request, ['tid' => 'required|integer', 'new_name' => 'required|no_special_chars']);
     $t = Texture::find($request->input('tid'));
     if (!$t) {
         return json(trans('skinlib.non-existent'), 1);
     }
     if ($t->uploader != $this->user->uid && !$this->user->isAdmin()) {
         return json(trans('skinlib.no-permission'), 1);
     }
     $t->name = $request->input('new_name');
     if ($t->save()) {
         return json(trans('skinlib.rename.success', ['name' => $request->input('new_name')]), 0);
     }
 }
示例#12
0
 public function colours()
 {
     $response = "";
     $colour_id = Input::get("colour_id");
     $product_id = Input::get("product_id");
     //GET COLOUR IMAGE
     $colour_images = DB::table('product_photos')->where("product_id", "=", $product_id)->where("is_colour_img", "=", 1)->get();
     $colour_image_result = false;
     foreach ($colour_images as $colour_image) {
         $result = DB::table('photos_colours')->where("photo_id", "=", $colour_image->id)->where("colour_id", "=", $colour_id)->first();
         if ($result) {
             $colour_image_result = DB::table('product_photos')->where("id", "=", $result->photo_id)->first();
             break;
         }
     }
     $response["colour_image"] = $colour_image_result;
     //GET TEXTURE
     $textures = DB::table('textures')->where("colour_id", "=", $colour_id)->get();
     $texture_result = false;
     if ($textures) {
         foreach ($textures as $texture) {
             $tmp = DB::table('product_textures')->where("product_id", "=", $product_id)->where('texture_id', '=', $texture->id)->get();
             if ($tmp) {
                 $texture_result = Texture::find($tmp[0]->texture_id);
                 break;
             }
         }
     }
     $response["texture"] = $texture_result;
     return $response;
 }