ElggObject::canComment PHP Method

canComment() public method

Can a user comment on this object?
See also: ElggEntity::canComment()
Since: 1.8.0
public canComment ( integer $user_guid, boolean $default = null ) : boolean
$user_guid integer User guid (default is logged in user)
$default boolean Default permission
return boolean
    public function canComment($user_guid = 0, $default = null)
    {
        $result = parent::canComment($user_guid, $default);
        if ($result !== null) {
            return $result;
        }
        if ($user_guid == 0) {
            $user_guid = _elgg_services()->session->getLoggedInUserGuid();
        }
        // must be logged in to comment
        if (!$user_guid) {
            return false;
        }
        // must be member of group
        if (elgg_instanceof($this->getContainerEntity(), 'group')) {
            if (!$this->getContainerEntity()->canWriteToContainer($user_guid)) {
                return false;
            }
        }
        // no checks on read access since a user cannot see entities outside his access
        return true;
    }

Usage Example

Esempio n. 1
0
 /**
  * (non-PHPdoc)
  * @see ElggObject::canComment()
  */
 public function canComment($user_guid = 0)
 {
     if ($this->comments_allowed !== 'yes') {
         return false;
     }
     return parent::canComment($user_guid);
 }
All Usage Examples Of ElggObject::canComment