<commit_before><?php

namespace ErenMustafaOzdal\LaravelModulesBase\Services;

use Illuminate\Support\Collection;

class CollectionService
{

    /**
     * glue between items
     *
     * @var string
     */
    protected $glue;

    /**
     * get this key values of collection
     *
     * @var array
     */
    protected $keys;

    /**
     * collection relation
     *
     * @var array
     */
    protected $relation;

    /**
     * collection results
     *
     * @var array
     */
    protected $results = [];



    /*
    |--------------------------------------------------------------------------
    | Collection render with relation
    | its render the nested category
    |
    | Input:
    | - Category
    |    - Sub Category
    |
    | Result: Category{Glue: maybe '/'}Sub Category
    |--------------------------------------------------------------------------
    */

    /**
     * get rendered collection with relation
     *
     * @param Collection $items
     * @param string $relation
     * @param string $glue
     * @param array $keys
     * @return Collection
     */
    public function relationRender(Collection $items, $relation, $glue = '/', $keys = ['name'])
    {
        $this->glue = $glue;
        $this->keys = $keys;
        $this->relation = $relation;
        return collect( $this->getOptions($items) );
    }

    /**
     * get options of collection
     *
     * @param Collection $items
     * @param string $glue
     * @return array
     */
    private function getOptions(Collection $items, $glue = '')
    {
        $relation = $this->relation;
        foreach($items as $item) {
            $model = $this->getValues($item,$glue);
            $item->parents = $glue . $item->name_uc_first;
            $this->results[] = $model;
            if ($item->$relation->count() > 0) {
                $this->getOptions($item->$relation,$item->parents . $this->glue);
            }
        }
        return $this->results;
    }

    /**
     * get key values
     *
     * @param $item
     * @param string $glue
     * @return array
     */
    private function getValues($item, $glue)
    {
        $datas = [
            'id'        => $item->id,
            'parents'   => $glue . $item->parents
        ];
        foreach($this->keys as $key) {
            $datas[$key] = $item->$key;
        }
        return $datas;
    }
}<commit_msg>collection service node render düzenlendi ve overview içindeki kategori görünme hatası düzeltildi<commit_after><?php

namespace ErenMustafaOzdal\LaravelModulesBase\Services;

use Illuminate\Support\Collection;

class CollectionService
{
    /*
    |--------------------------------------------------------------------------
    | Nested Baum Collection get with ancestors and self
    | its render the nested category
    |
    | Input:
    | - Category
    |    - Sub Category
    |
    | Result: Category{Glue: maybe '/'}Sub Category
    |--------------------------------------------------------------------------
    */

    /**
     * ancestors and self render and get
     *
     * @param Collection $items
     * @param string $glue
     * @param array $keys
     * @return array
     */
    public function renderAncestorsAndSelf($items, $glue = '/', $keys = ['name'])
    {
        return $items->map(function($item,$key) use($keys, $glue)
        {
            $ancSelf = $item->ancestorsAndSelf()->get();
            $result = [ 'id' => $item->id];
            foreach ($keys as $k) {
                $plucks = $ancSelf->pluck($k);
                $plucks->pop();
                $result['parent_' . $k] = $plucks->implode($k,$glue);
                $result[$k] = $item->$k;
            }
            return $result;
        })->all();
    }
}
{'fraction_non_alphanumeric': 0.20853333333333332, 'fraction_numerical': 0.0002666666666666667, 'mean_word_length': 1.4309786130913804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '6796092', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1038, 'n_words': 240}