Feature
9 years ago
View
9 years ago
phtml
9 years ago
Feature.php
9 years ago
Filter.php
9 years ago
Manager.php
9 years ago
View.php
9 years ago
Feature.php
116 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | class AAM_Backend_Feature { |
| 11 | |
| 12 | /** |
| 13 | * Collection of features |
| 14 | * |
| 15 | * @var array |
| 16 | * |
| 17 | * @access private |
| 18 | * @static |
| 19 | */ |
| 20 | static private $_features = array(); |
| 21 | |
| 22 | /** |
| 23 | * Register UI Feature |
| 24 | * |
| 25 | * @param stdClass $feature |
| 26 | * |
| 27 | * @return boolean |
| 28 | * |
| 29 | * @access public |
| 30 | * @static |
| 31 | */ |
| 32 | public static function registerFeature(stdClass $feature) { |
| 33 | $response = false; |
| 34 | |
| 35 | if (empty($feature->capability)){ |
| 36 | $cap = AAM_Core_Config::get('page.capability', 'administrator'); |
| 37 | } else { |
| 38 | $cap = $feature->capability; |
| 39 | } |
| 40 | |
| 41 | if (AAM::getUser()->hasCapability($cap)) { |
| 42 | self::$_features[] = $feature; |
| 43 | $response = true; |
| 44 | } |
| 45 | |
| 46 | return $response; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Initiate the Controller |
| 51 | * |
| 52 | * @param stdClass $feature |
| 53 | * |
| 54 | * @return stdClass |
| 55 | * |
| 56 | * @access public |
| 57 | * @static |
| 58 | */ |
| 59 | public static function initView(stdClass $feature){ |
| 60 | if (is_string($feature->view)){ |
| 61 | $feature->view = new $feature->view; |
| 62 | } |
| 63 | |
| 64 | return $feature; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Retrieve list of features |
| 69 | * |
| 70 | * Retrieve sorted list of featured based on current subject |
| 71 | * |
| 72 | * @return array |
| 73 | * |
| 74 | * @access public |
| 75 | * @static |
| 76 | */ |
| 77 | public static function retriveList() { |
| 78 | $response = array(); |
| 79 | |
| 80 | $subject = AAM_Backend_View::getSubject(); |
| 81 | foreach (self::$_features as $feature) { |
| 82 | if (in_array(get_class($subject), $feature->subjects)) { |
| 83 | $response[] = self::initView($feature); |
| 84 | } |
| 85 | } |
| 86 | usort($response, 'AAM_Backend_Feature::reorder'); |
| 87 | |
| 88 | return $response; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Order list of features or subjectes |
| 93 | * |
| 94 | * Reorganize the list based on "position" attribute |
| 95 | * |
| 96 | * @param array $features |
| 97 | * |
| 98 | * @return array |
| 99 | * |
| 100 | * @access public |
| 101 | * @static |
| 102 | */ |
| 103 | public static function reorder($feature_a, $feature_b){ |
| 104 | $pos_a = (empty($feature_a->position) ? 9999 : $feature_a->position); |
| 105 | $pos_b = (empty($feature_b->position) ? 9999 : $feature_b->position); |
| 106 | |
| 107 | if ($pos_a == $pos_b){ |
| 108 | $response = 0; |
| 109 | } else { |
| 110 | $response = ($pos_a < $pos_b ? -1 : 1); |
| 111 | } |
| 112 | |
| 113 | return $response; |
| 114 | } |
| 115 | |
| 116 | } |