phpQuery::data PHP Method

data() public static method

public static data ( $node, $name, $data, $documentID = null )
    public static function data($node, $name, $data, $documentID = null)
    {
        if (!$documentID) {
            // TODO check if this works
            $documentID = self::getDocumentID($node);
        }
        $document = self::$documents[$documentID];
        $node = self::dataSetupNode($node, $documentID);
        if (!isset($node->dataID)) {
            $node->dataID = ++self::$documents[$documentID]->uuid;
        }
        $id = $node->dataID;
        if (!isset($document->data[$id])) {
            $document->data[$id] = array();
        }
        if (!is_null($data)) {
            $document->data[$id][$name] = $data;
        }
        if ($name) {
            if (isset($document->data[$id][$name])) {
                return $document->data[$id][$name];
            }
        } else {
            return $id;
        }
    }

Usage Example

Example #1
0
 /**
  * Enter description here...
  * 
  * @param <type> $key
  * @param <type> $value
  */
 public function data($key, $value = null)
 {
     if (!isset($value)) {
         // TODO? implement specific jQuery behavior od returning parent values
         // is child which we look up doesn't exist
         return phpQuery::data($this->get(0), $key, $value, $this->getDocumentID());
     } else {
         foreach ($this as $node) {
             phpQuery::data($node, $key, $value, $this->getDocumentID());
         }
         return $this;
     }
 }