IMP_Ftree::getAttribute PHP Method

getAttribute() public method

Get an attribute value.
public getAttribute ( string $type, string $name ) : mixed
$type string The attribute type.
$name string The element name.
return mixed Boolean attribute result, or null if element or attribute doesn't exist
    public function getAttribute($type, $name)
    {
        if (!($elt = $this[$name])) {
            return null;
        }
        $s_elt = strval($elt);
        switch ($type) {
            case 'children':
                return isset($this->_parent[$s_elt]);
            case 'container':
                $attr = self::ELT_NOSELECT;
                break;
            case 'namespace_other':
                $attr = self::ELT_NAMESPACE_OTHER;
                break;
            case 'namespace_shared':
                $attr = self::ELT_NAMESPACE_SHARED;
                break;
            case 'needsort':
                $attr = self::ELT_NEED_SORT;
                break;
            case 'nochildren':
                $attr = self::ELT_NOINFERIORS;
                break;
            case 'nonimap':
                $attr = self::ELT_NONIMAP;
                break;
            case 'open':
                if (!$elt->children) {
                    return false;
                }
                $attr = self::ELT_IS_OPEN;
                break;
            case 'polled':
                if ($this->_elts[$s_elt] & self::ELT_IS_POLLED) {
                    return true;
                } elseif ($this->_elts[$s_elt] & self::ELT_NOT_POLLED) {
                    return false;
                }
                $polled = $this->poll[$elt];
                $this->setAttribute('polled', $elt, $polled);
                return $polled;
            case 'remote':
                $attr = self::ELT_REMOTE;
                break;
            case 'remote_auth':
                $attr = self::ELT_REMOTE_AUTH;
                break;
            case 'remote_mbox':
                $attr = self::ELT_REMOTE_MBOX;
                break;
            case 'subscribed':
                if ($elt->inbox) {
                    return true;
                }
                $attr = self::ELT_IS_SUBSCRIBED;
                break;
            case 'vfolder':
                $attr = self::ELT_VFOLDER;
                break;
            default:
                return null;
        }
        return (bool) ($this->_elts[$s_elt] & $attr);
    }

Usage Example

Example #1
0
 /**
  */
 public function __get($name)
 {
     switch ($name) {
         case 'account':
             return $this->_tree->getAccount($this->_id);
         case 'base_elt':
             return $this->_id == IMP_Ftree::BASE_ELT;
         case 'child_list':
             return $this->_tree->getChildren($this->_id);
         case 'inbox':
             return $this->_id == 'INBOX';
         case 'level':
             if ($this->base_elt) {
                 return 0;
             }
             $i = substr_count($this->_id, $this->namespace_info->delimiter);
             $elt = $this;
             while ($elt = $elt->parent) {
                 if ($elt->namespace) {
                     return $i + 1;
                 } elseif ($elt->remote) {
                     if ($this->remote_mbox) {
                         ++$i;
                     }
                     return $i + 1;
                 }
             }
             return $i;
         case 'mbox_ob':
             return IMP_Mailbox::get($this->_id);
         case 'namespace':
             return $this->namespace_other || $this->namespace_shared;
         case 'namespace_info':
             return $this->mbox_ob->imp_imap->getNamespace($this->_id);
         case 'parent':
             return $this->_tree->getParent($this->_id);
         default:
             return $this->_tree->getAttribute($name, $this->_id);
     }
 }