<commit_before><?php
namespace App\Http\Controllers\Admin;

use App\Models\Busi\Customer;
use App\Models\Busi\Store;
use App\Models\Busi\VisitStoreTodo;
use App\Services\VisitCalendarService;
use Illuminate\Http\Request;
use App\Http\Controllers\Admin\AdminController;
use App\Models\Busi\VisitTodoGroup;

class VisitTodoGroupController extends AdminController
{
    public function newEntity(array $attributes = [])
    {
        // TODO: Implement newEntity() method.
        return new VisitTodoGroup($attributes);
    }

    /**
     * Display a listing of the resource.
     *
     * @return  \Illuminate\Http\Response
     */
    public function index()
    {
        $customers = Customer::all();
        return view('admin.visit-todo-group.index', compact('customers'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return  \Illuminate\Http\Response
     */
    public function create()
    {
        return view('admin.visit-todo-group.create');
    }

    /**
     * Display the specified resource.
     *
     * @param    int $id
     * @return  \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $entity = VisitTodoGroup::find($id);
        return view('admin.visit-todo-group.edit', ['entity' => $entity]);
    }

    /**
     * Display the specified resource.
     *
     * @param    int $id
     * @return  \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    public function store(Request $request, $extraFields = [])
    {
        $data = $data = $request->input('data', []);
        $props = $this->beforeSave(current($data));
        $is_default = $props['fis_default'];
        if ($is_default==1){
            VisitTodoGroup::query()->where('fis_default',1)->update([
                'fis_default' => 0
            ]);
        }
        return parent::store($request, $extraFields); // TODO: Change the autogenerated stub
    }

    public function update(Request $request, $id, $extraFields = [])
    {
        $data = $data = $request->input('data', []);
        $props = $this->beforeSave(current($data));
        $is_default = $props['fis_default'];
        if ($is_default==1){
            VisitTodoGroup::query()->where('fis_default',1)->update([
                'fis_default' => 0
            ]);
        }
        return parent::update($request, $id, $extraFields); // TODO: Change the autogenerated stub
    }

    /**
     * @param  Request $request
     * @param  array $searchCols
     * @param  array $with
     * @param  null $conditionCall
     * @param  bool $all_columns
     * @return  \Illuminate\Http\JsonResponse
     */
    public function pagination(Request $request, $searchCols = [], $with = [], $conditionCall = null, $all_columns = false)
    {
        $searchCols = ["fdocument_status", "fname", "fremark"];
        return parent::pagination($request, $searchCols);
    }

    public function todoGroupTree(Request $request)
    {

        $todoGroup = VisitTodoGroup::find($request->input('id'));
        if (empty($todoGroup))
            return response()->json([]);
        $all = $todoGroup->todos->where('fparent_id', 0);
        $tree = [];
        foreach ($all as $top)
            $tree[] = $this->toBootstrapTreeViewData1($top, ['text' => 'fname', 'dataid' => 'id'], false, $todoGroup->todos->pluck('id')->toArray());
//        $tree['state'] = ['expanded' => true];
        return response()->json($tree);
    }

    public function toBootstrapTreeViewData1($entity, $props, $expanded = true, $todoids)
    {
        $data = ['item' => $entity];
        if (!empty($entity)) {
            foreach ($props as $k => $val) {

                $data[$k] = $entity->{$val};
                $data['state']['expanded'] = $expanded;

            }

            if (!empty($entity->children)) {
                $nodes = [];
                foreach ($entity->children as $child) {
                    if (in_array($child->id, $todoids)) {
                        $nodes[] = $this->toBootstrapTreeViewData($child, $props, $expanded);
                    }
                }
                if (!empty($nodes))
                    $data['nodes'] = $nodes;

            }
        }
        return $data;
    }

    public function config()
    {
        $customers = Customer::all();
        $groups = VisitTodoGroup::all()->where('fstart_date', '>', date("Y-m-d"));

        return view('admin.visit-todo-group.config', compact('customers', 'groups'));
    }

    public function addTodo(Request $request)
    {
        $data = $request->all();<commit_msg>bug fix<commit_after><?php
namespace App\Http\Controllers\Admin;

use App\Models\Busi\Customer;
use App\Models\Busi\Store;
use App\Models\Busi\VisitStoreTodo;
use App\Services\VisitCalendarService;
use Illuminate\Http\Request;
use App\Http\Controllers\Admin\AdminController;
use App\Models\Busi\VisitTodoGroup;

class VisitTodoGroupController extends AdminController
{
    public function newEntity(array $attributes = [])
    {
        // TODO: Implement newEntity() method.
        return new VisitTodoGroup($attributes);
    }

    /**
     * Display a listing of the resource.
     *
     * @return  \Illuminate\Http\Response
     */
    public function index()
    {
        $customers = Customer::all();
        return view('admin.visit-todo-group.index', compact('customers'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return  \Illuminate\Http\Response
     */
    public function create()
    {
        return view('admin.visit-todo-group.create');
    }

    /**
     * Display the specified resource.
     *
     * @param    int $id
     * @return  \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $entity = VisitTodoGroup::find($id);
        return view('admin.visit-todo-group.edit', ['entity' => $entity]);
    }

    /**
     * Display the specified resource.
     *
     * @param    int $id
     * @return  \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    public function store(Request $request, $extraFields = [])
    {
        $data = $data = $request->input('data', []);
        $props = $this->beforeSave(current($data));
        $is_default = $props['fis_default'];
        if ($is_default==1){
            VisitTodoGroup::query()->where('fis_default',1)->update([
                'fis_default' => 0
            ]);
        }
        return parent::store($request, $extraFields); // TODO: Change the autogenerated stub
    }

    public function update(Request $request, $id, $extraFields = [])
    {
        $data = $data = $request->input('data', []);
        $props = $this->beforeSave(current($data));
        $is_default = $props['fis_default'];
        if ($is_default==1){
            VisitTodoGroup::query()->where('fis_default',1)->update([
                'fis_default' => 0
            ]);
        }
        return parent::update($request, $id, $extraFields); // TODO: Change the autogenerated stub
    }

    /**
     * @param  Request $request
     * @param  array $searchCols
     * @param  array $with
     * @param  null $conditionCall
     * @param  bool $all_columns
     * @return  \Illuminate\Http\JsonResponse
     */
    public function pagination(Request $request, $searchCols = [], $with = [], $conditionCall = null, $all_columns = false)
    {
        $searchCols = ["fdocument_status", "fname", "fremark"];
        return parent::pagination($request, $searchCols);
    }

    public function todoGroupTree(Request $request)
    {

        $todoGroup = VisitTodoGroup::find($request->input('id'));
        if (empty($todoGroup))
            return response()->json([]);
        $all = $todoGroup->todos->where('fparent_id', 0);
        $tree = [];
        foreach ($all as $top)
            $tree[] = $this->toBootstrapTreeViewData1($top, ['text' => 'fname', 'dataid' => 'id'], false, $todoGroup->todos->pluck('id')->toArray());
//        $tree['state'] = ['expanded' => true];
        return response()->json($tree);
    }

    public function toBootstrapTreeViewData1($entity, $props, $expanded = true, $todoids)
    {
        $data = ['item' => $entity];
        if (!empty($entity)) {
            foreach ($props as $k => $val) {

                $data[$k] = $entity->{$val};
                $data['state']['expanded'] = $expanded;

            }

            if (!empty($entity->children)) {
                $nodes = [];
                foreach ($entity->children as $child) {
                    if (in_array($child->id, $todoids)) {
                        $nodes[] = $this->toBootstrapTreeViewData($child, $props, $expanded);
                    }
                }
                if (!empty($nodes))
                    $data['nodes'] = $nodes;

            }
        }
        return $data;
    }

    public function config()
    {
        $customers = Customer::all();
        $groups = VisitTodoGroup::all()->where('fstart_date', '<=', date("Y-m-d"));

        return view('admin.visit-todo-group.config', compact('customers', 'groups'));
    }

    public function addTodo(Request $request)
    {
        $data = $request->all();
{'fraction_non_alphanumeric': 0.16067354698533406, 'fraction_numerical': 0.001955458989679522, 'mean_word_length': 2.185467128027682, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 68, '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': '1083107', 'n_tokens_mistral': 2763, 'n_tokens_neox': 2721, 'n_words': 538}