Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions administrator/models/option.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* @package TjFields
*
* @author Techjoomla <extensions@techjoomla.com>
* @copyright Copyright (c) 2009-2019 TechJoomla. All rights reserved.
* @license GNU General Public License version 2 or later.
*/
defined('_JEXEC') or die;

jimport('joomla.application.component.modelitem');

/**
* Methods supporting a list of Tjfields option record.
*
* @since _DEPLOY_VERSION_
*/
class TjfieldsModelOption extends JModelItem
{
/**
* Constructor.
*
* @param Array $config An optional associative array of configuration settings.
*
* @since _DEPLOY_VERSION_
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'field_id', 'a.field_id',
'options', 'a.options',
'value', 'a.value'
);
}

parent::__construct($config);
}


/**
* Method to get an array of data items.
*
* @return mixed An array of data items on success, false on failure.
*
* @since _DEPLOY_VERSION_
*/
public function getItem()
{
$db = $this->getDbo();
$query = $db->getQuery(true);

// Get the ID from state if not provided
$id = (!empty($id)) ? (int) $id : (int) $this->getState('filter.id');

Comment on lines +50 to +57
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix parameter usage in getItem() method.

The method signature doesn't define an $id parameter, but line 56 attempts to use it. This will cause a PHP undefined variable notice.

- public function getItem()
+ public function getItem($id = null)
{
    $db = $this->getDbo();
    $query = $db->getQuery(true);

    // Get the ID from state if not provided
    $id = (!empty($id)) ? (int) $id : (int) $this->getState('filter.id');
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function getItem()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
// Get the ID from state if not provided
$id = (!empty($id)) ? (int) $id : (int) $this->getState('filter.id');
public function getItem($id = null)
{
$db = $this->getDbo();
$query = $db->getQuery(true);
// Get the ID from state if not provided
$id = (!empty($id)) ? (int) $id : (int) $this->getState('filter.id');

// If no ID is found, return false
if (!$id) {
return false;
}

// Build the query to fetch record by ID
$query->select('*')
->from($db->quoteName('#__tjfields_options'))
->where($db->quoteName('id') . ' = ' . (int) $id);
$db->setQuery($query);

// Fetch the result
$item = $db->loadObject();

return $item;
}
}