qa-event-updates.php 5.64 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
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	File: qa-include/qa-event-updates.php
	Description: Event module for maintaining events tables


	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
*/

Scott committed
23 24 25 26 27 28
class qa_event_updates
{
	public function process_event($event, $userid, $handle, $cookieid, $params)
	{
		if (@$params['silent']) // don't create updates about silent edits, and possibly other silent events in future
			return;
Scott committed
29

Scott committed
30 31
		require_once QA_INCLUDE_DIR . 'db/events.php';
		require_once QA_INCLUDE_DIR . 'app/events.php';
Scott committed
32

Scott committed
33 34 35 36
		switch ($event) {
			case 'q_post':
				if (isset($params['parent'])) // question is following an answer
					qa_create_event_for_q_user($params['parent']['parentid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid, $params['parent']['userid']);
Scott committed
37

Scott committed
38 39 40 41
				qa_create_event_for_q_user($params['postid'], $params['postid'], null, $userid);
				qa_create_event_for_tags($params['tags'], $params['postid'], null, $userid);
				qa_create_event_for_category($params['categoryid'], $params['postid'], null, $userid);
				break;
Scott committed
42 43


Scott committed
44 45 46
			case 'a_post':
				qa_create_event_for_q_user($params['parentid'], $params['postid'], null, $userid, $params['parent']['userid']);
				break;
Scott committed
47 48


Scott committed
49
			case 'c_post':
Scott committed
50
				$keyuserids = array();
Scott committed
51

Scott committed
52
				foreach ($params['thread'] as $comment) // previous comments in thread (but not author of parent again)
Scott committed
53
				{
Scott committed
54
					if (isset($comment['userid']))
Scott committed
55 56
						$keyuserids[$comment['userid']] = true;
				}
Scott committed
57

Scott committed
58
				foreach ($keyuserids as $keyuserid => $dummy) {
Scott committed
59 60
					if ($keyuserid != $userid)
						qa_db_event_create_not_entity($keyuserid, $params['questionid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid);
Scott committed
61
				}
Scott committed
62

Scott committed
63
				switch ($params['parent']['basetype']) {
Scott committed
64
					case 'Q':
Scott committed
65
						$updatetype = QA_UPDATE_C_FOR_Q;
Scott committed
66
						break;
Scott committed
67

Scott committed
68
					case 'A':
Scott committed
69
						$updatetype = QA_UPDATE_C_FOR_A;
Scott committed
70
						break;
Scott committed
71

Scott committed
72
					default:
Scott committed
73
						$updatetype = null;
Scott committed
74 75
						break;
				}
Scott committed
76

Scott committed
77
				// give precedence to 'your comment followed' rather than 'your Q/A commented' if both are true
Scott committed
78 79 80
				qa_create_event_for_q_user($params['questionid'], $params['postid'], $updatetype, $userid,
					@$keyuserids[$params['parent']['userid']] ? null : $params['parent']['userid']);
				break;
Scott committed
81 82


Scott committed
83 84
			case 'q_edit':
				if ($params['titlechanged'] || $params['contentchanged'])
Scott committed
85
					$updatetype = QA_UPDATE_CONTENT;
Scott committed
86
				elseif ($params['tagschanged'])
Scott committed
87
					$updatetype = QA_UPDATE_TAGS;
Scott committed
88
				else
Scott committed
89
					$updatetype = null;
Scott committed
90

Scott committed
91 92
				if (isset($updatetype)) {
					qa_create_event_for_q_user($params['postid'], $params['postid'], $updatetype, $userid, $params['oldquestion']['userid']);
Scott committed
93

Scott committed
94 95 96 97
					if ($params['tagschanged'])
						qa_create_event_for_tags($params['tags'], $params['postid'], QA_UPDATE_TAGS, $userid);
				}
				break;
Scott committed
98 99


Scott committed
100 101 102
			case 'a_select':
				qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_SELECTED, $userid, $params['answer']['userid']);
				break;
Scott committed
103 104


Scott committed
105 106 107 108
			case 'q_reopen':
			case 'q_close':
				qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CLOSED, $userid, $params['oldquestion']['userid']);
				break;
Scott committed
109 110


Scott committed
111 112 113 114
			case 'q_hide':
				if (isset($params['oldquestion']['userid']))
					qa_db_event_create_not_entity($params['oldquestion']['userid'], $params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
				break;
Scott committed
115 116


Scott committed
117 118 119
			case 'q_reshow':
				qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldquestion']['userid']);
				break;
Scott committed
120 121


Scott committed
122 123 124 125
			case 'q_move':
				qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CATEGORY, $userid, $params['oldquestion']['userid']);
				qa_create_event_for_category($params['categoryid'], $params['postid'], QA_UPDATE_CATEGORY, $userid);
				break;
Scott committed
126 127


Scott committed
128 129 130 131
			case 'a_edit':
				if ($params['contentchanged'])
					qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']);
				break;
Scott committed
132 133


Scott committed
134 135 136 137
			case 'a_hide':
				if (isset($params['oldanswer']['userid']))
					qa_db_event_create_not_entity($params['oldanswer']['userid'], $params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
				break;
Scott committed
138 139


Scott committed
140 141 142
			case 'a_reshow':
				qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldanswer']['userid']);
				break;
Scott committed
143 144


Scott committed
145 146 147 148
			case 'c_edit':
				if ($params['contentchanged'])
					qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldcomment']['userid']);
				break;
Scott committed
149 150


Scott committed
151 152 153 154 155 156
			case 'a_to_c':
				if ($params['contentchanged'])
					qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']);
				else
					qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_TYPE, $userid, $params['oldanswer']['userid']);
				break;
Scott committed
157 158


Scott committed
159 160 161 162
			case 'c_hide':
				if (isset($params['oldcomment']['userid']))
					qa_db_event_create_not_entity($params['oldcomment']['userid'], $params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
				break;
Scott committed
163 164


Scott committed
165 166 167
			case 'c_reshow':
				qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldcomment']['userid']);
				break;
Scott committed
168 169
		}
	}
Scott committed
170
}