Vsch\TranslationManager\Manager::clearUsageCache PHP Method

clearUsageCache() public method

public clearUsageCache ( $clearDatabase, $groups = null )
    public function clearUsageCache($clearDatabase, $groups = null)
    {
        $ltm_translations = $this->getTranslationsTableName();
        if (!$groups || $groups === '*') {
            $this->usageCache();
            $this->usageCache = [];
            $this->usageCacheIsDirty = true;
            $this->saveUsageCache();
            if ($clearDatabase) {
                $this->getConnection()->affectingStatement(<<<SQL
UPDATE {$ltm_translations} SET was_used = 0 WHERE was_used <> 0
SQL
);
            }
        } elseif ($this->usageCache()) {
            $this->usageCache();
            if (!is_array($groups)) {
                $groups = [$groups];
            }
            foreach ($groups as $group) {
                if (array_key_exists($group, $this->usageCache)) {
                    unset($this->usageCache[$group]);
                    $this->usageCacheIsDirty = !!$this->persistentPrefix;
                }
                if ($clearDatabase) {
                    $this->getConnection()->affectingStatement(<<<SQL
UPDATE {$ltm_translations} SET was_used = 0 WHERE was_used <> 0 AND (`group` = ? OR `group` LIKE ? OR `group` LIKE ?)
SQL
, [$group, 'vnd:%.' . $group, 'wbn:%.' . $group]);
                }
            }
            $this->saveUsageCache();
        }
    }

Usage Example

 public function getUsageInfo()
 {
     $group = \Request::get("group");
     $reset = \Request::get("reset-usage-info");
     $show = \Request::get("show-usage-info");
     // need to store this so that it can be displayed again
     \Cookie::queue($this->cookieName(self::COOKIE_SHOW_USAGE), $show, 60 * 24 * 365 * 1);
     if ($reset) {
         // TODO: add show usage info to view variables so that a class can be added to keys that have no usage info
         // need to clear the usage information
         $this->manager->clearUsageCache(true, $group);
     }
     if (\App::runningUnitTests()) {
         return \Redirect::to('/');
     }
     return !is_null(\Request::header('referer')) ? \Redirect::back() : \Redirect::to('/');
 }