<?php
/**
 * @package     DOCman
 * @copyright   Copyright (C) 2019 Timble CVBA. (http://www.timble.net)
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.joomlatools.com
 */

namespace Foliolabs\Docman;

use Foliolabs\Library;

class DatabaseTableUsers extends Library\DatabaseTableAbstract
{
    public function clearPermissions($users = [])
    {
        $driver = $this->getDriver();

        $driver->execute('START TRANSACTION;');

		if ($users)
		{
			$driver->execute(sprintf('DELETE FROM #__docman_categories_permissions WHERE wp_user_id IN (%s);', implode(',', $users)));
			$driver->execute(sprintf('UPDATE #__docman_users SET permissions_map = NULL WHERE wp_user_id IN (%s);', implode(',', $users)));
		}
		else
		{
			$driver->execute('TRUNCATE TABLE #__docman_categories_permissions;');
			$driver->execute('UPDATE #__docman_users SET permissions_map = NULL;');
		}

        $driver->execute('COMMIT;');

        $this->getObject('user')->resetData(); // Force current user to reset it's aggregate data

        return $this;
    }
}
