/**
  * Gets a list of all View Access Levels available in the CMS ACL (translated by CMS)
  *
  * @param  boolean                     $html                   TRUE: Output array of HTML StdClass options value/text, FALSE: Output array( int AccessLevelId => string AccessLevelName )
  * @param  AuthoriseInterface|boolean  $filterByVisibleToUser  [optional] default: FALSE: No filtering, User: viewing user
  * @return array|\StdClass[]                                   Array( id => 'text' ) if $html=false, or array( StdClass with ->value and ->text ) if $html=true
  */
 public function getAllViewAccessLevels($html = false, AuthoriseInterface $filterByVisibleToUser = null)
 {
     $filter = false;
     $viewAccessLevels = array();
     if ($filterByVisibleToUser !== null) {
         if (!$filterByVisibleToUser->isSuperAdmin()) {
             $filter = true;
             $viewAccessLevels = $filterByVisibleToUser->getAuthorisedViewLevels();
         }
     }
     $access_levels = array();
     $levels = $this->loadAllViewAccessLevels();
     if (!$html && !$filter) {
         return $levels;
     }
     foreach ($levels as $value => $text) {
         if ($filter && !in_array((int) $value, $viewAccessLevels)) {
             continue;
         }
         if ($html) {
             $access_levels[] = \JHtml::_('select.option', $value, $text);
         } else {
             $access_levels[$value] = $text;
         }
     }
     return $access_levels;
 }
Example #2
0
 /**
  * Checks if $this user is Moderator for $entity or Super-administrator
  * Right now this implementation is relying on global moderator status,
  * but in future it might be on a per-user or per-group basis.
  *
  * @param  AuthoriseInterface  $entity  User Id to moderate
  * @return boolean                      True: Yes, False: No
  */
 public function isModeratorFor(AuthoriseInterface $entity)
 {
     // Checks if $this is authorized AND ( it is for himself OR the other $entity is not moderator )
     // OR $this is a super-admin:
     return $this->canViewAccessLevel($this->moderatorViewAccessLevel) && ($entity instanceof self && $this->getUserId() == $entity->getUserId() || !$entity->canViewAccessLevel($this->moderatorViewAccessLevel)) || $this->isSuperAdmin();
 }