CategoryModel::loadAllCategories PHP Method

loadAllCategories() private static method

Load all of the categories from the cache or the database.
private static loadAllCategories ( )
    private static function loadAllCategories()
    {
        Logger::log(Logger::DEBUG, "CategoryModel::loadAllCategories");
        // Try and get the categories from the cache.
        $categoriesCache = Gdn::cache()->get(self::CACHE_KEY);
        $rebuild = true;
        // If we received a valid data structure, extract the embedded expiry
        // and re-store the real categories on our static property.
        if (is_array($categoriesCache)) {
            // Test if it's time to rebuild
            $rebuildAfter = val('expiry', $categoriesCache, null);
            if (!is_null($rebuildAfter) && time() < $rebuildAfter) {
                $rebuild = false;
            }
            self::$Categories = val('categories', $categoriesCache, null);
        }
        unset($categoriesCache);
        if ($rebuild) {
            // Try to get a rebuild lock
            $haveRebuildLock = self::rebuildLock();
            if ($haveRebuildLock || !self::$Categories) {
                $Sql = Gdn::sql();
                $Sql = clone $Sql;
                $Sql->reset();
                $Sql->select('c.*')->from('Category c')->orderBy('c.TreeLeft');
                self::$Categories = array_merge(array(), $Sql->get()->resultArray());
                self::$Categories = Gdn_DataSet::Index(self::$Categories, 'CategoryID');
                self::buildCache();
                // Release lock
                if ($haveRebuildLock) {
                    self::rebuildLock(true);
                }
            }
        }
        if (self::$Categories) {
            self::joinUserData(self::$Categories, true);
        }
    }