Classes

File content/keyword/KeywordsCache.class.php

File content/keyword/KeywordsCache.class.php

 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 
<?php
/**
 * @package     Content
 * @subpackage  Keyword
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Julien BRISWALTER <j1.seth@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2018 11 09
 * @since       PHPBoost 5.1 - 2018 11 09
*/

abstract class KeywordsCache implements CacheData
{
    protected $keywords;

    public function synchronize()
    {
        $this->keywords = array();
        $result = PersistenceContext::get_querier()->select('SELECT relation.id_in_module, relation.id_keyword, keyword.*
            FROM '. DB_TABLE_KEYWORDS_RELATIONS .' relation
            LEFT JOIN '. DB_TABLE_KEYWORDS .' keyword ON keyword.id = relation.id_keyword
            WHERE relation.module_id = :module_id
            ORDER BY relation.id_keyword', array(
                'module_id' => self::get_class()->get_module_identifier()
        ));
        while ($row = $result->fetch())
        {
            $keyword = new Keyword();
            $keyword->set_properties($row);
            $this->keywords[$row['id_in_module']][$row['name']] = $keyword;
        }
        $result->dispose();
    }

    abstract public function get_module_identifier();

    public function get_keywords($id_in_module)
    {
        if ($this->has_keywords($id_in_module))
        {
            return $this->keywords[$id_in_module];
        }
        return array();
    }

    public function has_keywords($id)
    {
        return array_key_exists($id, $this->keywords);
    }

    /**
     * Loads and returns the keywords cached data.
     * @return KeywordsCache The cached data
     */
    public static function load()
    {
        return CacheManager::load(get_called_class(), self::get_class()->get_module_identifier(), 'keywords');
    }

    /**
     * Invalidates keywords cached data.
     */
    public static function invalidate()
    {
        CacheManager::invalidate(self::get_class()->get_module_identifier(), 'keywords');
    }

    public static function get_class()
    {
        $class_name = get_called_class();
        return new $class_name();
    }
}
?>
Annonces