annotate() 공개 메소드

Adds an annotation to an entity.
public annotate ( string $name, mixed $value, integer $access_id = ACCESS_PRIVATE, integer $owner_guid, string $vartype = "" ) : boolean | integer
$name string Annotation name
$value mixed Annotation value
$access_id integer Access ID
$owner_guid integer GUID of the annotation owner
$vartype string The type of annotation value
리턴 boolean | integer Returns int if an annotation is saved
예제 #1
0
 public function testCanEdit()
 {
     $user = new \ElggUser();
     $user->save();
     $id = $this->entity->annotate('test', 'foo', ACCESS_LOGGED_IN, elgg_get_logged_in_user_guid());
     $a = elgg_get_annotation_from_id($id);
     $this->assertTrue($a->canEdit());
     $this->assertFalse($a->canEdit($user->guid));
     $id = $this->entity->annotate('test', 'foo2', ACCESS_LOGGED_IN, $user->guid);
     $a = elgg_get_annotation_from_id($id);
     $this->assertTrue($a->canEdit());
     $this->assertTrue($a->canEdit($user->guid));
     $user->delete();
 }
예제 #2
0
/**
 * 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
 */
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;
}
예제 #3
0
 public function testElggEnityGetAndSetAnnotations()
 {
     $this->assertIdentical($this->entity->getAnnotations(array('annotation_name' => 'non_existent')), array());
     // save entity and check for annotation
     $this->entity->annotate('non_existent', 'foo');
     $annotations = $this->entity->getAnnotations(array('annotation_name' => 'non_existent'));
     $this->assertIsA($annotations[0], '\\ElggAnnotation');
     $this->assertIdentical($annotations[0]->name, 'non_existent');
     $this->assertEqual($this->entity->countAnnotations('non_existent'), 1);
     // @todo belongs in Annotations API test class
     $this->assertIdentical($annotations, elgg_get_annotations(array('guid' => $this->entity->getGUID())));
     $this->assertIdentical($annotations, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'object')));
     $this->assertIdentical(false, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'object', 'subtype' => 'fail')));
     //  clear annotation
     $this->assertTrue($this->entity->deleteAnnotations());
     $this->assertEqual($this->entity->countAnnotations('non_existent'), 0);
     // @todo belongs in Annotations API test class
     $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID())));
     $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'object')));
 }