src/Charcoal/Cms/Service/Loader/SectionLoader.php
public function sectionRoutes()
    {
        if ($this->sectionRoutes) {
            return $this->sectionRoutes;
        }

        $proto = $this->modelFactory()->create(ObjectRoute::class);

        $sectionTypes = $this->sectionTypes();
        if (empty($sectionTypes)) {
            $sectionTypes = [
                'base' => $this->objType()
            ];
        }

        $loader = $this->collectionLoader()->reset();
        $loader->setModel($proto);

        $filters = [];
        foreach ($sectionTypes as $key => $val) {
            $filters[] = 'route_obj_type = \''.$val.'\'';
        }
        $q = 'SELECT * FROM `'.$proto->source()->table().'`
            WHERE active = 1 AND ('.implode(' OR ', $filters).')
            AND `route_options_ident` IS NULL
            ORDER BY creation_date ASC';

        $objectRoutes = $loader->loadFromQuery($q);

        // $loader->addFilter('route_obj_type', $this->objType())
        //     // This is important. This is why it all works
        //     // Loading it from the first created to the last created
        //     // makes the following foreach override previous data.
        //     ->addOrder('creation_date', 'asc');

        // $objectRoutes = $loader->load();

        $sections = [];
        $routes = [];
        // The current language
        $lang = $this->translator()->getLocale();
        foreach ($objectRoutes as $o) {
            if ($o->lang() === $lang) {
                // Will automatically override previous slug set
                $sections[$o->routeObjId()] = $o->slug();
            }
            // Keep track of EVERY slug.
            $routes[$o->slug()] = $o->routeObjId();
        }

        $this->sectionRoutes = [
            'sections' => $sections,
            'routes'   => $routes
        ];

        return $this->sectionRoutes;
    }
public function sectionRoutes()
    {
        if ($this->sectionRoutes) {
            return $this->sectionRoutes;
        }

        $proto = $this->modelFactory()->create(ObjectRoute::class);

        $sectionTypes = $this->sectionTypes();
        if (empty($sectionTypes)) {
            $sectionTypes = [
                'base' => $this->objType()
            ];
        }

        $loader = $this->collectionLoader()->reset();
        $loader->setModel($proto);

        $filters = [];
        foreach ($sectionTypes as $key => $val) {
            $filters[] = 'route_obj_type = \''.$val.'\'';
        }
        $q = 'SELECT * FROM `'.$proto->source()->table().'`
            WHERE active = 1 AND ('.implode(' OR ', $filters).')
            AND `route_options_ident` IS NULL
            ORDER BY creation_date ASC';

        $objectRoutes = $loader->loadFromQuery($q);

        // $loader->addFilter('route_obj_type', $this->objType())
        //     // This is important. This is why it all works
        //     // Loading it from the first created to the last created
        //     // makes the following foreach override previous data.
        //     ->addOrder('creation_date', 'asc');

        // $objectRoutes = $loader->load();

        $sections = [];
        $routes = [];
        // The current language
        $lang = $this->translator()->getLocale();
        foreach ($objectRoutes as $o) {
            if ($o->lang() === $lang) {
                // Will automatically override previous slug set
                $sections[$o->routeObjId()] = $o->slug();
            }
            // Keep track of EVERY slug.
            $routes[$o->slug()] = $o->routeObjId();
        }

        $this->sectionRoutes = [
            'sections' => $sections,
            'routes'   => $routes
        ];

        return $this->sectionRoutes;
    }
public function sectionRoutes ( ) { if ( $ this -> sectionRoutes ) { return $ this -> sectionRoutes ; } $ proto = $ this -> modelFactory ( ) -> create ( ObjectRoute :: class ) ; $ sectionTypes = $ this -> sectionTypes ( ) ; if ( empty ( $ sectionTypes ) ) { $ sectionTypes = [ 'base' => $ this -> objType ( ) ] ; } $ loader = $ this -> collectionLoader ( ) -> reset ( ) ; $ loader -> setModel ( $ proto ) ; $ filters = [ ] ; foreach ( $ sectionTypes as $ key => $ val ) { $ filters [ ] = 'route_obj_type = \'' . $ val . '\'' ; } $ q = 'SELECT * FROM `' . $ proto -> source ( ) -> table ( ) . '`
            WHERE active = 1 AND (' . implode ( ' OR ' , $ filters ) . ')
            AND `route_options_ident` IS NULL
            ORDER BY creation_date ASC' ; $ objectRoutes = $ loader -> loadFromQuery ( $ q ) ; // $loader->addFilter('route_obj_type', $this->objType()) //     // This is important. This is why it all works //     // Loading it from the first created to the last created //     // makes the following foreach override previous data. //     ->addOrder('creation_date', 'asc'); // $objectRoutes = $loader->load(); $ sections = [ ] ; $ routes = [ ] ; // The current language $ lang = $ this -> translator ( ) -> getLocale ( ) ; foreach ( $ objectRoutes as $ o ) { if ( $ o -> lang ( ) === $ lang ) { // Will automatically override previous slug set $ sections [ $ o -> routeObjId ( ) ] = $ o -> slug ( ) ; } // Keep track of EVERY slug. $ routes [ $ o -> slug ( ) ] = $ o -> routeObjId ( ) ; } $ this -> sectionRoutes = [ 'sections' => $ sections , 'routes' => $ routes ] ; return $ this -> sectionRoutes ; }
Pair routes slug to sections ID
@return array
Pair routes slug to sections ID