setMetadata() public method

Plugin developers usually want to use the magic set method ($entity->name = 'value'). Use this method if you want to explicitly set the owner or access of the metadata. You cannot set the owner/access before the entity has been saved.
public setMetadata ( string $name, mixed $value, string $value_type = '', boolean $multiple = false, integer $owner_guid, integer $access_id = null ) : boolean
$name string Name of the metadata
$value mixed Value of the metadata (doesn't support assoc arrays)
$value_type string 'text', 'integer', or '' for automatic detection
$multiple boolean Allow multiple values for a single name. Does not support associative arrays.
$owner_guid integer GUID of entity that owns the metadata. Default is owner of entity.
$access_id integer Who can read the metadata relative to the owner (deprecated). Default is the access level of the entity. Use ACCESS_PUBLIC for compatibility with Elgg 3.0
return boolean
コード例 #1
0
ファイル: deprecated-1.9.php プロジェクト: gzachos/elgg_ellak
/**
 * Utility function used by import_extender_plugin_hook() to process
 * an ODDMetaData and add it to an entity. This function does not
 * hit ->save() on the entity (this lets you construct in memory)
 *
 * @param \ElggEntity  $entity  The entity to add the data to.
 * @param ODDMetaData $element The OpenDD element
 *
 * @return bool
 * @access private
 * @deprecated 1.9
 */
function oddmetadata_to_elggextender(\ElggEntity $entity, ODDMetaData $element)
{
    // Get the type of extender (metadata, type, attribute etc)
    $type = $element->getAttribute('type');
    $attr_name = $element->getAttribute('name');
    $attr_val = $element->getBody();
    switch ($type) {
        // Ignore volatile items
        case 'volatile':
            break;
        case 'annotation':
            $entity->annotate($attr_name, $attr_val);
            break;
        case 'metadata':
            $entity->setMetadata($attr_name, $attr_val, "", true);
            break;
        default:
            // Anything else assume attribute
            $entity->set($attr_name, $attr_val);
    }
    // Set time if appropriate
    $attr_time = $element->getAttribute('published');
    if ($attr_time) {
        $entity->set('time_updated', $attr_time);
    }
    return true;
}