You are here

public function EasyRdf_Graph::deleteSingleProperty in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php \EasyRdf_Graph::deleteSingleProperty()

Delete a property (or optionally just a specific value)

@ignore

Parameters

mixed $resource The resource to delete the property from:

string $property The name of the property (e.g. foaf:name):

mixed $value The value to delete (null to delete all values):

Return value

integer The number of values deleted

1 call to EasyRdf_Graph::deleteSingleProperty()
EasyRdf_Graph::delete in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Delete a property (or optionally just a specific value)

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php, line 1072

Class

EasyRdf_Graph
Container for collection of EasyRdf_Resources.

Code

public function deleteSingleProperty($resource, $property, $value = null) {
  $this
    ->checkResourceParam($resource);
  $this
    ->checkSinglePropertyParam($property, $inverse);
  $this
    ->checkValueParam($value);
  $count = 0;
  if (isset($this->index[$resource][$property])) {
    foreach ($this->index[$resource][$property] as $k => $v) {
      if (!$value or $v == $value) {
        unset($this->index[$resource][$property][$k]);
        $count++;
        if ($v['type'] == 'uri' or $v['type'] == 'bnode') {
          $this
            ->deleteInverse($v['value'], $property, $resource);
        }
      }
    }

    // Clean up the indexes - remove empty properties and resources
    if ($count) {
      if (count($this->index[$resource][$property]) == 0) {
        unset($this->index[$resource][$property]);
      }
      if (count($this->index[$resource]) == 0) {
        unset($this->index[$resource]);
      }
    }
  }
  return $count;
}