[SOLVED] update item with custom field

2 years 2 weeks ago #65083 by fopo-web
A Reminder! ;)

Please Log in or Create an account to join the conversation.

2 years 2 weeks ago - 2 years 2 weeks ago #65086 by ggppdk
Hello

I have added a new method (for v3.1.2) and update the FAQ article too
How to create a new FLEXIcontent item or edit an existing item by calling the FLEXIcontent item model in custom code


You can use:
$items_custom_values = FlexicontentFields::getCustomFieldValues(array($item), 'item');
$data['custom'] = reset($items_custom_values); // Get data of first item
If your site is not live yet, then visit this URL: github.com/FLEXIcontent/flexicontent-cck/tree/3.1.x-stable

Click "Clone or Download" / "Download ZIP"

Then upgrade your existing FLEXIcontent installation,
by uploading the file via Joomla extension installer


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star review. Thanks!

Please Log in or Create an account to join the conversation.

2 years 2 weeks ago - 2 years 2 weeks ago #65087 by ggppdk
If you do not want to upgrade then copy the new method into your code (use the following):
function getCustomFieldValues(&$items, $view = 'item')
{
	$custom = FlexicontentFields::_getCustomValues($items, $view);
 
	$db = JFactory::getDBO();
	$query = 'SELECT *'
		.' FROM #__flexicontent_fields';
	$db->setQuery($query);
	$fields = $db->loadObjectList('id');
 
	$data = array();
	foreach($custom as $item_id => $fdata)
	{
		foreach($fdata as $fid => $fvalues)
		{
			if ( !isset($fields[$fid]) ) continue;
 
			// Make sure field values is an array
			if ( !is_array($fvalues) )
			{
				$fvalues = strlen($fvalues) ? array($fvalues) : array();
			}
 
			// Unserialize values already serialized values
			foreach ($fvalues as $i => $val)
			{
				if ( @unserialize($val)!== false || $val === 'b:0;' )
				{
					$fvalues[$i] = unserialize($val);
				}
			}
 
			$data[$item_id][$fields[$fid]->name] = $fvalues;
		}
	}
 
	return $data;
}
 



and then use:
  $items_custom_values = getCustomFieldValues(array($item), 'item');
  $data['custom'] = reset($items_custom_values); // Get data of first item


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star review. Thanks!

Please Log in or Create an account to join the conversation.

2 years 2 weeks ago #65114 by fopo-web
Thanks for your help. This is the solution. :)

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
© 2018 Flexicontent. All Rights Reserved.