summaryrefslogtreecommitdiff
path: root/src/web/_model/format.php
blob: d2a3700635ef0a5607cd78baf1ce6df8dc332d4a (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php /* Copyright (c) 2024 Freya Murphy */
class Format_model extends Model {

	function __construct($load) {
		parent::__construct($load);
	}

	/**
	 * Formats a users's name
	 * @param array $user - the $user
	 * @returns the user's formatted display name
	 */
	public function name($user) {
		$name = '';
		if ($user['first_name']) {
			$name .= $user['first_name'];
		}
		if ($user['middle_name']) {
			if ($name != '') {
				$name .= ' ';
			}
			$name .= $user['middle_name'];
		}
		if ($user['last_name']) {
			if ($name != '') {
				$name .= ' ';
			}
			$name .= $user['last_name'];
		}
		if ($name == '') {
			$name = '@' . $user['username'];
		}
		return $name;
	}

	/**
	 * Formats a date
	 * @param string $date - the data in RFC3999 format
	 * @returns the formatted date
	 */
	public function date($date) {
		$date=date_create($date);
		return date_format($date, "Y-m-d H:i");
	}

}