Elgg  Version 1.9
ElggMetadata.php
Go to the documentation of this file.
1 <?php
2 
14 class ElggMetadata extends ElggExtender {
15 
23  protected function initializeAttributes() {
24  parent::initializeAttributes();
25 
26  $this->attributes['type'] = "metadata";
27  }
28 
37  public function __construct($row = null) {
38  $this->initializeAttributes();
39 
40  if (!empty($row)) {
41  // Create from db row
42  if ($row instanceof stdClass) {
43  $metadata = $row;
44 
45  $objarray = (array) $metadata;
46  foreach ($objarray as $key => $value) {
47  $this->attributes[$key] = $value;
48  }
49  } else {
50  // get an ElggMetadata object and copy its attributes
51  elgg_deprecated_notice('Passing an ID to constructor is deprecated. Use elgg_get_metadata_from_id()', 1.9);
53  $this->attributes = $metadata->attributes;
54  }
55  }
56  }
57 
66  public function canEdit($user_guid = 0) {
67  if ($entity = get_entity($this->entity_guid)) {
68  return $entity->canEditMetadata($this, $user_guid);
69  }
70  return false;
71  }
72 
80  public function save() {
81  if ($this->id > 0) {
82  return update_metadata($this->id, $this->name, $this->value,
83  $this->value_type, $this->owner_guid, $this->access_id);
84  } else {
85  $this->id = create_metadata($this->entity_guid, $this->name, $this->value,
86  $this->value_type, $this->owner_guid, $this->access_id);
87 
88  if (!$this->id) {
89  throw new IOException("Unable to save new " . get_class());
90  }
91  return $this->id;
92  }
93  }
94 
100  public function delete() {
101  $success = _elgg_delete_metastring_based_object_by_id($this->id, 'metadata');
102  if ($success) {
103  // we mark unknown here because this deletes only one value
104  // under this name, and there may be others remaining.
105  _elgg_get_metadata_cache()->markUnknown($this->entity_guid, $this->name);
106  }
107  return $success;
108  }
109 
116  public function disable() {
117  $success = _elgg_set_metastring_based_object_enabled_by_id($this->id, 'no', 'metadata');
118  if ($success) {
119  // we mark unknown here because this disables only one value
120  // under this name, and there may be others remaining.
121  _elgg_get_metadata_cache()->markUnknown($this->entity_guid, $this->name);
122  }
123  return $success;
124  }
125 
132  public function enable() {
133  $success = _elgg_set_metastring_based_object_enabled_by_id($this->id, 'yes', 'metadata');
134  if ($success) {
135  _elgg_get_metadata_cache()->markUnknown($this->entity_guid, $this->name);
136  }
137  return $success;
138  }
139 
140  // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
141 
151  public function getObjectFromID($id) {
153  }
154 }
$success
Definition: view.php:29
update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id)
Update a specific piece of metadata.
Definition: metadata.php:156
canEdit($user_guid=0)
Determines whether or not the user can edit this piece of metadata.
save()
Save metadata object.
__construct($row=null)
Construct a metadata object.
getObjectFromID($id)
For a given ID, return the object associated with it.
$metadata
Definition: entity.php:19
_elgg_get_metadata_cache()
Get the global metadata cache instance.
Definition: metadata.php:849
$value
Definition: longtext.php:29
initializeAttributes()
(non-PHPdoc)
elgg_get_metadata_from_id($id)
Get a specific metadata object by its id.
Definition: metadata.php:35
enable()
Enable the metadata.
$filehandler owner_guid
Definition: crop.php:21
$key
Definition: summary.php:34
_elgg_delete_metastring_based_object_by_id($id, $type)
Deletes a metastring-based object by its id.
create_metadata($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=ACCESS_PRIVATE, $allow_multiple=false)
Create a new metadata object, or update an existing one.
Definition: metadata.php:69
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1171
$comment access_id
Definition: save.php:52
disable()
Disable the metadata.
$row
$user_guid
Avatar remove action.
Definition: remove.php:6
$entity
Definition: delete.php:10
_elgg_set_metastring_based_object_enabled_by_id($id, $enabled, $type)
Enables or disables a metastrings-based object by its id.
if(!$collection_name) $id
Definition: add.php:17
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604