Skip to content

Commit

Permalink
Add joomla 4 compatibility
Browse files Browse the repository at this point in the history
update code to use auto loaded joomla resources and components
update view to be joomla 4 compatible
update datatables js Library
remove old jquery Library
  • Loading branch information
mattlorimer committed Feb 21, 2023
1 parent 9c7221d commit 9ab5fd7
Show file tree
Hide file tree
Showing 38 changed files with 1,064 additions and 1,066 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SuiteCRM-Portal-Joomla 2.0.3
# SuiteCRM-Portal-Joomla 3.0.0-beta
Joomla Plugin for the SuiteCRM Portal


Expand Down
16 changes: 8 additions & 8 deletions admin/advancedopenportal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;

// Set some global property
$document = JFactory::getDocument();
$document = Factory::getDocument();

// import joomla controller library
jimport('joomla.application.component.controller');

// Get an instance of the controller prefixed by AdvancedOpenPortal
$controller = JControllerLegacy::getInstance('AdvancedOpenPortal');
$controller = BaseController::getInstance('AdvancedOpenPortal');

// Perform the Request task
$controller->execute(JRequest::getCmd('task'));
$controller->execute(Factory::getApplication()->getInput()->get('task'));

// Redirect if set by the controller
$controller->redirect();
90 changes: 61 additions & 29 deletions admin/controller.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,70 @@
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla controller library
jimport('joomla.application.component.controller');
include_once 'components/com_advancedopenportal/models/advancedopenportals.php';

use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\AdminController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;

include_once 'components/com_advancedopenportal/models/AdvancedOpenPortalModel.php';

/**
* General Controller of Advanced OpenPortal component
*/
class AdvancedOpenPortalController extends JControllerLegacy
class AdvancedOpenPortalController extends AdminController
{
/**
* display task
*
* @return void
*/
function display($cachable = false)
{
if(array_key_exists('submit',$_REQUEST)){
$url = $_REQUEST['sugar_url'];
$user = $_REQUEST['sugar_user'];
$pass = $_REQUEST['sugar_pass'];
$reopen = !empty($_REQUEST['allow_case_reopen']);
$close = !empty($_REQUEST['allow_case_closing']);
$priority = !empty($_REQUEST['allow_priority']);
$type = !empty($_REQUEST['allow_type']);
AdvancedOpenPortalModelAdvancedOpenPortals::storeSettings($url,$user,$pass, $reopen, $close, $priority, $type);
JFactory::getApplication()->enqueueMessage(JText::_('COM_ADVANCEDOPENPORTAL_SETTINGS_SAVED'));

}
/**
* @throws Exception
*/
public function __construct($config = [], MVCFactoryInterface $factory = null, $app = null, $input = null)
{
$this->name = 'AdvancedOpenPortals';
$this->model_prefix = 'AdvancedOpenPortalModel';

parent::__construct($config, $factory, $app, $input);
}


/**
* display task
*
* @return void
* @throws Exception
*/
public function display($cachable = false, $urlparams = []): void
{
// set default view if not set
JRequest::setVar('view', JRequest::getCmd('view', 'AdvancedOpenPortals'));

// call parent behavior
parent::display($cachable);
}
}
$this->input->set('view', $this->app->input->getCmd('view', 'AdvancedOpenPortals'));

// call parent behavior
parent::display($cachable, $urlparams);
}

/**
* @throws Exception
*/
public function save()
{
// Check for request forgeries.
$this->checkToken();

$url = $this->input->get('sugar_url', '', 'trim');
$user = $this->input->get('sugar_user', '','trim');
$pass = $this->input->get('sugar_pass', '', 'trim');
$reopen = $this->input->get('allow_case_reopen', false, 'bool');
$close = $this->input->get('allow_case_closing', false, 'bool');
$priority = $this->input->get('allow_priority', false, 'bool');
$type = $this->input->get('allow_type', false, 'bool');

/** @var AdvancedOpenPortalModelAdvancedOpenPortals $model */
$model = $this->getModel();

if ($model->storeSettings($url, $user, $pass, $reopen, $close, $priority, $type)) {
$this->app->enqueueMessage(Text::_('COM_ADVANCEDOPENPORTAL_SETTINGS_SAVED'));
}

$this->display();
}

}
4 changes: 2 additions & 2 deletions admin/language/en-GB/en-GB.com_advancedopenportal.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
COM_ADVANCEDOPENPORTAL="Advanced OpenPortal"
COM_ADVANCEDOPENPORTAL_MANAGER_ADVANCEDOPENPORTALS="Advanced OpenPortal Settings"
COM_ADVANCEDOPENPORTAL="SuiteCRM Portal"
COM_ADVANCEDOPENPORTAL_MANAGER_ADVANCEDOPENPORTALS="SuiteCRM Portal Settings"
COM_ADVANCEDOPENPORTAL_SETTINGS_SAVED='Settings saved'
4 changes: 2 additions & 2 deletions admin/language/en-GB/en-GB.com_advancedopenportal.sys.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ COM_ADVANCEDOPENPORTAL_LIST_CASE_VIEW_DEFAULT_TITLE="List cases"
COM_ADVANCEDOPENPORTAL_LIST_CASE_VIEW_DEFAULT_DESC="Displays the list of users cases"
COM_ADVANCEDOPENPORTAL_NEW_CASE_VIEW_DEFAULT_TITLE="New case"
COM_ADVANCEDOPENPORTAL_NEW_CASE_VIEW_DEFAULT_DESC="Create a new case"
ADVANCEDOPENPORTAL="Advanced OpenPortal"
ADVANCEDOPENPORTAL0="Advanced OpenPortal"
ADVANCEDOPENPORTAL="SuiteCRM Portal"
ADVANCEDOPENPORTAL0="SuiteCRM Portal"
87 changes: 87 additions & 0 deletions admin/models/AdvancedOpenPortalModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\AdminModel;

