first commit
This commit is contained in:
45
components/com_convertforms/models/form.php
Normal file
45
components/com_convertforms/models/form.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Convert Forms
|
||||
* @version 3.2.12 Free
|
||||
*
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2020 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
class ConvertFormsModelForm extends JModelAdmin
|
||||
{
|
||||
/**
|
||||
* Get Submission Data
|
||||
*
|
||||
* @param object $pk The submission's primary key
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
$form_id = JFactory::getApplication()->getParams()->get('form_id');
|
||||
|
||||
$form = ConvertForms\Helper::renderFormById($form_id);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return mixed A JForm object on success, false on failure
|
||||
* @since 2.5
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
155
components/com_convertforms/models/submission.php
Normal file
155
components/com_convertforms/models/submission.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Convert Forms
|
||||
* @version 3.2.12 Free
|
||||
*
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2020 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/conversion.php';
|
||||
|
||||
class ConvertFormsModelSubmission extends ConvertFormsModelConversion
|
||||
{
|
||||
/**
|
||||
* Application Object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $app;
|
||||
|
||||
/**
|
||||
* Active Menu Item
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $menu;
|
||||
|
||||
/**
|
||||
* Submissions filter options and params;
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $options;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->app = JFactory::getApplication();
|
||||
$this->menu = $this->app->getMenu()->getActive();
|
||||
$this->options = isset($config['options']) ? new Registry($config['options']) : $this->menu->getParams();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Submission Data
|
||||
*
|
||||
* @param object $pk The submission's primary key
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getItem($pk = null, $prepare = true)
|
||||
{
|
||||
$item = parent::getItem($pk, $prepare);
|
||||
|
||||
if (!$item->id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($item->prepared_fields))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$item->fields = $item->prepared_fields;
|
||||
|
||||
$hide_empty_values = (bool) $this->options->get('hide_empty_values', false);
|
||||
|
||||
foreach ($item->fields as $key => $field)
|
||||
{
|
||||
if ($hide_empty_values && (is_null($field->value_html) || $field->value_html == ''))
|
||||
{
|
||||
unset($item->fields[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public function authorize()
|
||||
{
|
||||
// Verify we are browsing a submission that belongs the form selected in the menu item settings
|
||||
if (!$this->submissionBelongsToSelectedForm())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$filter_submitters = $this->options->get('filter_user', 'current');
|
||||
$view_own_only = $filter_submitters == 'current' ? true : (bool) $this->options->get('view_own_only', true);
|
||||
|
||||
// User is allowed to see all submissions
|
||||
if (!$view_own_only)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Deny access, if user is not logged-in
|
||||
if (!$user_id = JFactory::getUser()->id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$submission_user_id = (int) $this->getItem()->user_id;
|
||||
|
||||
if ($filter_submitters == 'current' && $user_id != $submission_user_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($filter_submitters == 'users')
|
||||
{
|
||||
$filter_users = explode(',', $this->options->get('users'));
|
||||
|
||||
if (!in_array($user_id, $filter_users))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify we are browsing a submission that belongs the form selected in the menu item settings
|
||||
*
|
||||
* @return mixed Null on failure, string on success
|
||||
*/
|
||||
private function submissionBelongsToSelectedForm()
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('id'))
|
||||
->from($db->quoteName('#__convertforms_conversions'))
|
||||
->where($db->quoteName('id') . ' = '. (int) $this->app->input->get('id'))
|
||||
->where($db->quoteName('form_id') . ' = ' . (int) $this->options->get('form_id'));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadResult();
|
||||
}
|
||||
|
||||
public function getMenu()
|
||||
{
|
||||
return $this->menu;
|
||||
}
|
||||
}
|
||||
146
components/com_convertforms/models/submissions.php
Normal file
146
components/com_convertforms/models/submissions.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Convert Forms
|
||||
* @version 3.2.12 Free
|
||||
*
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2020 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
require_once JPATH_ADMINISTRATOR . '/components/com_convertforms/models/conversions.php';
|
||||
|
||||
class ConvertFormsModelSubmissions extends ConvertFormsModelConversions
|
||||
{
|
||||
/**
|
||||
* Application Object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $app;
|
||||
|
||||
/**
|
||||
* Submissions filter options and params;
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $options;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
$this->app = JFactory::getApplication();
|
||||
$this->options = isset($config['options']) ? new Registry($config['options']) : $this->app->getMenu()->getActive()->getParams();
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* This method should only be called once per instantiation and is designed
|
||||
* to be called on the first call to the getState() method unless the model
|
||||
* configuration flag to ignore the request is set.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering An optional ordering field.
|
||||
* @param string $direction An optional direction (asc|desc).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.0.1
|
||||
*/
|
||||
protected function populateState($ordering = 'ordering', $direction = 'ASC')
|
||||
{
|
||||
$options = $this->options;
|
||||
|
||||
$this->setState('filter.form_id', $options->get('form_id', 0));
|
||||
|
||||
// Set page limit / limit start
|
||||
$this->setState('list.limit', $options->get('list_limit', 20));
|
||||
|
||||
$limitstart = $this->app->input->get('limitstart', 0, 'uint');
|
||||
$this->setState('list.start', $limitstart);
|
||||
|
||||
// Filter State
|
||||
$filter_confirmed_only = $options->get('confirmed_only', false);
|
||||
$this->setState('filter.state', $filter_confirmed_only ? '1' : '0,1');
|
||||
|
||||
// Set ordering
|
||||
$ordering = $options->get('ordering', 'recent');
|
||||
|
||||
switch ($ordering)
|
||||
{
|
||||
case 'oldest':
|
||||
$this->setState('list.ordering', 'created');
|
||||
$this->setState('list.direction', 'asc');
|
||||
break;
|
||||
|
||||
case 'random':
|
||||
$this->setState('list.ordering', 'rand()');
|
||||
break;
|
||||
|
||||
default: // recent
|
||||
$this->setState('list.ordering', 'created');
|
||||
$this->setState('list.direction', 'desc');
|
||||
break;
|
||||
}
|
||||
|
||||
// Filter Users
|
||||
$filter_user = $options->get('filter_user', '');
|
||||
|
||||
switch ($filter_user)
|
||||
{
|
||||
case 'specific':
|
||||
$user = $options->get('user_ids', -1);
|
||||
break;
|
||||
case 'current':
|
||||
$user = \JFactory::getUser()->id ?: -1;
|
||||
break;
|
||||
default:
|
||||
$user = null;
|
||||
}
|
||||
|
||||
if ($user)
|
||||
{
|
||||
$this->setState('filter.user_id', $user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [getItems description]
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
if (!$items = parent::getItems())
|
||||
{
|
||||
return $items;
|
||||
}
|
||||
|
||||
foreach ($items as &$item)
|
||||
{
|
||||
// View submission link
|
||||
$item->link = Route::link('site', 'index.php?option=com_convertforms&view=submission&id=' . $item->id . '&Itemid=' . Factory::getApplication()->input->get('Itemid'));
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user