Skip to content

Commit f1bf8b2

Browse files
committed
create option model to fetch single option item detail
1 parent 3952c13 commit f1bf8b2

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

administrator/models/option.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* @package TjFields
4+
*
5+
* @author Techjoomla <extensions@techjoomla.com>
6+
* @copyright Copyright (c) 2009-2019 TechJoomla. All rights reserved.
7+
* @license GNU General Public License version 2 or later.
8+
*/
9+
defined('_JEXEC') or die;
10+
11+
jimport('joomla.application.component.modelitem');
12+
13+
/**
14+
* Methods supporting a list of Tjfields option record.
15+
*
16+
* @since _DEPLOY_VERSION_
17+
*/
18+
class TjfieldsModelOption extends JModelItem
19+
{
20+
/**
21+
* Constructor.
22+
*
23+
* @param Array $config An optional associative array of configuration settings.
24+
*
25+
* @since _DEPLOY_VERSION_
26+
*/
27+
public function __construct($config = array())
28+
{
29+
if (empty($config['filter_fields']))
30+
{
31+
$config['filter_fields'] = array(
32+
'id', 'a.id',
33+
'field_id', 'a.field_id',
34+
'options', 'a.options',
35+
'value', 'a.value'
36+
);
37+
}
38+
39+
parent::__construct($config);
40+
}
41+
42+
43+
/**
44+
* Method to get an array of data items.
45+
*
46+
* @return mixed An array of data items on success, false on failure.
47+
*
48+
* @since _DEPLOY_VERSION_
49+
*/
50+
public function getItem()
51+
{
52+
$db = $this->getDbo();
53+
$query = $db->getQuery(true);
54+
55+
// Get the ID from state if not provided
56+
$id = (!empty($id)) ? (int) $id : (int) $this->getState('filter.id');
57+
58+
// If no ID is found, return false
59+
if (!$id) {
60+
return false;
61+
}
62+
63+
// Build the query to fetch record by ID
64+
$query->select('*')
65+
->from($db->quoteName('#__tjfields_options'))
66+
->where($db->quoteName('id') . ' = ' . (int) $id);
67+
$db->setQuery($query);
68+
69+
// Fetch the result
70+
$item = $db->loadObject();
71+
72+
return $item;
73+
}
74+
}

0 commit comments

Comments
 (0)