qa-app-events.php 4.08 KB
Newer Older
Gideon Greenspan committed
1 2 3 4 5 6 7
<?php

/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-include/qa-app-events.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Handles the submission of events to the database (application level)


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

	if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
		header('Location: ../');
		exit;
	}

	require_once QA_INCLUDE_DIR.'qa-db-events.php';
	require_once QA_INCLUDE_DIR.'qa-app-updates.php';
Scott Vivian committed
34

Gideon Greenspan committed
35 36 37 38 39 40 41 42 43 44 45

	function qa_create_event_for_q_user($questionid, $lastpostid, $updatetype, $lastuserid, $otheruserid=null, $timestamp=null)
/*
	Add appropriate events to the database for an action performed on a question. The event of type $updatetype relates
	to $lastpostid whose antecedent question is $questionid, and was caused by $lastuserid. Pass a unix $timestamp for
	the event time or leave as null to use now. This will add an event to $questionid's and $lastuserid's streams. If
	$otheruserid is set, it will also add an notification-style event for that user, unless they are the one who did it.
*/
	{
		qa_db_event_create_for_entity(QA_ENTITY_QUESTION, $questionid, $questionid, $lastpostid, $updatetype, $lastuserid, $timestamp); // anyone who favorited the question

Gideon Greenspan committed
46
		if (isset($lastuserid) && !QA_FINAL_EXTERNAL_USERS)
Gideon Greenspan committed
47 48 49 50 51
			qa_db_event_create_for_entity(QA_ENTITY_USER, $lastuserid, $questionid, $lastpostid, $updatetype, $lastuserid, $timestamp); // anyone who favorited the user who did it

		if (isset($otheruserid) && ($otheruserid!=$lastuserid))
			qa_db_event_create_not_entity($otheruserid, $questionid, $lastpostid, $updatetype, $lastuserid, $timestamp); // possible other user to be informed
	}
Scott Vivian committed
52

Gideon Greenspan committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

	function qa_create_event_for_tags($tagstring, $questionid, $updatetype, $lastuserid, $timestamp=null)
/*
	Add appropriate events to the database for an action performed on a set of tags in $tagstring (namely, a question
	being created with those tags or having one of those tags added afterwards). The event of type $updatetype relates
	to the question $questionid, and was caused by $lastuserid. Pass a unix $timestamp for the event time or leave as
	null to use now.
*/
	{
		require_once QA_INCLUDE_DIR.'qa-util-string.php';
		require_once QA_INCLUDE_DIR.'qa-db-post-create.php';

		$tagwordids=qa_db_word_mapto_ids(array_unique(qa_tagstring_to_tags($tagstring)));
		foreach ($tagwordids as $wordid)
			qa_db_event_create_for_entity(QA_ENTITY_TAG, $wordid, $questionid, $questionid, $updatetype, $lastuserid, $timestamp);
	}
Scott Vivian committed
69

Gideon Greenspan committed
70 71 72 73 74 75 76 77 78 79 80 81

	function qa_create_event_for_category($categoryid, $questionid, $updatetype, $lastuserid, $timestamp=null)
/*
	Add appropriate events to the database for an action performed on $categoryid (namely, a question being created in
	that category or being moved to it later on), along with all of its ancestor categories. The event of type
	$updatetype relates to the question $questionid, and was caused by $lastuserid. Pass a unix $timestamp for the event
	time or leave as null to use now.
*/
	{
		if (isset($categoryid)) {
			require_once QA_INCLUDE_DIR.'qa-db-selects.php';
			require_once QA_INCLUDE_DIR.'qa-app-format.php';
Scott Vivian committed
82

Gideon Greenspan committed
83 84 85 86 87
			$categories=qa_category_path(qa_db_single_select(qa_db_category_nav_selectspec($categoryid, true)), $categoryid);
			foreach ($categories as $category)
				qa_db_event_create_for_entity(QA_ENTITY_CATEGORY, $category['categoryid'], $questionid, $questionid, $updatetype, $lastuserid, $timestamp);
		}
	}
Scott Vivian committed
88 89


Gideon Greenspan committed
90 91 92
/*
	Omit PHP closing tag to help avoid accidental output
*/