/**
  * @return \EE_Default_Where_Conditions
  */
 protected function _generate_restrictions()
 {
     //if there are no standard caps for this model, then for now all we know
     //if they need the default cap to access this
     if (!$this->model()->cap_slug()) {
         return array(EE_Restriction_Generator_Base::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions());
     }
     $restrictions = array();
     //does the basic cap exist? (eg 'ee_read_registrations')
     if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action())) {
         $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action())] = new EE_Return_None_Where_Conditions();
         //does the others cap exist? (eg 'ee_read_others_registrations')
         if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others')) {
             //both caps exist
             $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others')] = new EE_Default_Where_Conditions(array(EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder));
             //does the private cap exist (eg 'ee_read_others_private_events')
             if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_private') && $this->model() instanceof EEM_CPT_Base) {
                 //if they have basic and others, but not private, restrict them to see theirs and others' that aren't private
                 $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private')] = new EE_Default_Where_Conditions(array('OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') => array(EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, 'status' => array('!=', 'private'))));
             }
         }
     } else {
         //there is no basic cap. So they can only access this if they have the default admin cap
         $restrictions[EE_Restriction_Generator_Base::get_default_restrictions_cap()] = new EE_Return_None_Where_Conditions();
     }
     return $restrictions;
 }
 /**
  *
  * @return \EE_Default_Where_Conditions
  */
 protected function _generate_restrictions()
 {
     //if there are no standard caps for this model, then for now all we know is
     //if they need the default cap to access this
     if (!$this->model()->cap_slug()) {
         return array(self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions());
     }
     $event_model = EEM_Event::instance();
     $restrictions = array(EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(array($this->_default_field_name => true)), EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions(array('OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => array($this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder), $this->_default_field_name => true)), EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions(array('OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => array($this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, $this->_path_to_event_model . 'status' => array('!=', 'private'), $this->_default_field_name => true))), EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_default') => new EE_Default_Where_Conditions(array($this->_default_field_name => false)));
     if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others_default')) {
         $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default')] = new EE_Default_Where_Conditions(array('OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') => array('AND' => array($this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, $this->_default_field_name => true), $this->_default_field_name => false)));
     }
     return $restrictions;
 }
 protected function _generate_restrictions()
 {
     //if there are no standard caps for this model, then for allow full access
     if (!$this->model()->cap_slug()) {
         return array();
     }
     $restrictions = array();
     //does the basic cap exist? (eg 'ee_read_registrations')
     if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action())) {
         if ($this->model() instanceof EEM_CPT_Base) {
             $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action())] = new EE_Default_Where_Conditions(array('status' => 'publish'));
         } elseif ($this->model() instanceof EEM_Soft_Delete_Base) {
             $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action())] = new EE_Default_Where_Conditions(array($this->model()->deleted_field_name() => false));
         } else {
             //don't impose any restrictions if they don't have the basic reading cap
         }
         //does the others cap exist? (eg 'ee_read_others_registrations')
         if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others')) {
             //both caps exist
             if ($this->model() instanceof EEM_CPT_Base) {
                 //then if they don't have the others cap, AT MOST show them their own and other published ones
                 $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others')] = new EE_Default_Where_Conditions(array('OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => array(EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, 'status' => 'publish')));
             } elseif ($this->model() instanceof EEM_Soft_Delete_Base) {
                 //then if they don't have the other cap, AT MOST show them their own or non deleted ones
                 $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others')] = new EE_Default_Where_Conditions(array('OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => array(EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, $this->model()->deleted_field_name() => false)));
             } else {
                 //again, if they don't have the others cap, continue showing all because there are no inherently hidden ones
             }
             //does the private cap exist (eg 'ee_read_others_private_events')
             if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_private') && $this->model() instanceof EEM_CPT_Base) {
                 //if they have basic and others, but not private, restrict them to see theirs and others' that aren't private
                 $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private')] = new EE_Default_Where_Conditions(array('OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') => array(EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, 'status' => array('!=', 'private'))));
             }
         }
     } else {
         //there is no basic cap. So allow full access
         $restrictions = array();
     }
     return $restrictions;
 }
 function test_is_cap()
 {
     $this->assertTrue(EE_Restriction_Generator_Base::is_cap(EEM_Event::instance(), 'edit'));
     $this->assertTrue(EE_Restriction_Generator_Base::is_cap(EEM_Event::instance(), 'edit_others'));
     $this->assertFalse(EE_Restriction_Generator_Base::is_cap(EEM_Event::instance(), 'rock'));
 }