-
Notifications
You must be signed in to change notification settings - Fork 0
/
Json.php
executable file
·100 lines (78 loc) · 2.72 KB
/
Json.php
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php namespace components\simple_gallery; if(!defined('MK')) die('No direct access.');
class Json extends \dependencies\BaseViews
{
protected
$permissions = array(
'get_gallery' => 0
);
/**
* Get a page's timeline filters, or resort to the defaults.
*/
protected function get_gallery($data, $params)
{
// Fit 440x440 = retina thumbnail
// Fill 1440x## = retina full
$gallery = mk('Sql')
->table('simple_gallery', 'Galleries')
->where('id', $params->{0})
->execute_single();
$categories = mk('Sql')
->table('simple_gallery', 'Categories', $C)
->join('CategoryInfo', $CI)
->select("$CI.title", 'title')
->where("$C.gallery_id", $gallery->id)
->order('lft', 'ASC')
->execute();
// Map the ordered category ID's to a property on the gallery.
$gallery->merge(array(
'categories'=>$categories->map(function($cat){ return $cat->id->get('int'); })
));
// Collect all the images from all galleries.
$images = array();
foreach($categories as $category){
$videos = $category->videos;
// Fetch the items and merge it with the collection.
$categoryImages = $category->get_items();
$categoryImages = $categoryImages->merge($videos->get('array'));
$images = array_merge($images, $categoryImages->get('array'));
// Map the items to be listed as ID's in a property.
$category->merge(array(
'images' => $categoryImages->map(function($img){ return $img->id->get('int'); })
));
// $category->images->merge($videos->get('array'));
}
// Process the images to add their URL's.
foreach($images as $item){
if($item->is_video->get('bool') != true){
$image = $item->get_image();
$item->merge(array(
'thumbnail' => (string)$image->generate_url(array('fill_width'=>440, 'fill_height'=>440)),
'full' => (string)$image->generate_url(array( 'resize_width'=>(1440/2) ))
));
}
}
return array(
'gallery'=>$gallery,
'categories'=>$categories,
'images'=>$images
);
}
protected function get_categories($options, $params)
{
$params->{0}->is('set', function($gid)use($options){
$options->merge(array(
'gallery_id' => $gid
));
});
$options = $options->having('gallery_id')
->gallery_id->validate('Gallery ID', array('number'=>'integer', 'gt'=>0))->back()
;
return tx('Sql')
->table('simple_gallery', 'Categories')
->is($options->gallery_id->is_set(), function($q)use($options){
$q->where('gallery_id', $options->gallery_id);
})
->order('lft', 'ASC')
->execute();
}
}