Exemplo n.º 1
0
	public static function generate_conversation($reason) {
		/*
		(Mixed) -> Bool
		Attempts to create a conversation due to some reason
		 */
		if (is_subclass_of($reason, 'ProposedDate')) {
			if ((is_a($reason->creator, 'User') && ($reason->creator->user_id))) {
				$mysqli = Database::connection();
				$header = ConversationFactory::_generate_header($reason);
				$sql = "INSERT INTO `conversations` (conversation_name, date_started, date_recent_activity, header, date_id) VALUES ('" . date('F j, Y', strtotime($reason->begin_datetime)) . " - " . $reason->datename . "', NOW(), NOW(), '$header', '$reason->date_id')";
				$result = $mysqli->query($sql)
				or die ($mysqli->error);
			//echo $sql;
				$conversation_id = $mysqli->insert_id;
				//Add the user into the conversation
				$creator_id = $reason->creator->user_id;
				$sql = "INSERT INTO `conversation_members` (user_id, conversation_id, admin, date) VALUES('$creator_id', '$conversation_id', '" . Conversation::ADMIN_TYPE . "', NOW())";
				$result = $mysqli->query($sql)
				or die ($mysqli->error);
				return true;
			}
			else {
				throw new UnexpectedValueException('UnexpectedValueException occured on creating the conversation for the date');
			}
		}
		else {
			throw new UnexpectedValueException('Date is not a proposed type');
		}
	}
Exemplo n.º 2
0
	public function propose_badminton_date(ProposedDate $badminton_date) {
		/*
		(Children of ProposedDate) -> BadmintonDate
		Attempts to create a new badminton date into the database, assumes sanitized input already
		 */
		if ((strtotime($badminton_date->begin_datetime) > time()) && (strtotime($badminton_date->end_datetime) > time())) {
			$sql = "INSERT INTO badminton_dates (datename, begin_datetime, end_datetime, creator_id, confirmed, summary) VALUES ('$badminton_date->datename', '$badminton_date->begin_datetime', '$badminton_date->end_datetime', '$this->user_id', '" . BadmintonDate::CONFIRMED . "', '$badminton_date->summary')
			ON DUPLICATE KEY UPDATE date_id = date_id";
			$result = $this->dbc->query($sql)
			or die ($this->dbc->error);
			if (($this->dbc->affected_rows == 2) || ($this->dbc->affected_rows == 0)) {
				//Update was preformed
				$sql = "SELECT date_id FROM `badminton_dates` WHERE begin_datetime = '$badminton_date->begin_datetime' AND end_datetime = '$badminton_date->end_datetime'";
				$result = $this->dbc->query($sql)
				or die ($this->dbc->error);
				$badminton_date->date_id = mysqli_fetch_row($result)[0];
			}
			else {
				//Join the badminton date
				$badminton_date->date_id = $this->dbc->insert_id;
				//Push the action
				$action = new ProposeBadmintonDate(array(
					'proposer' => clone $this,
					'badminton_date' => $badminton_date)
				);
				ActionPusher::push_action($action);
				$this->join_badminton_date($badminton_date);
				//Create the badminton conversation
				ConversationFactory::generate_conversation($badminton_date);


			}
			return $badminton_date;
		}
		else {
			throw new UnexpectedValueException('UnexpectedValueException occured on request on the method call propose_badminton_date');
			return false;
		}
	}