Elgg  Version 1.11
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  _elgg_services()->metadataCache->clear($this->entity_guid);
104  }
105  return $success;
106  }
107 
114  public function disable() {
115  $success = _elgg_set_metastring_based_object_enabled_by_id($this->id, 'no', 'metadata');
116  if ($success) {
117  _elgg_services()->metadataCache->clear($this->entity_guid);
118  }
119  return $success;
120  }
121 
128  public function enable() {
129  $success = _elgg_set_metastring_based_object_enabled_by_id($this->id, 'yes', 'metadata');
130  if ($success) {
131  _elgg_services()->metadataCache->clear($this->entity_guid);
132  }
133  return $success;
134  }
135 
136  // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
137 
147  public function getObjectFromID($id) {
149  }
150 }
$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:84
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
$value
Definition: longtext.php:26
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.
_elgg_services()
Definition: autoloader.php:14
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:65
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1006
$comment access_id
Definition: save.php:61
disable()
Disable the metadata.
$site name
$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:382