Commit 82c845d9 authored by Nathan Lewis's avatar Nathan Lewis Committed by Aaron Wells
Browse files

Reverting activity stream patches (Bug #1316324)

Content from the following commits was reverted:

Patch 3327: 7a7673c0
"Add activity stream block (Bug #1316324)"

Patch 3374: c538c745
"Add likes to activity streams (Bug #1321480)"

Patch 3432: 121e9027
"Add new parameters to the get_activity_body function (Bug #1328729)"

Patch 3434: 2e47dfb1


"Improvements to activity stream body helper (Bug #1328760)"

Change-Id: Id03c156a7c8c016c8dc76c998a73310ea57fe0a5
Signed-off-by: default avatarNathan Lewis <nathan.lewis@totaralms.com>
parent b25d16e4
......@@ -127,10 +127,8 @@ function edit_comment_submit(Pieform $form, $values) {
require_once('activity.php');
$data = (object) array(
'usr' => $comment->get('author'),
'objecttype' => ActivityType::OBJECTTYPE_VIEW,
'objectid' => $viewid,
'additionalid' => $comment->get('id'),
'commentid' => $comment->get('id'),
'viewid' => $viewid,
);
activity_occurred('feedback', $data, 'artefact', 'comment');
......
......@@ -105,9 +105,3 @@ To see %s online, follow this link:
$string['artefactdefaultpermissions'] = 'Default comment permission';
$string['artefactdefaultpermissionsdescription'] = 'The selected artefact types will have comments enabled on creation. Users can override these settings for individual artefacts.';
// Activity stream helper messages.
$string['activitystreamcomment'] = array(
0 => '%2$s left a comment on %3$s %4$s "%5$s": %6$s',
1 => '%2$s left %1$d comments on %3$s %4$s "%5$s": %6$s'
);
......@@ -61,7 +61,6 @@ class PluginArtefactComment extends PluginArtefact {
'admin' => 0,
'delay' => 0,
'allownonemethod' => 1,
'onlyapplyifwatched' => 0,
'defaultmethod' => 'email',
)
);
......@@ -1006,10 +1005,8 @@ function delete_comment_submit(Pieform $form, $values) {
if ($deletedby != 'owner' && $comment->get('owner') != $USER->get('id')) {
// Notify owner
$data = (object) array(
'usr' => $comment->get('author'),
'objecttype' => ActivityType::OBJECTTYPE_VIEW,
'objectid' => $view->get('id'),
'additionalid' => $comment->get('id'),
'commentid' => $comment->get('id'),
'viewid' => $view->get('id'),
);
activity_occurred('feedback', $data, 'artefact', 'comment');
}
......@@ -1191,17 +1188,10 @@ function add_feedback_form_submit(Pieform $form, $values) {
}
require_once('activity.php');
$data->usr = $comment->get('author');
if ($artefact) {
$data->objecttype = ActivityType::OBJECTTYPE_ARTEFACT;
$data->objectid = $data->onartefact;
}
else {
$data->objecttype = ActivityType::OBJECTTYPE_VIEW;
$data->objectid = $data->onview;
}
$data->additionalid = $comment->get('id');
$data = (object) array(
'commentid' => $comment->get('id'),
'viewid' => $view->get('id')
);
activity_occurred('feedback', $data, 'artefact', 'comment');
if (isset($moderatemsg)) {
......@@ -1239,19 +1229,21 @@ function add_feedback_form_cancel_submit(Pieform $form) {
));
}
class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin implements ActivityStreamable {
class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin {
protected $viewid;
protected $commentid;
/**
* @param array $data Parameters:
* - objecttype (ActivityType::OBJECTTYPE_VIEW or ActivityType::OBJECTTYPE_ARTEFACT)
* - objectid (view or artefact id int)
* - usr (user id int
* - additionalid (comment id int)
* - viewid (int)
* - commentid (int)
*/
public function __construct($data, $cron=false) {
parent::__construct($data, $cron);
$comment = new ArtefactTypeComment($data->additionalid);
$comment = new ArtefactTypeComment($this->commentid);
$this->overridemessagecontents = true;
if ($onartefact = $comment->get('onartefact')) { // feedback on artefact
......@@ -1262,7 +1254,7 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin implements
$userid = $artefactinstance->get('owner');
}
if (empty($this->url)) {
$this->url = 'artefact/artefact.php?artefact=' . $onartefact . '&view=' . $this->objectid;
$this->url = 'artefact/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid;
}
}
else { // feedback on view.
......@@ -1275,7 +1267,6 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin implements
$this->url = 'view/view.php?id=' . $onview;
}
}
if (empty($userid)) {
return;
}
......@@ -1340,10 +1331,6 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin implements
);
}
public function get_required_parameters() {
return array('objecttype', 'objectid', 'usr', 'additionalid');
}
public function get_plugintype(){
return 'artefact';
}
......@@ -1352,66 +1339,7 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin implements
return 'comment';
}
public static function get_activity_body($activity, $streamtype, $viewer, $owner, $group, $institution) {
$helperinfo = new stdClass();
$subactivity = $activity->subactivity[0];
$comment = new ArtefactTypeComment($subactivity->additionalid);
$helperinfo->activity = $activity;
$helperinfo->foruserid = $viewer;
$helperinfo->activityidentifier = 'activitystreamcomment';
$helperinfo->activitysection = 'artefact.comment';
$helperinfo->objecttypename = ActivityType::get_object_type_name($activity->objecttype, $activity->objectid);
$helperinfo->snippet = $comment->get('description');
$artefactid = $comment->get('onartefact');
$viewid = $comment->get('onview');
if ($artefactid) {
self::set_helperinfo_with_artefact($helperinfo, $artefactid);
}
else {
self::set_helperinfo_with_view($helperinfo, $viewid);
}
return ActivityStreamHelper::get_standard_activity_body($helperinfo);
}
/**
* Configure the abhelper for a given artefact.
*
* @param int $artefactid
*/
private static function set_helperinfo_with_artefact($helperinfo, $artefactid) {
$artefact = get_record('artefact', 'id', $artefactid);
$artefactowner = reset(artefact_get_owner_info(array($artefactid)));
$helperinfo->ownername = $artefactowner->name;
$helperinfo->ownerurl = $artefactowner->url;
$owneruserid = $artefact->owner;
if ($owneruserid) {
$helperinfo->owneruserid = $owneruserid;
}
$helperinfo->objecttitle = $artefact->title;
$helperinfo->objecturl = null; // TODO Link to artefact in future patch.
}
/**
* Prepare the abhelper for a given view.
*
* @param int $viewid
*/
private static function set_helperinfo_with_view($helperinfo, $viewid) {
$view = new View($viewid);
$owneruserid = $view->get('owner');
$groupid = $view->get('group');
if ($owneruserid) {
$helperinfo->owneruserid = $owneruserid;
}
else if ($groupid) {
$helperinfo->ownername = $view->formatted_owner();
$helperinfo->ownerurl = get_config('wwwroot') . 'group/view.php?id=' . $groupid;
}
$helperinfo->objecttitle = $view->get('title');
$helperinfo->objecturl = $view->get_url();
public function get_required_parameters() {
return array('commentid', 'viewid');
}
}
/**
* Javascript for the Activity Stream
* @source: http://gitorious.org/mahara/mahara
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
//self executing function for namespacing code
(function( ActivityStreamManager, $, undefined ) {
function init() {
$('.as-actionlike').click(function(event) {
var link = $(this);
sendjsonrequest(
config.wwwroot + 'blocktype/activitystream/likes/like.json.php',
{'activityid': link.attr('activityid'), 'action': link.attr('action')},
'GET',
function(reply) {
linkid = link.attr('id').replace('actionlike', '');
$('#totallikes' + linkid + '.as-totallikes').replaceWith(reply.totallikes);
$('#actionlike' + linkid + '.as-actionlike').html(reply.newactiontext);
$('#actionlike' + linkid + '.as-actionlike').attr('action', reply.newaction);
}
);
});
}
$(document).ready(function() {
init();
});
}( window.ActivityStreamManager = window.ActivityStreamManager || {}, jQuery ));
\ No newline at end of file
<?php
/**
* Creative Commons License Block type for Mahara
*
* @package mahara
* @subpackage blocktype-activitystream
* @author Nathan Lewis <nathan.lewis@totaralms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
defined('INTERNAL') || die();
$string['activity'] = 'activity';
$string['activitystream'] = 'Activity stream';
$string['description'] = 'Show history of activities';
$string['like'] = 'Like';
$string['likethisobjecttypename'] = 'Like this %s';
$string['noactivities'] = 'There are no activities to display in this stream. This activity stream will be filled with
relevant activities as they occur.';
$string['noactivitieshomestream'] = 'There are no activities to display in your home stream. You may need to change
some notifications to "Home stream" so they will be displayed here. <a href="%s">Edit your notification settings</a>.';
$string['numberoflikes'] = array(
0 => '%d person likes this',
1 => '%d people like this'
);
$string['title'] = 'Activity stream';
$string['unlike'] = 'Unlike';
$string['unlikethisobjecttypename'] = 'Unlike this %s';
This diff is collapsed.
<?php
/**
*
* @package mahara
* @subpackage blocktype-activitystream
* @author Nathan Lewis <nathan.lewis@totaralms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
defined('INTERNAL') || die();
require_once(get_config('libroot') . 'activity.php');
class Likes {
/**
* Get the information required to uniquely identify the activity or object it is based on.
*
* Likes on views and artefacts need to go on the view or artefact itself, not the activity.
*
* System activities and subactivities may have different meanings for 'objectid'. Because of this, we
* put the like on the activity itself.
*
* TODO: Likes on group, institution and interaction activities are being treated the same as system
* activities. This means that likes on these activities will be put on the activities. Someone may
* want to change this behaviour in the future, particularly relating to forums (interactions).
*
* @param object $activity
* @return object
*/
private static function get_related_object($activity) {
$object = new stdClass();
if ($activity->objecttype == ActivityType::OBJECTTYPE_VIEW ||
$activity->objecttype == ActivityType::OBJECTTYPE_ARTEFACT) {
$object->objecttype = $activity->objecttype;
$object->objectid = $activity->objectid;
}
else {
$object->objecttype = ActivityType::OBJECTTYPE_ACTIVITY;
$object->objectid = $activity->id;
}
return $activity;
}
/**
* Creates an html string stating how many likes the activity or object it is based on has.
*
* @param object $activity
* @return html string
*/
public static function total_likes($activity) {
$object = self::get_related_object($activity);
$totallikes = count_records('likes',
'objecttype', $object->objecttype,
'objectid', $object->objectid);
$totallikesstring = get_string("numberoflikes", 'blocktype.activitystream', $totallikes);
return "<div class='as-totallikes' id='totallikes{$activity->objecttype}_{$activity->objectid}'>{$totallikesstring}</div>";
}
/**
* Creates an html link which can be clicked to add or remove a like from the activity or object it is based on.
*
* @param object $activity
* @return html string
*/
public static function action_link($activity) {
global $USER;
$baseobject = self::get_related_object($activity);
$isliked = record_exists('likes',
'objecttype', $baseobject->objecttype,
'objectid', $baseobject->objectid,
'usr', $USER->get('id'));
$action = $isliked ? 'unlike' : 'like';
$label = self::action_label($action, $activity);
return "<a class='as-actionlike' activityid='{$activity->id}' " .
"id='actionlike{$activity->objecttype}_{$activity->objectid}' action='{$action}'>$label</a>";
}
/**
* Get the string indicating the action that can be performed on the base activity or object.
*
* @param string $action 'like' or 'unlike'
* @param object $activity
* @return string
*/
public static function action_label($action, $activity) {
$baseobject = self::get_related_object($activity);
$objecttypename = ActivityType::get_object_type_name($baseobject->objecttype, $baseobject->objectid);
if ($objecttypename) {
return get_string($action . 'thisobjecttypename', 'blocktype.activitystream', $objecttypename);
}
else {
return get_string($action, 'blocktype.activitystream');
}
}
/**
* Add a like to the activity or object it is based on, for the given user.
*
* @param object $activity
* @param int $userid
*/
public static function add($activity, $userid) {
$object = self::get_related_object($activity);
// Check if it already exists.
$recordexists = record_exists('likes',
'objecttype', $object->objecttype,
'objectid', $object->objectid,
'usr', $userid);
if (!$recordexists) {
$like = new stdClass();
$like->objecttype = $object->objecttype;
$like->objectid = $object->objectid;
$like->usr = $userid;
$like->ctime = db_format_timestamp(time());
insert_record('likes', $like);
}
}
/**
* Remove a like from the activity or object it is based on, for the given user.
*
* @param object $activity
* @param int $userid
*/
public static function remove($activity, $userid) {
$object = self::get_related_object($activity);
// Remove a like record (doesn't matter if it doesn't exist).
delete_records('likes',
'objecttype', $object->objecttype,
'objectid', $object->objectid,
'usr', $userid);
}
}
<?php
/**
*
* @package mahara
* @subpackage blocktype-activitystream
* @author Nathan Lewis <nathan.lewis@totaralms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
safe_require('blocktype', 'activitystream');
$activityid = param_integer('activityid');
$action = param_alpha('action');
$activity = get_record('activity', 'id', $activityid);
if ($action == 'like') {
Likes::add($activity, $USER->get('id'));
$newaction = 'unlike';
}
else {
Likes::remove($activity, $USER->get('id'));
$newaction = 'like';
}
$totallikes = Likes::total_likes($activity);
$newactiontext = Likes::action_label($newaction, $activity);
// Send a reply with the new action and likes total.
json_reply(false, array('newaction' => $newaction, 'newactiontext' => $newactiontext, 'totallikes' => $totallikes));
<?php
/**
* @package mahara
* @subpackage tests
* @author Nathan Lewis <nathan.lewis@totaralms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*/
require_once(get_config('docroot') . '/blocktype/activitystream/lib.php');
class ArtefactAccessTest extends MaharaUnitTest {
private $viewer;
private $other;
private $friend12;
private $friend21;
private $group;
private $institution;
private $conditionstotest;
private $conditionstotestknownfriends;
const OBJECT_ID_PUBLIC = 1001;
const OBJECT_ID_LOGGEDIN = 1002;
const OBJECT_ID_FRIEND12 = 1003;
const OBJECT_ID_FRIEND21 = 1004;
const OBJECT_ID_USR = 1005;
const OBJECT_ID_GROUP = 1006;
// const OBJECT_ID_MYGROUPS = 1007;
const OBJECT_ID_INSTITUTION = 1008;
private $objectids = array(
self::OBJECT_ID_PUBLIC,
self::OBJECT_ID_LOGGEDIN,
self::OBJECT_ID_FRIEND12,
self::OBJECT_ID_FRIEND21,
self::OBJECT_ID_USR,
self::OBJECT_ID_GROUP,
// self::OBJECT_ID_MYGROUPS,
self::OBJECT_ID_INSTITUTION
);
private $testcases = array(
array('public', null, array(self::OBJECT_ID_PUBLIC => 1)),
array('loggedin', null, array(self::OBJECT_ID_LOGGEDIN => 1)),
array('friend12', null, array(self::OBJECT_ID_FRIEND12 => 1)),
array('friend21', null, array(self::OBJECT_ID_FRIEND21 => 1)),
array('usr', null, array(self::OBJECT_ID_USR => 1)),
array('group', null, array(self::OBJECT_ID_GROUP => 1)),
// array('mygroups', null, array(self::OBJECT_ID_GROUP => 1)),
array('institution', null, array(self::OBJECT_ID_INSTITUTION => 1)),
array('public', true, array(self::OBJECT_ID_PUBLIC => 1)),
array('loggedin', true, array(self::OBJECT_ID_LOGGEDIN => 1)),
array('friends', true, array(self::OBJECT_ID_FRIEND12 => 1, self::OBJECT_ID_FRIEND21 => 1)),
array('usr', true, array(self::OBJECT_ID_USR => 1)),
array('group', true, array(self::OBJECT_ID_GROUP => 1)),
// array('mygroups', true, array(self::OBJECT_ID_MYGROUPS => 1)),
array('institution', true, array(self::OBJECT_ID_INSTITUTION => 1)),
);
/**
* Shared setUp method.
*/
public function setUp() {
parent::setUp();
$this->institution = $this->create_test_institution(array('name' => 'testinstitution'));
// Other user.
$this->other = $this->create_test_user((object)array(
'username' => 'other',
'email' => 'other@localhost',
'firstname' => 'other',
'lastname' => 'other',
));
// Friend12.
$this->friend12 = $this->create_test_user((object)array(
'username' => 'friend12',
'email' => 'friend12@localhost',
'firstname' => 'friend12',
'lastname' => 'friend12',
));
// Friend21.
$this->friend21 = $this->create_test_user((object)array(
'username' => 'friend21',
'email' => 'friend21@localhost',
'firstname' => 'friend21',
'lastname' => 'friend21',
));
// Viewer.
$this->viewer = $this->create_test_user((object)array(
'username' => 'viewer',
'email' => 'viewer@localhost',
'firstname' => 'viewer',
'lastname' => 'viewer',
), 'testinstitution');
// They are a member of a group.
$this->group = $this->create_test_group(array(
'name' => 'test',
'grouptype' => 'standard',
'members' => array($this->viewer => 'member')
));
// Create two friend records so that they can be tested individually.
execute_sql("INSERT INTO {usr_friend} (usr1, usr2, ctime) VALUES ({$this->viewer}, {$this->friend21}, NOW())");
execute_sql("INSERT INTO {usr_friend} (usr2, usr1, ctime) VALUES ({$this->viewer}, {$this->friend12}, NOW())");
// Public.
execute_sql("INSERT INTO {artefact} (id, artefacttype, container, owner, title, ctime, mtime, atime, authorname)
VALUES (" . self::OBJECT_ID_PUBLIC . ", 'html', 0, {$this->other}, 'artefactaccesstest', NOW(), NOW(), NOW(), '')");
execute_sql("INSERT INTO {artefact_access} (artefact, accesstype, ctime)
VALUES (" . self::OBJECT_ID_PUBLIC . ", 'public', NOW())");
// Loggedin.
execute_sql("INSERT INTO {artefact} (id, artefacttype, container, owner, title, ctime, mtime, atime, authorname)
VALUES (" . self::OBJECT_ID_LOGGEDIN . ", 'html', 0, {$this->other}, 'artefactaccesstest', NOW(), NOW(), NOW(), '')");
execute_sql("INSERT INTO {artefact_access} (artefact, accesstype, ctime)
VALUES (" . self::OBJECT_ID_LOGGEDIN . ", 'loggedin', NOW())");
// Friends12.
execute_sql("INSERT INTO {artefact} (id, artefacttype, container, owner, title, ctime, mtime, atime, authorname)
VALUES (" . self::OBJECT_ID_FRIEND12 . ", 'html', 0, {$this->friend12}, 'artefactaccesstest', NOW(), NOW(), NOW(), '')");
execute_sql("INSERT INTO {artefact_access} (artefact, accesstype, ctime)
VALUES (" . self::OBJECT_ID_FRIEND12 . ", 'friends', NOW())");
// Friends21.
execute_sql("INSERT INTO {artefact} (id, artefacttype, container, owner, title, ctime, mtime, atime, authorname)
VALUES (" . self::OBJECT_ID_FRIEND21 . ", 'html', 0, {$this->friend21}, 'artefactaccesstest', NOW(), NOW(), NOW(), '')");
execute_sql("INSERT INTO {artefact_access} (artefact, accesstype, ctime)
VALUES (" . self::OBJECT_ID_FRIEND21 . ", 'friends', NOW())");
// Usr.
execute_sql("INSERT INTO {artefact} (id, artefacttype, container, owner, title, ctime, mtime, atime, authorname)
VALUES (" . self::OBJECT_ID_USR . ", 'html', 0, {$this->other}, 'artefactaccesstest', NOW(), NOW(), NOW(), '')");
execute_sql("INSERT INTO {artefact_access} (artefact, usr, ctime)
VALUES (" . self::OBJECT_ID_USR . ", {$this->viewer}, NOW())");