Skip to content

Instantly share code, notes, and snippets.

@mrclay
Last active December 12, 2015 01:48
Show Gist options
  • Save mrclay/4693673 to your computer and use it in GitHub Desktop.
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.
<?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;
});
<?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;
});
@ewinslow
Copy link

ewinslow commented Feb 1, 2013

Not really feeling this, unfortunately, because this makes the river lie about when items were created.

@mrclay
Copy link
Author

mrclay commented Feb 1, 2013

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". :/

@mrclay
Copy link
Author

mrclay commented Feb 1, 2013

<?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());
}

@mrclay
Copy link
Author

mrclay commented Feb 1, 2013

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