class.swpm-permission-collection.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. /**
  8. * Description of bPermissionCollection
  9. *
  10. * @author nur
  11. */
  12. class SwpmPermissionCollection {
  13. protected $permissions;
  14. protected static $instance;
  15. protected function __construct() {
  16. $this->permissions = array();
  17. }
  18. public static function get_instance(){
  19. self::$_this = empty(self::$_this)? new SwpmPermissionCollection():self::$_this;
  20. return self::$_this;
  21. }
  22. public function load($level_ids = array()){
  23. if (empty($level_ids)){
  24. global $wpdb;
  25. $level_ids = $wpdb->get_col("SELECT id FROM {$wpdb->prefix}swpm_membership_tbl WHERE id != 1");
  26. }
  27. foreach($level_ids as $id){
  28. $this->permissions[] = SwpmPermission::get_instance($id);
  29. }
  30. }
  31. public function get_permitted_levels($post_id){
  32. $levels = array();
  33. foreach($this->permissions as $permission){
  34. if ($permission->is_permitted($post_id)){
  35. $levels[$permission->get($id)] = $permission->get('alias');
  36. }
  37. }
  38. return $levels;
  39. }
  40. }