DcatSeeder::seedThemes PHP Method

seedThemes() private method

return @void
private seedThemes ( )
    private function seedThemes()
    {
        $this->command->info('---- DCAT Themes ----');
        $uri = 'http://ns.thedatatank.com/dcat/themes#Taxonomy';
        $themes_fetched = false;
        // Try to get the themes from the ns.thedatatank.com (semantic data)
        try {
            $this->command->info('Trying to fetch new themes online.');
            $themes_graph = Graph::newAndLoad($uri);
            if ($themes_graph->isEmpty()) {
                $this->command->info('We could not reach the online themes.');
            } else {
                $themes_fetched = true;
                $this->command->info('Found new themes online, removing the old ones.');
                // Empty the themes table
                \Theme::truncate();
            }
            // Fetch all of the themes
            foreach ($themes_graph->resourcesMatching('skos:inScheme') as $theme) {
                if ($theme->get('skos:inScheme')->getUri() == $uri) {
                    $theme_uri = $theme->getUri();
                    $label = $theme->getLiteral('rdfs:label');
                    if (!empty($label) && !empty($theme_uri)) {
                        $label = $label->getValue();
                        $this->command->info('Added ' . $uri . ' with label ' . $label);
                        \Theme::create(array('uri' => $theme_uri, 'label' => $label));
                    }
                }
            }
            $this->command->info('Added new themes.');
        } catch (Exception $ex) {
            $this->command->info('An error occurred when we tried to fetch online themes.');
        }
        // If it's not available, get them from a file (json)
        if (!$themes_fetched) {
            $this->command->info('Trying to fetch the themes from the local json file containing a default set of themes.');
            $themes = json_decode(file_get_contents(app_path() . '/database/seeds/data/themes.json'));
            if (!empty($themes)) {
                $this->command->info('Found new themes, removing the old ones.');
                // Empty the themes table
                \Theme::truncate();
                foreach ($themes as $theme) {
                    \Theme::create(array('uri' => $theme->uri, 'label' => $theme->label));
                }
                if (!empty($themes)) {
                    $this->command->info('Added themes from the local json file.');
                }
            } else {
                $this->command->info('No themes were found in the local json file, the old ones will not be replaced.');
            }
        }
    }