events.php 3.93 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	File: qa-include/qa-app-events.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.

	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;
	}

Scott committed
28
	require_once QA_INCLUDE_DIR.'db/events.php';
Scott committed
29
	require_once QA_INCLUDE_DIR.'app/updates.php';
Scott committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57


	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

		if (isset($lastuserid) && !QA_FINAL_EXTERNAL_USERS)
			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
	}


	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.
*/
	{
Scott committed
58
		require_once QA_INCLUDE_DIR.'util/string.php';
Scott committed
59
		require_once QA_INCLUDE_DIR.'db/post-create.php';
Scott committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

		$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);
	}


	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)) {
Scott committed
76
			require_once QA_INCLUDE_DIR.'db/selects.php';
Scott committed
77
			require_once QA_INCLUDE_DIR.'app/format.php';
Scott committed
78 79 80 81 82 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);
		}
	}


/*
	Omit PHP closing tag to help avoid accidental output
Gideon Greenspan committed
88
*/