Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
199 lars 1
<?php namespace Clockwork\Request;
2
 
3
// Data structure representing custom user data item (shown as counters or table)
4
class UserDataItem
5
{
6
	// Data contents (labels and values or table rows)
7
	protected $data;
8
 
9
	// Describes how the data should be presented ("counters" or "table")
10
	protected $showAs;
11
 
12
	// Data title (shown as table title in the official app)
13
	protected $title;
14
 
15
	// Map of human-readable labels for the data contents
16
	protected $labels;
17
 
18
	public function __construct(array $data)
19
	{
20
		$this->data = $data;
21
	}
22
 
23
	// Set how the item should be presented ("counters" or "table")
24
	public function showAs($showAs)
25
	{
26
		$this->showAs = $showAs;
27
		return $this;
28
	}
29
 
30
	// Set data title (shown as table title in the official app)
31
	public function title($title)
32
	{
33
		$this->title = $title;
34
		return $this;
35
	}
36
 
37
	// Set a map of human-readable labels for the data contents
38
	public function labels($labels)
39
	{
40
		$this->labels = $labels;
41
		return $this;
42
	}
43
 
44
	// Transform contents to a serializable array with metadata
45
	public function toArray()
46
	{
47
		return array_merge($this->data, [
48
			'__meta' => array_filter([
49
				'showAs' => $this->showAs,
50
				'title'  => $this->title,
51
				'labels' => $this->labels
52
			])
53
		]);
54
	}
55
}