Beispiel #1
0
/**
 * Attempt to construct an ODD object out of a XmlElement or sub-elements.
 *
 * @param XmlElement $element The element(s)
 *
 * @return mixed An ODD object if the element can be handled, or false.
 */
function ODD_factory(XmlElement $element)
{
    $name = $element->name;
    $odd = false;
    switch ($name) {
        case 'entity':
            $odd = new ODDEntity("", "", "");
            break;
        case 'metadata':
            $odd = new ODDMetaData("", "", "", "");
            break;
        case 'relationship':
            $odd = new ODDRelationship("", "", "");
            break;
    }
    // Now populate values
    if ($odd) {
        // Attributes
        foreach ($element->attributes as $k => $v) {
            $odd->setAttribute($k, $v);
        }
        // Body
        $body = $element->content;
        $a = stripos($body, "<![CDATA");
        $b = strripos($body, "]]>");
        if ($body && $a !== false && $b !== false) {
            $body = substr($body, $a + 8, $b - ($a + 8));
        }
        $odd->setBody($body);
    }
    return $odd;
}
Beispiel #2
0
 /**
  * Export this relationship
  *
  * @return array
  * @deprecated 1.9 Use toObject()
  */
 public function export()
 {
     elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
     $uuid = get_uuid_from_object($this);
     $relationship = new ODDRelationship(guid_to_uuid($this->guid_one), $this->relationship, guid_to_uuid($this->guid_two));
     $relationship->setAttribute('uuid', $uuid);
     return $relationship;
 }
Beispiel #3
0
 /**
  * Export this relationship
  *
  * @return array
  */
 public function export()
 {
     $uuid = get_uuid_from_object($this);
     $relationship = new ODDRelationship(guid_to_uuid($this->guid_one), $this->relationship, guid_to_uuid($this->guid_two));
     $relationship->setAttribute('uuid', $uuid);
     return $relationship;
 }
/**
 * Extract entities from the system log and produce them as an OpenDD stream.
 * This stream can be subscribed to and reconstructed on another system as an activity stream.
 *
 * @param int $by_user The user who initiated the event.
 * @param string $relationship Limit return results to only those users who $by_user has $relationship with.
 * @param int $limit Maximum number of events to show
 * @param int $offset An offset
 * @return ODDDocument
 */
function get_river_entries_as_opendd($by_user = "", $relationship = "", $limit = 10, $offset = 0)
{
    global $CONFIG;
    $limit = (int) $limit;
    $offset = (int) $offset;
    $relationship = sanitise_string($relationship);
    if (is_array($by_user) && sizeof($by_user) > 0) {
        foreach ($by_user as $key => $val) {
            $by_user[$key] = (int) $val;
        }
    } else {
        $by_user = array((int) $by_user);
    }
    // Get river data
    $log_data = __get_river_from_log($by_user, $relationship, $limit, $offset);
    // River objects
    $river = new ODDDocument();
    if ($log_data) {
        foreach ($log_data as $log) {
            $event = $log->event;
            $class = $log->object_class;
            $type = $log->object_type;
            $subtype = $log->object_subtype;
            $tmp = new $class();
            $object = $tmp->getObjectFromID($log->object_id);
            $by_user_obj = get_entity($log->performed_by_guid);
            // Belts and braces
            if ($object instanceof $class) {
                $relationship_obj = NULL;
                // Handle updates of entities
                if ($object instanceof ElggEntity) {
                    $relationship_obj = new ODDRelationship(guid_to_uuid($log->performed_by_guid), $log->event, guid_to_uuid($log->object_id));
                }
                // Handle updates of metadata
                if ($object instanceof ElggExtender) {
                    $odd = $object->export();
                    $relationship_obj = new ODDRelationship(guid_to_uuid($log->performed_by_guid), $log->event, $odd->getAttribute('uuid'));
                }
                // Handle updates of relationships
                if ($object instanceof ElggRelationship) {
                    $odd = $object->export();
                    $relationship_obj = new ODDRelationship(guid_to_uuid($log->performed_by_guid), $log->event, $odd->getAttribute('uuid'));
                }
                // If we have handled it then add it to the document
                if ($relationship_obj) {
                    $relationship_obj->setPublished($log->time_created);
                    $river->addElement($relationship_obj);
                }
            }
        }
    }
    return $river;
}