<commit_before><?php

namespace ErenMustafaOzdal\LaravelProductModule\Http\Controllers;

use App\Http\Requests;
use App\Product;
use Laracasts\Flash\Flash;

use ErenMustafaOzdal\LaravelModulesBase\Controllers\BaseController;
// events
use ErenMustafaOzdal\LaravelProductModule\Events\Product\StoreSuccess;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\StoreFail;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\UpdateSuccess;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\UpdateFail;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\DestroySuccess;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\DestroyFail;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\PublishSuccess;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\PublishFail;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\NotPublishSuccess;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\NotPublishFail;
// requests
use ErenMustafaOzdal\LaravelProductModule\Http\Requests\Product\StoreRequest;
use ErenMustafaOzdal\LaravelProductModule\Http\Requests\Product\UpdateRequest;

class ProductController extends BaseController
{
    /**
     * default relation datas
     *
     * @var array
     */
    private $relations = [
        'descriptions' => [
            'relation_type'     => 'hasMany',
            'relation'          => 'descriptions',
            'relation_model'    => '\App\ProductDescription',
            'is_reset'          => true,
            'datas'             => null
        ]
    ];

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view(config('laravel-product-module.views.product.index'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $operation = 'create';
        return view(config('laravel-product-module.views.product.create'), compact('operation'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  StoreRequest  $request
     * @return \Illuminate\Http\Response
     */
    public function store(StoreRequest $request)
    {
        return $this->baseStoreModel($request);
    }

    /**
     * Display the specified resource.
     *
     * @param Product $product
     * @return \Illuminate\Http\Response
     */
    public function show($product)
    {
        return view(config('laravel-product-module.views.product.show'), compact('product'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param Product $product
     * @return \Illuminate\Http\Response
     */
    public function edit($product)
    {
        $operation = 'edit';
        return view(config('laravel-product-module.views.product.edit'), compact('product','operation'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  UpdateRequest  $request
     * @param Product $product
     * @return \Illuminate\Http\Response
     */
    public function update(UpdateRequest $request, $product)
    {
        $this->setToFileOptions($request, ['photos.photo' => 'multiple_photo']);
        $this->setEvents([
            'success'   => UpdateSuccess::class,
            'fail'      => UpdateFail::class
        ]);
        $relation = [];
        if ($request->has('group-description')) {
            $this->relations['descriptions']['datas'] = collect($request->get('group-description'))->reject(function($item)
            {
                return $item['description_title'] == '' || $item['description_description'] == '';
            })->map(function($item,$key)
            {
                $item['title'] = $item['description_title'];
                unsetReturn($item,'description_title');
                $item['description'] = $item['description_description'];
                unsetReturn($item,'description_description');
                $item['is_publish'] = !isset($item['description_is_publish']) || !$item['description_is_publish'] ? 0 : 1;
                unsetReturn($item,'description_is_publish');
                return $item;
            });
            $relation[] = $this->relations['descriptions'];
        }
        $this->setOperationRelation($relation);
        return $this->updateModel($product,'show', true);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param Product $product
     * @return \Illuminate\Http\Response
     */
    public function destroy($product)
    {
        $this->setEvents([<commit_msg>firma<commit_after><?php

namespace ErenMustafaOzdal\LaravelProductModule\Http\Controllers;

use App\Http\Requests;
use App\Product;
use Laracasts\Flash\Flash;

use ErenMustafaOzdal\LaravelModulesBase\Controllers\BaseController;
// events
use ErenMustafaOzdal\LaravelProductModule\Events\Product\StoreSuccess;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\StoreFail;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\UpdateSuccess;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\UpdateFail;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\DestroySuccess;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\DestroyFail;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\PublishSuccess;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\PublishFail;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\NotPublishSuccess;
use ErenMustafaOzdal\LaravelProductModule\Events\Product\NotPublishFail;
// requests
use ErenMustafaOzdal\LaravelProductModule\Http\Requests\Product\StoreRequest;
use ErenMustafaOzdal\LaravelProductModule\Http\Requests\Product\UpdateRequest;

class ProductController extends BaseController
{
    /**
     * default relation datas
     *
     * @var array
     */
    private $relations = [
        'descriptions' => [
            'relation_type'     => 'hasMany',
            'relation'          => 'descriptions',
            'relation_model'    => '\App\ProductDescription',
            'is_reset'          => true,
            'datas'             => null
        ]
    ];

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view(config('laravel-product-module.views.product.index'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $operation = 'create';
        return view(config('laravel-product-module.views.product.create'), compact('operation'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  StoreRequest  $request
     * @return \Illuminate\Http\Response
     */
    public function store(StoreRequest $request)
    {
        return $this->baseStoreModel($request);
    }

    /**
     * Display the specified resource.
     *
     * @param Product $product
     * @return \Illuminate\Http\Response
     */
    public function show($product)
    {
        return view(config('laravel-product-module.views.product.show'), compact('product'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param Product $product
     * @return \Illuminate\Http\Response
     */
    public function edit($product)
    {
        $operation = 'edit';
        return view(config('laravel-product-module.views.product.edit'), compact('product','operation'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  UpdateRequest  $request
     * @param Product $product
     * @return \Illuminate\Http\Response
     */
    public function update(UpdateRequest $request, $product)
    {
        $this->setToFileOptions($request, ['photos.photo' => 'multiple_photo']);
        $this->setEvents([
            'success'   => UpdateSuccess::class,
            'fail'      => UpdateFail::class
        ]);

        // önce eski açıklamalar silinir
        dd($request->all());
        $relation = [];
        if ($request->has('group-description')) {
            $this->relations['descriptions']['datas'] = collect($request->get('group-description'))->reject(function($item)
            {
                return $item['description_title'] == '' || $item['description_description'] == '';
            })->map(function($item,$key)
            {
                $item['title'] = $item['description_title'];
                unsetReturn($item,'description_title');
                $item['description'] = $item['description_description'];
                unsetReturn($item,'description_description');
                $item['is_publish'] = !isset($item['description_is_publish']) || !$item['description_is_publish'] ? 0 : 1;
                unsetReturn($item,'description_is_publish');
                return $item;
            });
            $relation[] = $this->relations['descriptions'];
        }
        $this->setOperationRelation($relation);
        return $this->updateModel($product,'show', true);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param Product $product
     * @return \Illuminate\Http\Response
     */
    public function destroy($product)
    {
        $this->setEvents([
{'fraction_non_alphanumeric': 0.12736, 'fraction_numerical': 0.00042666666666666667, 'mean_word_length': 2.6927924379677037, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3821445', 'n_tokens_mistral': 2669, 'n_tokens_neox': 2577, 'n_words': 434}