| @@ -1,0 +1,61 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * @package VikBooking | |
| 4 | + * @subpackage com_vikbooking | |
| 5 | + * @author E4J srl | |
| 6 | + * @copyright Copyright (C) e4j - Extensionsforjoomla.com. All rights reserved. | |
| 7 | + * @license GNU General Public License version 2 or later; see LICENSE | |
| 8 | + * @link https://vikwp.com | |
| 9 | + */ | |
| 10 | + | |
| 11 | +// No direct access | |
| 12 | +defined('ABSPATH') or die('No script kiddies please!'); | |
| 13 | + | |
| 14 | +JLoader::import('adapter.mvc.models.form'); | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * VikBooking plugin ACL model. | |
| 18 | + * | |
| 19 | + * @since 1.0 | |
| 20 | + * @see JModelForm | |
| 21 | + */ | |
| 22 | +class VikBookingModelAcl extends JModelForm | |
| 23 | +{ | |
| 24 | + /** | |
| 25 | + * A list containing the roles to ignore. | |
| 26 | + * | |
| 27 | + * @var array | |
| 28 | + */ | |
| 29 | + private $ignores = array('administrator'); | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * @override | |
| 33 | + * Updates the ACL for the existing Wordpress user roles. | |
| 34 | + * | |
| 35 | + * @param array &$data The array data containing the ACL rules. | |
| 36 | + * | |
| 37 | + * @return boolean True on success, otherwise false. | |
| 38 | + */ | |
| 39 | + public function save(&$data) | |
| 40 | + { | |
| 41 | + foreach ($data as $slug => $actions) | |
| 42 | + { | |
| 43 | + $role = get_role($slug); | |
| 44 | + | |
| 45 | + if ($role && !in_array($slug, $this->ignores)) | |
| 46 | + { | |
| 47 | + foreach ($actions as $cap => $has) | |
| 48 | + { | |
| 49 | + $has = (int) $has; | |
| 50 | + | |
| 51 | + if ($has != -1) | |
| 52 | + { | |
| 53 | + $b = $role->add_cap($cap, (bool) $has); | |
| 54 | + } | |
| 55 | + } | |
| 56 | + } | |
| 57 | + } | |
| 58 | + | |
| 59 | + return true; | |
| 60 | + } | |
| 61 | +} | |