Server : LiteSpeed System : Linux server 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : alsaif ( 1057) PHP Version : 7.4.33 Disable Function : show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/alsaif/public_html/administrator/components/com_convertforms/ConvertForms/ |
<?php
/**
* @package Convert Forms
* @version 4.3.3 Pro
*
* @author Tassos Marinos <info@tassos.gr>
* @link https://www.tassos.gr
* @copyright Copyright © 2023 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace ConvertForms;
defined('_JEXEC') or die('Restricted access');
class SubmissionMeta
{
/**
* Logs table
*
* @var string
*/
private static $table = '#__convertforms_submission_meta';
/**
* Adds or updates a record in the database
*
* @param int $submission_id
* @param string $type
* @param string $key
* @param string $value
* @param array $params
*
* @return void
*/
public static function save($submission_id, $type, $key = '', $value = '', $params = [])
{
if ($record = self::getMeta($submission_id, $type, $key))
{
// Update existing record
$data = (object) [
'id' => $record['id'],
'submission_id' => $submission_id,
'meta_type' => $type,
'meta_key' => $key,
'meta_value' => $value,
'params' => json_encode($params),
'date_modified' => \JFactory::getDate()->toSql()
];
try
{
\JFactory::getDbo()->updateObject(self::$table, $data, 'id');
}
catch (Exception $e)
{
}
return;
}
// Add new record
self::add($submission_id, $type, $key, $value, $params);
}
/**
* Adds a Submission Meta.
*
* @param int $submission_id
* @param string $type
* @param string $key
* @param string $value
* @param array $params
*
* @return void
*/
public static function add($submission_id, $type, $key = '', $value = '', $params = [])
{
if (!$submission_id || !$type || !$value)
{
return;
}
// Data to save
$data = (object) [
'submission_id' => $submission_id,
'meta_type' => $type,
'meta_key' => $key,
'meta_value' => $value,
'params' => json_encode($params),
'date_created' => \JFactory::getDate()->toSql()
];
// Insert the data
try
{
\JFactory::getDbo()->insertObject(self::$table, $data);
}
catch (Exception $e)
{
}
}
/**
* Retrieves the meta row.
*
* @param int $submission_id
* @param string $type
* @param string $key
*
* @return mixed
*/
public static function getMeta($submission_id, $type, $key = '')
{
if (!$submission_id || !$type)
{
return;
}
$db = \JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('*')
->from($db->quoteName(self::$table))
->where($db->quoteName('submission_id') . ' = ' . $db->quote($submission_id))
->where($db->quoteName('meta_type') . ' = ' . $db->quote($type));
if (!empty($key))
{
$query->where($db->quoteName('meta_key') . ' = ' . $db->quote($key));
}
$db->setQuery($query);
return $db->loadAssoc();
}
/**
* Retrieves meta value.
*
* @param int $submission_id
* @param string $type
* @param string $key
*
* @return string
*/
public static function getValue($submission_id, $type, $key = '')
{
if (!$data = self::getMeta($submission_id, $type, $key))
{
return;
}
return $data['meta_value'];
}
/**
* Deletes a submission meta
*
* @param int $submission_id
* @param string $type
* @param string $key
*
* @return void
*/
public static function delete($submission_id, $type, $key = '')
{
if (!$submission_id || !$type)
{
return;
}
$db = \JFactory::getDbo();
$query = $db->getQuery(true)
->delete($db->quoteName(self::$table))
->where($db->quoteName('submission_id') . ' = ' . $db->quote($submission_id))
->where($db->quoteName('meta_type') . ' = ' . $db->quote($type));
if (!empty($key))
{
$query->where($db->quoteName('meta_key') . ' = ' . $db->quote($key));
}
$db->setQuery($query);
return $db->execute();
}
/**
* Deletes a list of submission meta by ID
*
* @param array $ids
*
* @return void
*/
public static function deleteAll($ids)
{
if (!is_array($ids))
{
return;
}
$db = \JFactory::getDbo();
$query = $db->getQuery(true)
->delete($db->quoteName(self::$table))
->where($db->quoteName('id') . ' IN (' . implode(', ', (array) $ids) . ')');
$db->setQuery($query);
return $db->execute();
}
}