diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-07-15 10:49:19 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-07-15 10:49:19 +0000 |
commit | d9a7f8ee70bdd5a5a596a5bb745c8d11391105e9 (patch) | |
tree | 342786130bc41bfb48065e4e72c661ca9486e7e8 | |
parent | dea81fd61b6c04fda3dabc0360de312197c80db7 (diff) | |
download | elgg-d9a7f8ee70bdd5a5a596a5bb745c8d11391105e9.tar.gz elgg-d9a7f8ee70bdd5a5a596a5bb745c8d11391105e9.tar.bz2 |
Using ElggRiverStatement. Plugin writers update your views! Refs #135.
git-svn-id: https://code.elgg.org/elgg/trunk@1422 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/lib/river.php | 185 | ||||
-rw-r--r-- | mod/groups/views/default/river/ElggRelationship/create.php | 24 | ||||
-rw-r--r-- | mod/profile/views/default/river/ElggUser/update.php | 12 |
3 files changed, 187 insertions, 34 deletions
diff --git a/engine/lib/river.php b/engine/lib/river.php index d9578a195..0d1a9e1b5 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -12,6 +12,139 @@ */ /** + * @class ElggRiverComponent Component passed to river views. + * This class represents all the necessary information for constructing a river article - this includes: + * - The user who performed the action + * - The object the action was performed on + * - The event performed + * - Any related objects + * + * @author Marcus Povey + */ + class ElggRiverStatement + { + /** + * Object in question (may be a relationship event or a metadata event). In the case of a relationship this is an array containing + * the objects that the relationship is established between. in the case of metadata it consists of + */ + private $object; + + /** + * The log event (create / update etc). + */ + private $log_event; + + /** + * The subject who created this event (the user). + */ + private $subject; + + /** + * Create the statement. + * + * @param ElggUser $subject The subject (the user who created this) + * @param string $event The event. + * @param mixed $object The object, either an ElggEntity or an associated array + * ('subject' => ElggEntity, 'relationship' => relationship, 'object' => ElggEntity) or + * ('subject' => ElggEntity, 'object' => ElggEntity) + */ + public function __construct(ElggUser $subject, $event, $object) + { + $this->setSubject($subject); + $this->setEvent($event); + $this->setObject($object); + } + + /** + * Set the subject. + * + * @param ElggEntity $subject The subject. + */ + public function setSubject(ElggEntity $subject) { $this->subject = $subject; } + + /** + * Return the user that created this event - the subject of the statement. + * @return ElggUser + */ + public function getSubject() { return $this->subject; } + + /** + * Return the user who initiated this event (an alias of getSubject(); + * @return ElggUser + */ + public function getByUser() { return $this->getSubject(); } + + /** + * Set the object. + * + * @param mixed $object ElggEntity or array. + * @return bool + */ + public function setObject($object) + { + if (is_array($object)) + { + /*if ( + (!isset($object['subject'])) || + ( + (!($object['subject'] instanceof ElggEntity)) || + (!($object['subject'] instanceof ElggExtender)) + ) + ) + return false; + + if ( (!isset($object['object'])) || (!($object['object'] instanceof ElggEntity)) ) + return false; + */ + $this->object = $object; + + return true; + } + else if ($object instanceof ElggEntity) + { + $this->object = $object; + + return true; + } + + return false; + } + + /** + * Return the accusitive object of the statement. This is either an object in isolation, or an array containing + * the parts of the statement. + * + * E.g. + * + * For the statement "User X created object Y", this function will return object Y. + * + * However, for a statement "User X is now friends with User Y" you are essentially making the system level statement + * "User X has created a relationship of type friend between Y and Z" (where X is almost always going to be the same as Y).. therefore + * this function will return a three element array associative containing the relationship type, plus the elements the relationship + * is between ['subject', 'relationship', 'object']. + * + * Also, if you are updating a bit of metadata about an object this a two element array: ['subject', 'object']. + * Which is making the statement "User X updated some Metadata (subject) about object (object) Y + * + * @return mixed + */ + public function getObject() { return $this->object; } + + /** + * Set the log event. + * + * @param string $event The event - e.g. "update". + */ + public function setEvent($event) { $this->log_event = $event; } + + /** + * Return the event in the system log that this action relates to (eg, "create", "update"). + * @return string + */ + public function getEvent() { return $this->log_event; } + } + + /** * Extract a list of river events from the current system log. * This function retrieves the objects from the system log and will attempt to render * the view "river/CLASSNAME/EVENT" where CLASSNAME is the class of the object the system event is referring to, @@ -83,11 +216,25 @@ // See if anything can handle it $tam = ""; - // test if view exist and if so
- //if (isset($by_user_obj) && $by_user_obj instanceof ElggUser) {
- //} else {
- $by_user_obj = get_entity($log->performed_by_guid);
- //}
+ // Construct the statement + $by_user_obj = get_entity($log->performed_by_guid); + $statement_object = $object; + if ($object instanceof ElggRelationship) { + + $statement_object = array( + 'subject' => get_entity($object->guid_one), + 'relationship' => $object->relationship, + 'object' => get_entity($object->guid_two) + ); + } else if ($object instanceof ElggExtender) { + $statement_object = array( + 'subject' => $object, + 'object' => get_entity($object->entity_guid) + ); + } + $statement = new ElggRiverStatement($by_user_obj, $event, $statement_object); +
+
if ($object instanceof ElggEntity) {
$subtype = $object->getSubtype();
} else {
@@ -98,24 +245,22 @@ }
if (!empty($subtype) && elgg_view_exists("river/{$subtype}/{$event}")) {
- $tam = elgg_view("river/{$subtype}/$event", array(
- 'performed_by' => $by_user_obj,
- 'log_entry' => $log,
- 'entity' => $object
+ $tam = elgg_view("river/{$subtype}/$event", array( + 'statement' => $statement
));
- } else { + } else if (elgg_view_exists("river/$class/$event")) { $tam = elgg_view("river/$class/$event", array( - 'performed_by' => $by_user_obj, - 'log_entry' => $log, - 'entity' => $object + 'statement' => $statement ));
}
if (!empty($tam)) {
$tam = elgg_view("river/wrapper",array(
- 'entry' => $tam,
- 'log' => $log,
- 'entity' => $object));
+ 'entry' => $tam, + 'time' => $log->time_created, + 'event' => $event, + 'statement' => $statement + ));
} if ($tam) @@ -224,7 +369,13 @@ // Handle updates of relationships if ($object instanceof ElggRelationship) { - $relationship_obj = $object->export(); // I figure this is what you're actually interested in in this instance. + $odd = $object->export(); + $relationship_obj = new ODDRelationship( + guid_to_uuid($log->performed_by_guid), + $log->event, + $odd->getAttribute('uuid') + ); + //$relationship_obj = $object->export(); // I figure this is what you're actually interested in in this instance. } // If we have handled it then add it to the document diff --git a/mod/groups/views/default/river/ElggRelationship/create.php b/mod/groups/views/default/river/ElggRelationship/create.php index b302097bc..169a9b2aa 100644 --- a/mod/groups/views/default/river/ElggRelationship/create.php +++ b/mod/groups/views/default/river/ElggRelationship/create.php @@ -10,31 +10,31 @@ * @link http://elgg.com/ */ - $performed_by = $vars['performed_by']; - $log_entry = $vars['log_entry']; - $object = $vars['entity']; + $statement = $vars['statement']; - // Find out what type of relationship we're dealing with (will only display a few) - if ($object instanceof ElggRelationship) + $performed_by = $statement->getSubject(); + $event = $statement->getEvent(); + $object = $statement->getObject(); + + if (is_array($object)) { - - switch ($object->relationship) + switch ($object['relationship']) { // Friending case 'member' : - - $user = get_entity($object->guid_one); - $group = get_entity($object->guid_two); - + $user = $object['subject']; + $group = $object['object']; + if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) { echo "<a href=\"{$user->getURL()}\">{$user->name}</a> "; echo elgg_echo("groups:river:member"); echo " '<a href=\"{$group->getURL()}\">{$group->title}</a>'"; } - + break; } } + ?>
\ No newline at end of file diff --git a/mod/profile/views/default/river/ElggUser/update.php b/mod/profile/views/default/river/ElggUser/update.php index c9b710512..36f775991 100644 --- a/mod/profile/views/default/river/ElggUser/update.php +++ b/mod/profile/views/default/river/ElggUser/update.php @@ -1,10 +1,12 @@ <?php
-
- $performed_by = $vars['performed_by'];
+ + $statement = $vars['statement']; + + $performed_by = $statement->getSubject(); + + $url = "<a href=\"{$performed_by->getURL()}\">{$performed_by->name}</a>"; + $string = sprintf(elgg_echo("profile:river:update"),$url); - $url = "<a href=\"{$performed_by->getURL()}\">{$performed_by->name}</a>";
- $string = sprintf(elgg_echo("profile:river:update"),$url);
-
?>
<?php echo $string; ?>
\ No newline at end of file |