You are here

function activity_insert in Activity 5.4

Same name and namespace in other branches
  1. 5 activity.module \activity_insert()
  2. 5.2 activity.module \activity_insert()
  3. 5.3 activity.module \activity_insert()
  4. 6 activity.module \activity_insert()

API function

Insert an activity record. This gets called by modules wishing to record their activities.

Parameters

$module : The name of the module that is doing the recording, eg. 'node'.

$type : Module's can track more than one type of activity. For example, the nodeactivity module tracks activities for each content type separately. This should be an identifier for the calling module to use.

14 calls to activity_insert()
ActivityAPITest::testGetActivity1 in tests/ActivityAPITests.test
Test activity_get_activity activity_get_activity($uids = ACTIVITY_ALL, $filters = NULL, $limit = NULL, $tablesort_headers = NULL)
ActivityAPITest::testGetActivity2 in tests/ActivityAPITests.test
ActivityAPITest::testInsertActivity in tests/ActivityAPITests.test
function activity_insert($module, $type, $operation, $data, $target_users_roles)
buddylist2activity_buddy_api in contrib/buddylist2activity/buddylist2activity.module
Implementation of hook_buddy_api().
buddylistactivity_buddylist in contrib/buddylistactivity/buddylistactivity.module
Implementation of hook_buddylist_api(). $arg[0] = operation $arg[1] = user being added/removed $arg[2] = user doing the add/remove

... See full list

File

./activity.module, line 390
activity.module

Code

function activity_insert($uid, $module, $type, $operation, $data, $target_users_roles) {

  // check time limit, ignore activity if within the limit
  $result = db_query("SELECT COUNT(*) FROM {activity} WHERE uid = %d AND module = '%s' AND type = '%s' AND operation = '%s' AND data = '%s' AND created >= %d", $uid, $module, $type, $operation, serialize($data), time() - variable_get('activity_time_limit', 30));
  if (db_fetch_object($result)->count != 0) {
    return FALSE;
  }
  $aid = db_next_id('activity');
  db_query("INSERT INTO {activity} (aid, uid,  module,  type,  operation,  created, data)\n                            VALUES (%d,  %d,   '%s',    '%s',  '%s',       %d,      '%s')", $aid, $uid, $module, $type, $operation, time(), serialize($data));
  foreach ($target_users_roles as $target_uid => $role) {
    db_query("INSERT INTO {activity_targets} (aid, target_uid, target_role) VALUES (%d, %d, '%s')", $aid, $target_uid, $role);
  }
  $activity = array(
    'aid' => $aid,
    'uid' => $uid,
    'module' => $module,
    'type' => $type,
    'operation' => $operation,
    'data' => $data,
    'target_user_roles' => $target_users_roles,
  );

  // Invoke activityapi
  activity_invoke_activityapi($activity, 'insert');
  return $aid;
}