You are here

function activity_insert in Activity 6

Same name and namespace in other branches
  1. 5.4 activity.module \activity_insert()
  2. 5 activity.module \activity_insert()
  3. 5.2 activity.module \activity_insert()
  4. 5.3 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.

11 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)
commentactivity_comment in contrib/commentactivity/commentactivity.module
Implementation of hook_comment().
favorite_nodesactivity_favorite_nodes in contrib/favorite_nodesactivity/favorite_nodesactivity.module
Implementation of hook_favorite_nodes().

... See full list

File

./activity.module, line 489
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;
  }
  db_query("INSERT INTO {activity} (uid, module,  type,  operation,  created, data)\n                            VALUES (%d,  '%s',    '%s',  '%s',       %d,      '%s')", $uid, $module, $type, $operation, time(), serialize($data));
  $aid = db_last_insert_id('activity', 'aid');
  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;
}