Elgg  Version 2.3
ElggMetadata.php
Go to the documentation of this file.
1 <?php
2 
17 class ElggMetadata extends \ElggExtender {
18 
26  protected function initializeAttributes() {
27  parent::initializeAttributes();
28 
29  $this->attributes['type'] = "metadata";
30  }
31 
40  public function __construct($row = null) {
41  $this->initializeAttributes();
42 
43  if (!empty($row)) {
44  // Create from db row
45  if ($row instanceof \stdClass) {
46  $metadata = $row;
47 
48  $objarray = (array) $metadata;
49  foreach ($objarray as $key => $value) {
50  $this->attributes[$key] = $value;
51  }
52  } else {
53  // get an \ElggMetadata object and copy its attributes
54  elgg_deprecated_notice('Passing an ID to constructor is deprecated. Use elgg_get_metadata_from_id()', 1.9);
56  $this->attributes = $metadata->attributes;
57  }
58  }
59  }
60 
69  public function canEdit($user_guid = 0) {
70  if ($entity = get_entity($this->entity_guid)) {
71  return $entity->canEditMetadata($this, $user_guid);
72  }
73  return false;
74  }
75 
83  public function save() {
84  if ($this->id > 0) {
85  return update_metadata($this->id, $this->name, $this->value,
86  $this->value_type, $this->owner_guid, $this->access_id);
87  } else {
88  // using create_metadata() for deprecation notices in 2.x
89  $this->id = create_metadata($this->entity_guid, $this->name, $this->value,
90  $this->value_type, $this->owner_guid, $this->access_id);
91 
92  if (!$this->id) {
93  throw new \IOException("Unable to save new " . get_class());
94  }
95  return $this->id;
96  }
97  }
98 
104  public function delete() {
105  $success = _elgg_delete_metastring_based_object_by_id($this->id, 'metadata');
106  if ($success) {
107  _elgg_services()->metadataCache->clear($this->entity_guid);
108  }
109  return $success;
110  }
111 
118  public function disable() {
119  $success = _elgg_set_metastring_based_object_enabled_by_id($this->id, 'no', 'metadata');
120  if ($success) {
121  $this->enabled = 'no';
122  _elgg_services()->metadataCache->clear($this->entity_guid);
123  }
124  return $success;
125  }
126 
133  public function enable() {
134  $success = _elgg_set_metastring_based_object_enabled_by_id($this->id, 'yes', 'metadata');
135  if ($success) {
136  $this->enabled = 'yes';
137  _elgg_services()->metadataCache->clear($this->entity_guid);
138  }
139  return $success;
140  }
141 
142  // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
143 
153  public function getObjectFromID($id) {
155  }
156 }
update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id)
Update a specific piece of metadata.
Definition: metadata.php:93
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.
create_metadata($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=null, $allow_multiple=false)
Create a new metadata object, or update an existing one.
Definition: metadata.php:66
getObjectFromID($id)
For a given ID, return the object associated with it.
$metadata
Definition: entity.php:19
$value
Definition: longtext.php:42
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.
$key
Definition: summary.php:34
_elgg_delete_metastring_based_object_by_id($id, $type)
Deletes a metastring-based object by its id.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1098
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
$comment access_id
Definition: save.php:60
disable()
Disable the metadata.
$site name
$entity
Definition: delete.php:7
$row
$user_guid
Avatar remove action.
Definition: remove.php:6
_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
$comment owner_guid
Definition: save.php:58
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204