forked from fastslack/matware-libraries
/
get.php
75 lines (64 loc) · 1.81 KB
/
get.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
<?php
/**
* @package Joomla.Services
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
class ApiServicesMenuitemsGet extends ApiControllerItem
{
/**
* Constructor.
*
* @param JInput $input The input object.
* @param JApplicationBase $app The application object.
*/
public function __construct(JInput $input = null, JApplicationBase $app = null)
{
parent::__construct($input, $app);
// Use the default database.
$this->setDatabase();
// Set the controller options.
$serviceOptions = array(
'contentType' => 'application/vnd.joomla.item.v1; schema=menuitems.v1',
'describedBy' => 'http://docs.joomla.org/Schemas/menuitems/v1',
'primaryRel' => 'joomla:menuitems',
'resourceMap' => __DIR__ . '/resource.json',
'self' => '/joomla:menuitems/' . (int) $this->input->get('id'),
'tableName' => '#__menu',
);
$this->setOptions($serviceOptions);
}
/**
* Get a single record from database.
*
* @return array Array of data records.
*/
public function getData()
{
// Get the database query object.
$query = $this->getQuery($this->tableName);
// Get a database query helper object.
$apiQuery = $this->getApiQuery();
// Get single record from database.
$data = $apiQuery->getItem($query, (int) $this->input->get('id'), 'm.id');
return $data;
}
/**
* Get database query.
*
* @param string $table Primary table name.
*
* @return JDatabaseDriver object.
*/
public function getQuery($table)
{
// Create a database query object.
$query = $this->db->getQuery(true)
->select('m.*, mt.id AS menu_id')
->from('#__menu AS m')
->leftjoin('#__menu_types AS mt ON m.menutype = mt.menutype')
;
return $query;
}
}