<?php

/**
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS\module\members
 * @copyright Copyright (c) 2012 - 2013 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/**
 * membersEvents Class
 *
 * Class to process members module events.
 *
 * @package clearFusionCMS\module\members
 */
class membersEvents {

	/**
	 * Event handler notified when a role is removed.
	 *
	 * @param flEvent $evt The event object.
	 */
	function onRoleDeleted($evt) {
		$id = $evt->getParam('id');

		$siteMgr = new cfSiteManager(clearFusionCMS::getDb());
		$sites = $siteMgr->listSites();
		foreach($sites as $site => $n) {
			// Remove the role from the sites default role list
			$cfg = new flConfigDb('cfMembers', clearFusionCMS::getDb(), "cf_config_{$site}");
			$roles = array_flip(unserialize($cfg->defaultRoles));
			unset($roles[$id]);
			$cfg->defaultRoles = serialize(array_keys($roles));
		}
	}

	/**
	 * Event handler for daily cron job to purge inactive accounts.
	 *
	 * @param flEvent $evt The event object.
	 */
	function onCron1d($evt) {
		$cfg = clearFusionCMS::getSiteConfig('cfMembers');
		clearFusionCMS::getUserMgr()->prunePendingActivation($cfg->purneAfter * 86400);
	}
}
