<commit_before><?php
/**
 * Created by IntelliJ IDEA.
 * User: onigoetz
 * Date: 27.04.14
 * Time: 18:24
 */

namespace Rocket\Taxonomy\Repositories;

use Rocket\Translation\I18NFacade as I18N;
use Rocket\Taxonomy\Facade as T;
use Rocket\Taxonomy\Model\TermContainer;
use Rocket\Taxonomy\Model\TermData;
use Rocket\Taxonomy\Term;

class TermRepository implements TermRepositoryInterface
{

    /**
     * @var \Illuminate\Cache\Repository
     */
    protected $cache;

    public function __construct(\Illuminate\Cache\CacheManager $cache)
    {
        $this->cache = $cache;
    }

    public function getTerm($term_id, $from_cache = true)
    {
        if (!$from_cache || !$data = $this->cache->get('Rocket::Taxonomy::Term::' . $term_id)) {
            $data = $this->cacheTerm($term_id);
        }

        return new Term($data);
    }

    /**
     * Puts the term in the cache and returns it for usage
     * @param  integer $term_id
     * @return array
     */
    protected function cacheTerm($term_id)
    {
        $term_table = (new TermContainer)->getTable();
        $data_table = (new TermData)->getTable();

        $translations = TermContainer::where($term_table . '.id', $term_id)
            ->select('term_id', 'vocabulary_id', $data_table . '.id', 'language_id', 'title', 'description')
            ->join($data_table, $term_table . '.id', '=', $data_table . '.term_id')
            ->get();<commit_msg>Bugfix on non existing Term retrieval<commit_after><?php
/**
 * Created by IntelliJ IDEA.
 * User: onigoetz
 * Date: 27.04.14
 * Time: 18:24
 */

namespace Rocket\Taxonomy\Repositories;

use Rocket\Translation\I18NFacade as I18N;
use Rocket\Taxonomy\Facade as T;
use Rocket\Taxonomy\Model\TermContainer;
use Rocket\Taxonomy\Model\TermData;
use Rocket\Taxonomy\Term;

class TermRepository implements TermRepositoryInterface
{

    /**
     * @var \Illuminate\Cache\Repository
     */
    protected $cache;

    public function __construct(\Illuminate\Cache\CacheManager $cache)
    {
        $this->cache = $cache;
    }

    public function getTerm($term_id, $from_cache = true)
    {
        if (!$from_cache || !$data = $this->cache->get('Rocket::Taxonomy::Term::' . $term_id)) {
            $data = $this->cacheTerm($term_id);
        }

        if (!$data) {
            return false;
        }

        return new Term($data);
    }

    /**
     * Puts the term in the cache and returns it for usage
     * @param  integer $term_id
     * @return array
     */
    protected function cacheTerm($term_id)
    {
        $term_table = (new TermContainer)->getTable();
        $data_table = (new TermData)->getTable();

        $translations = TermContainer::where($term_table . '.id', $term_id)
            ->select('term_id', 'vocabulary_id', $data_table . '.id', 'language_id', 'title', 'description')
            ->join($data_table, $term_table . '.id', '=', $data_table . '.term_id')
            ->get();
{'fraction_non_alphanumeric': 0.14732902347737326, 'fraction_numerical': 0.00952705001701259, 'mean_word_length': 2.735705209656925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '5704468', 'n_tokens_mistral': 961, 'n_tokens_neox': 938, 'n_words': 204}