/**
* AdvancedOpenPortalList Model
*/
class AdvancedOpenPortalModelAdvancedOpenPortals extends AdminModel
{

public function storeSettings($url, $user, $pass, $reopen, $close, $priority, $type): bool
{
$db = Factory::getDbo();

$ob = new stdClass();
$ob->id = 1;
$ob->sugar_url = $url;
$ob->sugar_user = $user;
$ob->allow_case_reopen = $reopen ? 1 : 0;
$ob->allow_case_closing = $close ? 1 : 0;
$ob->allow_priority = $priority ? 1 : 0;
$ob->allow_type = $type ? 1 : 0;
if (!empty($pass)) {
$ob->sugar_pass = md5($pass);
}

try {
$db->updateObject('#__advancedopenportal', $ob, 'id');
if ($db->getAffectedRows() === 0) {
$db->insertObject('#__advancedopenportal', $ob);
}
} catch (Exception $e) {
return false;
}

return true;
}

/**
* Method to build an SQL query to load the list data.
*
* @return string An SQL query
*/
protected function getListQuery()
{
// Create a new query object.
$db = Factory::getDbo();
$query = $db->getQuery(true);
// Select some fields
$query->select('*');
// From the hello table
$query->from('#__advancedopenportal');
return $query;
}

public function getItems()
{
$db = Factory::getDbo();
$query = $this->getListQuery();
try {
$result = $db->setQuery($query)->loadObjectList();
} catch (Exception $e) {
echo Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br>';

return [];
}

return $result;
}

public function getForm($data = [], $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_advancedopenportal.source', 'source',
['control' => 'jform', 'load_data' => $loadData]);

if (empty($form)) {
return false;
}

return $form;
}
}
62 changes: 0 additions & 62 deletions admin/models/advancedopenportals.php

This file was deleted.

20 changes: 11 additions & 9 deletions admin/models/fields/advancedopenportal.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php
// No direct access to this file
defined('_JEXEC') or die;

// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\ListField;
use Joomla\CMS\Form\FormHelper;

FormHelper::loadFieldClass('list');

/**
* AdvancedOpenPortal Form Field class for the AdvancedOpenPortal component
*/
class JFormFieldAdvancedOpenPortal extends JFormFieldList
class JFormFieldAdvancedOpenPortal extends ListField
{
/**
* The field type.
Expand All @@ -25,21 +27,21 @@ class JFormFieldAdvancedOpenPortal extends JFormFieldList
*/
protected function getOptions()
{
$db = JFactory::getDBO();
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select('id,sugar_url,sugar_user,sugar_pass');
$query->from('#__advancedopenportal');
$db->setQuery((string)$query);
$sagilitysugars = $db->loadObjectList();
$options = array();
$options = [];
if ($sagilitysugars)
{
foreach($sagilitysugars as $sagilitysugar)
{
$options[] = JHtml::_('select.option', $sagilitysugar->id, $sagilitysugar->sugar_url, $sagilitysugar->sugar_user,$sagilitysugar->sugar_pass);
$options[] = \Joomla\CMS\HTML\HTMLHelper::_('select.option', $sagilitysugar->id, $sagilitysugar->sugar_url, $sagilitysugar->sugar_user,$sagilitysugar->sugar_pass);
}
}
$options = array_merge(parent::getOptions(), $options);
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
13 changes: 6 additions & 7 deletions admin/tables/advancedopenportal.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php
// No direct access
defined('_JEXEC') or die('Restricted access');

// import Joomla table library
jimport('joomla.database.table');


use Joomla\CMS\Table\Table;

/**
* AdvancedOpenPortal Table class
*/
class AdvancedOpenPortalTableAdvancedOpenPortal extends JTable
class AdvancedOpenPortalTableAdvancedOpenPortal extends Table
{
/**
* Constructor
*
* @param object Database connector object
* @param object $db Database connector object
*/
function __construct(&$db)
public function __construct(&$db)
{
parent::__construct('#__advancedopenportal', 'id', $db);
}
Expand Down
Loading

0 comments on commit 9ab5fd7

Please sign in to comment.