qa-app-favorites.php 2.34 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-favorites.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Handles favoriting and unfavoriting (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 34 35 36 37 38 39 40 41
	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;
	}


	function qa_user_favorite_set($userid, $handle, $cookieid, $entitytype, $entityid, $favorite)
/*
	If $favorite is true, set $entitytype and $entityid to be favorites of $userid with $handle and $cookieid, otherwise
	remove them from its favorites list. Handles event reporting.
*/
	{
		require_once QA_INCLUDE_DIR.'qa-db-favorites.php';
		require_once QA_INCLUDE_DIR.'qa-app-limits.php';
		require_once QA_INCLUDE_DIR.'qa-app-updates.php';
Scott Vivian committed
42

Gideon Greenspan committed
43 44 45 46
		if ($favorite)
			qa_db_favorite_create($userid, $entitytype, $entityid);
		else
			qa_db_favorite_delete($userid, $entitytype, $entityid);
Scott Vivian committed
47

Gideon Greenspan committed
48 49 50 51 52
		switch ($entitytype) {
			case QA_ENTITY_QUESTION:
				$action=$favorite ? 'q_favorite' : 'q_unfavorite';
				$params=array('postid' => $entityid);
				break;
Scott Vivian committed
53

Gideon Greenspan committed
54 55 56 57
			case QA_ENTITY_USER:
				$action=$favorite ? 'u_favorite' : 'u_unfavorite';
				$params=array('userid' => $entityid);
				break;
Scott Vivian committed
58

Gideon Greenspan committed
59 60 61 62
			case QA_ENTITY_TAG:
				$action=$favorite ? 'tag_favorite' : 'tag_unfavorite';
				$params=array('wordid' => $entityid);
				break;
Scott Vivian committed
63

Gideon Greenspan committed
64 65 66 67
			case QA_ENTITY_CATEGORY:
				$action=$favorite ? 'cat_favorite' : 'cat_unfavorite';
				$params=array('categoryid' => $entityid);
				break;
Scott Vivian committed
68

Gideon Greenspan committed
69 70 71 72
			default:
				qa_fatal_error('Favorite type not recognized');
				break;
		}
Scott Vivian committed
73

Gideon Greenspan committed
74 75
		qa_report_event($action, $userid, $handle, $cookieid, $params);
	}
Scott Vivian committed
76 77


Gideon Greenspan committed
78 79 80
/*
	Omit PHP closing tag to help avoid accidental output
*/