Last active
December 12, 2015 01:48
-
-
Save mrclay/4693673 to your computer and use it in GitHub Desktop.
On an Elgg comment, bump the original "create" river item to the top instead of adding a separate river item.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
elgg_register_plugin_hook_handler('creating', 'river', function ($h, $t, $v, $p) { | |
$time = time(); | |
// Bump "create" river item to top | |
// @todo should bump other action_types? | |
$dbprefix = elgg_get_config('dbprefix'); | |
update_data(" | |
UPDATE {$dbprefix}river | |
SET posted = $time | |
WHERE action_type = 'create' | |
AND object_guid = {$v['object_guid']} | |
"); | |
update_entity_last_action($v['object_guid'], $time); | |
// cancel create comment action | |
return false; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Note: This is for the ElggComment patch https://github.com/Elgg/Elgg/pull/365/files | |
*/ | |
elgg_register_plugin_hook_handler('creating', 'river', function ($h, $t, $v, $p) { | |
$time = time(); | |
if ($v['type'] !== 'object' || $v['subtype'] !== 'comment') { | |
return true; | |
} | |
$comment = get_entity($v['object_guid']); | |
/* @var \ElggComment $comment */ | |
if (!$comment) { | |
return true; | |
} | |
$object_guid = $comment->container_guid; | |
if (!$object_guid) { | |
return true; | |
} | |
// Bump "create" river item to top | |
// @todo should bump other action_types? | |
$dbprefix = elgg_get_config('dbprefix'); | |
update_data(" | |
UPDATE {$dbprefix}river | |
SET posted = $time | |
WHERE action_type = 'create' | |
AND object_guid = $object_guid | |
"); | |
update_entity_last_action($object_guid, $time); | |
// cancel create comment action | |
return false; | |
}); |
We definitely need a new column. I'm working around by generating the timestamp from the river item object time_created if the river item is a "create". :/
<?php
if ($river_item->action_type === 'create') {
if ($river_obj = $river_item->getObjectEntity()) {
$timestamp = elgg_view_friendly_time($river_obj->time_created);
}
} else {
$timestamp = elgg_view_friendly_time($river_item->getPostedTime());
}
Another hack: bump the river item id and ORDER BY id DESC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not really feeling this, unfortunately, because this makes the river lie about when items were created.