initialise();
// Define component paths
define('JPATH_COMPONENT_SITE', JPATH_SITE . DS . 'components' . DS . 'com_flexicontent');
define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent');
// Create a log file
$user->id = "860";
$log_filename = 'item_creation_' . ($user->id) . '.php';
jimport('joomla.log.log');
JLog::addLogger(array('text_file' => $log_filename));
// **************************************
// Include the needed classes and helpers
// **************************************
require_once (JPATH_COMPONENT_SITE . DS . 'classes' . DS . 'flexicontent.helper.php');
require_once (JPATH_COMPONENT_SITE . DS . 'classes' . DS . 'flexicontent.categories.php');
require_once (JPATH_COMPONENT_SITE . DS . 'classes' . DS . 'flexicontent.fields.php');
require_once (JPATH_COMPONENT_SITE . DS . 'classes' . DS . 'flexicontent.acl.php');
require_once (JPATH_COMPONENT_SITE . DS . 'helpers' . DS . 'permission.php');
require_once (JPATH_COMPONENT_SITE . DS . 'helpers' . DS . 'route.php');
// Add component's table directory to the include path
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
// *******************
// Load language files
// *******************
// (BACKEND) Load english language file for 'com_content' component then override with current language file
JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, 'en-GB', true);
JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, null, true);
// (BACKEND) Load english language file for 'com_flexicontent' component then override with current language file
JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, 'en-GB', true);
JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, null, true);
// (FRONTEND) Load english language file for 'com_content' component then override with current language file
JFactory::getLanguage()->load('com_content', JPATH_SITE, 'en-GB', true);
JFactory::getLanguage()->load('com_content', JPATH_SITE, null, true);
// (FRONTEND) Load english language file for 'com_flexicontent' component then override with current language file
JFactory::getLanguage()->load('com_flexicontent', JPATH_SITE, 'en-GB', true);
JFactory::getLanguage()->load('com_flexicontent', JPATH_SITE, null, true);
// ****************************
// Create the item model object
// ****************************
require_once(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'models' . DS . 'item.php');
$item_model = new FlexicontentModelItem();
// Create the new item data
$data = array();
$data['id'] = 0; // indicate a new item will be created
// Type and language
$data['type_id'] = '2'; // e.g. 1 for article
$data['language'] = 'lv-LV'; // e.g. 'en-GB'
// main category, secondary categories and tags
$data['catid'] = 7; // INTEGER ... the main category of the item
$data['cid'] = array(7,8,9); //e.g. array(55,117,56) an array of the secondary categories of the item
$data['created_by'] = 860;
//$data['tag'] = ...; e.g. array(13,43,34) an array of the tags of the item
$data['vstate'] = 1; // item version is approved
$data['state'] = 1; // 1 for published ...
$data['title'] = 'Augsta riska HPV onkogēna E6/E7 mRNS';
$data['text'] = 'Augsta riska HPV onkogēna E6/E7 mRNS desk';
// Custom fields
$data['custom']['code'] = '1322015';
$data['custom']['price'] = '36.28';
$data['custom']['kompensacija'] = '0';
//$data['custom']['field2'][1] = 'this value 1 of field 2';
//$data['custom']['field2'][2] = 'this value 2 of field 2';
// Store the new item and log the result in file and on screen
if (!$item_model->store($data)) {
$msg = 'Failed to create the new item: ' . $model->getError();
JLog::add($msg);
echo $msg . "
";
} else {
$msg = 'Suceful to create the new item';
JLog::add($msg);
echo $msg . "
";
}