/** * Set the external news preferences for an agent user. * * @param bool $newsVisibilityPref True for visible or false for invisible. * @param mixed $newsCategoryPrefs Array of news category IDs or null to leave as-is. * * @return void */ public function setUserExternalNewsPreferences($newsVisibilityPref, $newsCategoryPrefs = null) { // Check we have a user ID set if (is_null($this->_userId)) { throw new Zend_Exception('User ID not specified'); } // Set user's news visibility preference $this->_userDatasource->setUserEnableExternalNews($newsVisibilityPref, $this->_userId); // Keep local user object in sync $this->_userObject->enableExternalNews = $newsVisibilityPref; // Set user's news category preferences, if given if (!is_null($newsCategoryPrefs)) { $externalNewsCategoryDatasource = new Datasource_Cms_ExternalNews_CategoriesAgentsMap(); return $externalNewsCategoryDatasource->setNewsPreferences($newsCategoryPrefs, $this->_userId); } }
/** * Clean up locally stored news - prunes old entries and removes dead * categories (and any mapping links to them) that are tagged as * non-permanent. * * Intended to be run as a cron task. * * @return void */ public function cleanupNews() { $this->_useCategoryDatasource(); $this->_useItemDatasource(); // Delete old news items $this->_externalNewsItemDatasource->prune(); // Identify non-permanent categories that haven't been updated in a while $unusedCategories = $this->_externalNewsCategoryDatasource->getPrunable(); // Remove mapping links between agent users and old non-permanent categories $mappingDatasource = new Datasource_Cms_ExternalNews_CategoriesAgentsMap(); $mappingDatasource->pruneByCategories($unusedCategories); // Remove old non-permanent categories $this->_externalNewsCategoryDatasource->prune(); }