From 3efe9358a2eef89e1bc561fc27a70b914d344dc8 Mon Sep 17 00:00:00 2001 From: Amol Thite Date: Wed, 6 Nov 2019 13:47:13 +0530 Subject: [PATCH 1/5] Task #53 feat: Create a bootsrap file --- src/com_tjvendors/site/controller.php | 17 +- src/com_tjvendors/site/includes/tjvendors.php | 198 ++++++++++++++++++ src/com_tjvendors/site/includes/version.php | 114 ++++++++++ src/com_tjvendors/site/router.php | 6 +- src/com_tjvendors/site/tjvendors.php | 34 +-- 5 files changed, 330 insertions(+), 39 deletions(-) create mode 100644 src/com_tjvendors/site/includes/tjvendors.php create mode 100644 src/com_tjvendors/site/includes/version.php diff --git a/src/com_tjvendors/site/controller.php b/src/com_tjvendors/site/controller.php index 197bf2ce..c0aef5de 100755 --- a/src/com_tjvendors/site/controller.php +++ b/src/com_tjvendors/site/controller.php @@ -11,14 +11,15 @@ // No direct access defined('_JEXEC') or die; -jimport('joomla.application.component.controller'); +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Controller\BaseController; /** * Class TjvendorsController * - * @since 1.6 + * @since 1.0.0 */ -class TjvendorsController extends JControllerLegacy +class TjvendorsController extends BaseController { /** * Method to display a view. @@ -28,15 +29,13 @@ class TjvendorsController extends JControllerLegacy * * @return JController This object to support chaining. * - * @since 1.5 + * @since 1.0.0 */ public function display($cachable = false, $urlparams = false) { - $view = JFactory::getApplication()->input->getCmd('view', 'vendors'); - JFactory::getApplication()->input->set('view', $view); + $view = Factory::getApplication()->input->getCmd('view', 'vendors'); + Factory::getApplication()->input->set('view', $view); - parent::display($cachable, $urlparams); - - return $this; + return parent::display($cachable, $urlparams); } } diff --git a/src/com_tjvendors/site/includes/tjvendors.php b/src/com_tjvendors/site/includes/tjvendors.php new file mode 100644 index 00000000..e6904794 --- /dev/null +++ b/src/com_tjvendors/site/includes/tjvendors.php @@ -0,0 +1,198 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +// No direct access +defined('_JEXEC') or die; + +use Joomla\CMS\Factory; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Table\Table; +use Joomla\String\StringHelper; + +/** + * TJVendors factory class. + * + * This class perform the helpful operation required to TJVendors package + * + * @since __DEPLOY_VERSION__ + */ +class TJV +{ + /** + * Holds the record of the loaded TJVendors classes + * + * @var array + * @since __DEPLOY_VERSION__ + */ + private static $loadedClass = array(); + + /** + * Holds the record of the component config + * + * @var Joomla\Registry\Registry + * @since __DEPLOY_VERSION__ + */ + private static $config = null; + + /** + * Retrieves a table from the table folder + * + * @param string $name The table file name + * @param array $config Configuration array for model. Optional. + * + * @return Table|boolean object or false on failure + * + * @since __DEPLOY_VERSION__ + **/ + public static function table($name, $config = array()) + { + Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjvendors/tables'); + $table = Table::getInstance($name, 'TjvendorsTable', $config); + + return $table; + } + + /** + * Retrieves a model from the model folder + * + * @param string $name The model name + * @param array $config Configuration array for model. Optional. + * + * @return BaseDatabaseModel|boolean object or false on failure + * + * @since __DEPLOY_VERSION__ + **/ + public static function model($name, $config = array()) + { + BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_tjvendors/models', 'TJVendorsModel'); + $model = BaseDatabaseModel::getInstance($name, 'TJVendorsModel', $config); + + return $model; + } + + /** + * Magic method to create instance of Tjvendors library + * + * @param string $name The name of the class + * @param mixed $arguments Arguments of class + * + * @return mixed return the Object of the respective class if exist OW return false + * + * @since __DEPLOY_VERSION__ + **/ + public static function __callStatic($name, $arguments) + { + self::loadClass($name); + + $className = 'Tjvendors' . StringHelper::ucfirst($name); + + if (class_exists($className)) + { + if (method_exists($className, 'getInstance')) + { + return call_user_func_array(array($className, 'getInstance'), $arguments); + } + + return new $className; + } + + return false; + } + + /** + * Load the class library if not loaded + * + * @param string $className The name of the class which required to load + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + **/ + public static function loadClass($className) + { + if (! isset(self::$loadedClass[$className])) + { + $className = (string) StringHelper::strtolower($className); + + $path = JPATH_SITE . '/components/com_tjvendors/includes/' . $className . '.php'; + + include_once $path; + + self::$loadedClass[$className] = true; + } + + return self::$loadedClass[$className]; + } + + /** + * Load the component configuration + * + * @return Joomla\Registry\Registry A Registry object. + */ + public static function config() + { + if (empty(self::$config)) + { + self::$config = ComponentHelper::getParams('com_tjvendors'); + } + + return self::$config; + } + + /** + * Initializes the css, js and necessary dependencies + * + * @param string $location The location where the assets needs to load + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public static function init($location = 'site') + { + static $loaded = null; + $docType = Factory::getDocument()->getType(); + $versionClass = self::version(); + + if ($loaded[$location] && ($docType != 'html')) + { + return; + } + + if (file_exists(JPATH_ROOT . '/media/techjoomla_strapper/tjstrapper.php')) + { + require_once JPATH_ROOT . '/media/techjoomla_strapper/tjstrapper.php'; + TjStrapper::loadTjAssets('com_tjvendors'); + } + + $version = $versionClass->getMediaVersion(); + $options = array("version" => $version); + + HTMLHelper::script('media/com_tjvendor/js/tjvendors.js', $options); + HTMLHelper::stylesheet('media/com_tjvendor/css/tjvendors.css', $options); + HTMLHelper::stylesheet('media/techjoomla_strapper/vendors/no-more-tables.css', $options); + + // Load Boostrap + if (self::config()->get('load_bootstrap') == '1') + { + define('COM_TJVENDORS_WRAPPAER_CLASS', "tjBs3"); + HTMLHelper::_('stylesheet', 'media/techjoomla_strapper/bs3/css/bootstrap.min.css'); + HTMLHelper::_('stylesheet', 'media/techjoomla_strapper/vendors/font-awesome/css/font-awesome.min.css'); + } + else + { + define('COM_TJVENDORS_WRAPPAER_CLASS', ''); + } + + $loaded[$location] = true; + } +} diff --git a/src/com_tjvendors/site/includes/version.php b/src/com_tjvendors/site/includes/version.php new file mode 100644 index 00000000..384a55f5 --- /dev/null +++ b/src/com_tjvendors/site/includes/version.php @@ -0,0 +1,114 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +use Joomla\CMS\Factory; + +defined('_JEXEC') or die(); + +/** + * Version information class for the TJVendors. + * + * @since __DEPLOY_VERSION__ + */ +class TjvendorsVersion +{ + /** + * Product name. + * + * @var string + * @since __DEPLOY_VERSION__ + */ + const PRODUCT = 'TJVendors'; + + /** + * Major release version. + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + const MAJOR_VERSION = 1; + + /** + * Minor release version. + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + const MINOR_VERSION = 4; + + /** + * Patch release version. + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + const PATCH_VERSION = 0; + + /** + * Release date. + * + * @var string + * @since __DEPLOY_VERSION__ + */ + const RELDATE = '20-August-2019'; + + /** + * Gets a "PHP standardized" version string for the current TJVendors. + * + * @return string Version string. + * + * @since __DEPLOY_VERSION__ + */ + public function getShortVersion() + { + return self::MAJOR_VERSION . '.' . self::MINOR_VERSION . '.' . self::PATCH_VERSION; + } + + /** + * Gets a version string for the current TJVendors with all release information. + * + * @return string Complete version string. + * + * @since __DEPLOY_VERSION__ + */ + public function getLongVersion() + { + return self::PRODUCT . ' ' . $this->getShortVersion() . ' ' . self::RELDATE; + } + + /** + * Generate a media version string for assets + * Public to allow third party developers to use it + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + public function generateMediaVersion() + { + return md5($this->getLongVersion() . Factory::getConfig()->get('secret')); + } + + /** + * Gets a media version which is used to append to TJVendors core media files. + * + * This media version is used to append to TJVendors core media in order to trick browsers into + * reloading the CSS and JavaScript, because they think the files are renewed. + * The media version is renewed after TJVendors core update, install, discover_install and uninstallation. + * + * @return string The media version. + * + * @since __DEPLOY_VERSION__ + */ + public function getMediaVersion() + { + return $this->generateMediaVersion(); + } +} diff --git a/src/com_tjvendors/site/router.php b/src/com_tjvendors/site/router.php index 5fa73fdd..6b28cf35 100755 --- a/src/com_tjvendors/site/router.php +++ b/src/com_tjvendors/site/router.php @@ -11,6 +11,8 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\Component\Router\RouterBase; + JLoader::registerPrefix('Tjvendors', JPATH_SITE . '/components/com_tjvendors/'); require_once JPATH_SITE . '/components/com_tjvendors/helpers/fronthelper.php'; @@ -19,7 +21,7 @@ * * @since 3.3 */ -class TjvendorsRouter extends JComponentRouterBase +class TjvendorsRouter extends RouterBase { /** * Build method for URLs @@ -86,8 +88,6 @@ public function parse(&$segments) // View is always the first element of the array $vars['view'] = array_shift($segments); - $TjvendorFrontHelper = new TjvendorFrontHelper; - $model = $TjvendorFrontHelper->getModel($vars['view']); while (!empty($segments)) { diff --git a/src/com_tjvendors/site/tjvendors.php b/src/com_tjvendors/site/tjvendors.php index 0f87585a..0ab4da20 100755 --- a/src/com_tjvendors/site/tjvendors.php +++ b/src/com_tjvendors/site/tjvendors.php @@ -9,10 +9,10 @@ */ defined('_JEXEC') or die; -use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Controller\BaseController; -// Include dependancies -jimport('joomla.application.component.controller'); +include_once JPATH_SITE . '/components/com_tjvendors/includes/tjvendors.php'; JLoader::registerPrefix('Tjvendors', JPATH_COMPONENT); @@ -25,29 +25,9 @@ JLoader::load('TjvendorFrontHelper'); } +TJV::init(); + // Execute the task. -$controller = JControllerLegacy::getInstance('Tjvendors'); -$controller->execute(JFactory::getApplication()->input->get('task')); +$controller = BaseController::getInstance('Tjvendors'); +$controller->execute(Factory::getApplication()->input->get('task')); $controller->redirect(); -$document = JFactory::getDocument(); -$options['relative'] = true; -JHtml::_('script', 'com_tjvendor/tjvendors.js', $options); - -// Frontend css -JHtml::_('stylesheet', 'com_tjvendor/tjvendors.css', $options); -JHtml::stylesheet(JUri::root() . 'media/techjoomla_strapper/vendors/no-more-tables.css', array(), true); - -// Load Boostrap -$params = ComponentHelper::getParams('com_tjvendors'); -$loadBootstrap = $params->get('load_bootstrap'); - -if ($loadBootstrap == '1') -{ - define('COM_TJVENDORS_WRAPPAER_CLASS', "tjBs3"); - JHtml::_('stylesheet', 'media/techjoomla_strapper/bs3/css/bootstrap.min.css'); - JHtml::_('stylesheet', 'media/techjoomla_strapper/vendors/font-awesome/css/font-awesome.min.css'); -} -else -{ - define('COM_TJVENDORS_WRAPPAER_CLASS', ''); -} From 948ade7fdea4ab7b76dce79be1acd68f51322a38 Mon Sep 17 00:00:00 2001 From: Amol Thite Date: Wed, 6 Nov 2019 14:10:53 +0530 Subject: [PATCH 2/5] Task #53 feat: Create a bootstrap file --- src/com_tjvendors/site/includes/tjvendors.php | 9 +-------- src/com_tjvendors/site/tjvendors.php | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/com_tjvendors/site/includes/tjvendors.php b/src/com_tjvendors/site/includes/tjvendors.php index e6904794..87b340c5 100644 --- a/src/com_tjvendors/site/includes/tjvendors.php +++ b/src/com_tjvendors/site/includes/tjvendors.php @@ -8,7 +8,6 @@ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access defined('_JEXEC') or die; use Joomla\CMS\Factory; @@ -25,7 +24,7 @@ * * @since __DEPLOY_VERSION__ */ -class TJV +class TJVendors { /** * Holds the record of the loaded TJVendors classes @@ -168,12 +167,6 @@ public static function init($location = 'site') return; } - if (file_exists(JPATH_ROOT . '/media/techjoomla_strapper/tjstrapper.php')) - { - require_once JPATH_ROOT . '/media/techjoomla_strapper/tjstrapper.php'; - TjStrapper::loadTjAssets('com_tjvendors'); - } - $version = $versionClass->getMediaVersion(); $options = array("version" => $version); diff --git a/src/com_tjvendors/site/tjvendors.php b/src/com_tjvendors/site/tjvendors.php index 0ab4da20..e64a52d4 100755 --- a/src/com_tjvendors/site/tjvendors.php +++ b/src/com_tjvendors/site/tjvendors.php @@ -25,7 +25,7 @@ JLoader::load('TjvendorFrontHelper'); } -TJV::init(); +TJVendors::init(); // Execute the task. $controller = BaseController::getInstance('Tjvendors'); From c643db69f0e235fbf9910f6c3412bf7fee77a5b6 Mon Sep 17 00:00:00 2001 From: Amol Thite Date: Wed, 13 Nov 2019 10:40:18 +0530 Subject: [PATCH 3/5] Task #53 feat: Vendor entity optimized --- .../en-GB/en-GB.com_tjvendors.ini | 28 +- src/com_tjvendors/site/controller.php | 2 +- .../site/helpers/fronthelper.php | 6 + src/com_tjvendors/site/includes/tjvendors.php | 3 + src/com_tjvendors/site/includes/vendor.php | 297 ++++++++++++++++++ .../site/models/forms/vendor.xml | 160 ++++++++-- src/com_tjvendors/site/models/vendor.php | 68 ++-- .../site/views/vendor/tmpl/default.php | 106 +++---- .../site/views/vendor/tmpl/edit.php | 249 +++++++-------- .../site/views/vendor/tmpl/profile.php | 120 +++---- .../site/views/vendor/view.html.php | 138 ++++---- 11 files changed, 754 insertions(+), 423 deletions(-) create mode 100644 src/com_tjvendors/site/includes/vendor.php diff --git a/src/com_tjvendors/admin_language/en-GB/en-GB.com_tjvendors.ini b/src/com_tjvendors/admin_language/en-GB/en-GB.com_tjvendors.ini index 7b4c8f47..781acf05 100755 --- a/src/com_tjvendors/admin_language/en-GB/en-GB.com_tjvendors.ini +++ b/src/com_tjvendors/admin_language/en-GB/en-GB.com_tjvendors.ini @@ -49,7 +49,7 @@ COM_TJVENDORS_VENDOR_APPROVAL_DESC="Admin needs to approve new vendor created in ; Add vendor view COM_TJVENDORS_TITLE_PERSONAL="Vendor Information" COM_TJVENDORS_FORM_DESC_VENDOR_USER_ID="Select user" -COM_TJVENDORS_CURRENCY_RECORDS="Curreny is not present" +COM_TJVENDORS_CURRENCY_RECORDS="Currency is not present" COM_TJVENDORS_FILE_UPLOAD_ALLOWED_EXTENSIONS="Allowed file extensions are - %s" COM_TJVENDORS_WRONG_FILE_UPLOAD=" The uploaded file type is not allowed. Allowed file types are jpg, jpeg, png" COM_TJVENDORS_TITLE_VENDORS="Vendors" @@ -95,15 +95,15 @@ COM_TJVENDORS_SUCCESSFULLY="Record inserted successfully." COM_TJVENDORS_ALREADY_EXISTED="User already existed." COM_TJVENDORS_RECORD_DELETED="Record deleted successfully" COM_TJVENDORS_ERR_DELETED="Error Deleting Records" -COM_TJVENDORS_SELECT_USER_RESET_ERROR="Plese Select the Vendor First" -COM_TJVENDORS_SELECT_USER_RESET_SUCCESS="Successfull Currency Reset : " +COM_TJVENDORS_SELECT_USER_RESET_ERROR="Please Select the Vendor First" +COM_TJVENDORS_SELECT_USER_RESET_SUCCESS="Successfully Currency Reset : " COM_TJVENDORS_FORM_LBL_VENDOR_CLIENTS="Is a vendor for" COM_TJVENDORS_DUPLICATE_CLIENT_ERROR="Registration for Duplicate Client not possible. Please Select New Client" COM_TJVENDORS_DISPLAY_YOU_ARE_ALREADY_A_VENDOR_AS="You are already a vendor as" COM_TJVENDORS_DISPLAY_DO_YOU_WANT_TO_ADD="Do you want to add " COM_TJVENDORS_DISPLAY_AS_A_CLIENT=" as a client" COM_TJVENDORS_VENDOR_LOGO_SIZE_VALIDATE="Upload an image within the specified size " -COM_TJVENDORS_VENDOR_LOGO_DIMENSIONS_VALIDATE=" Upload an image having dimentional value greater than " +COM_TJVENDORS_VENDOR_LOGO_DIMENSIONS_VALIDATE=" Upload an image having dimensional value greater than " COM_TJVENDORS_VENDOR_LOGO_IMAGE_TYPE_VALIDATION="Upload an image in proper format." COM_TJVENDORS_FORM_LBL_VENDOR_PAYMENT_GATEWAY="Choose Payment Gateway " COM_TJVENDORS_TITLE_PAYMENT_DETAILS="Payment Gateway Details" @@ -175,10 +175,10 @@ COM_TJVENDOR_EDIT_PAYOUT_SPECIFIC_COMM=" :Pay the Remaining Amount" COM_TJVENDORS_PAYOUTS_ID="ID" COM_TJVENDORS_VENDOR_APPROVAL="Enable vendor approval?" COM_TJVENDORS_VENDOR_APPROVAL_DESC="Enabling this configuration will let the administrator approve or deny any vendor that has registered on the site. After the administrator has approved, the vendor will then have the create rights." -COM_TJVENDORS_PAYOUTS_PAID_UPTO="Paid Upto Date" -COM_TJVENDOR_PAYOUTS_BULK_PAYOUT_NOTICE="Bulk Payout: Enables you to make payout for a particular vendor against a currency for all the clients associated with that vendor. The pending amount and the paid upto date columns show you the amount against that vendor for all clients he has." -COM_TJVENDOR_PAYOUTS_SINGLE_CLIENT_PAYOUT_NOTICE="Single Client Payout: Enables you to make payout for a particular vendor against a currency for a specified client. The paid upto date amount and the pending amount that appears are for one client." -COM_TJVENDORS_PAYOUT_SUCCESSFULL_MESSAGE = "Payout Successsfully Done." +COM_TJVENDORS_PAYOUTS_PAID_UPTO="Paid Up-to Date" +COM_TJVENDOR_PAYOUTS_BULK_PAYOUT_NOTICE="Bulk Payout: Enables you to make payout for a particular vendor against a currency for all the clients associated with that vendor. The pending amount and the paid up-to date columns show you the amount against that vendor for all clients he has." +COM_TJVENDOR_PAYOUTS_SINGLE_CLIENT_PAYOUT_NOTICE="Single Client Payout: Enables you to make payout for a particular vendor against a currency for a specified client. The paid up-to date amount and the pending amount that appears are for one client." +COM_TJVENDORS_PAYOUT_SUCCESSFULL_MESSAGE = "Payout Successfully Done." COM_TJVENDORS_PAYOUTS_BULK_LABEL= "Enter Payout Date Limit" COM_TJVENDORS_PAYOUTS_BULK_DESCRIPTION="Enter the no of days before which the payout will be calculated. Example when there are credit entries throughout this month but you want to calculate the payout amount for the whole month excluding the 5 days before today." COM_TJVENDORS_IMAGE_SIZE="Maximum Image Size for Vendor's Logo" @@ -216,12 +216,12 @@ COM_TJVENDORS_STATUS_CREDIT_DONE="Credit done" COM_TJVENDORS_BACK="Back" ;Clients -PLG_PAYPAL_PAYMENET_GATEWAY_EMAIL_ID="Paypal Email Id" -PLG_PAYPAL_PAYMENET_GATEWAY_EMAIL_ID_DESCRIPTION="Email id for paypal" -PLG_PAYPAL_PAYMENET_GATEWAY_PARAMETERS="Paypal plugin parameters" -PLG_ADAPTIVE_PAYPAL_PAYMENET_GATEWAY_EMAIL_ID="Adaptive Paypal Email id" -PLG_PAYPAL_PRO_PAYMENET_GATEWAY_EMAIL_ID="Paypal Pro Email id" -PLG_ADAPTIVE_PAYPAL_PAYMENET_GATEWAY_EMAIL_ID_DESCRIPTION="Enter the email id for paypal adaptive." +PLG_PAYPAL_PAYMENET_GATEWAY_EMAIL_ID="PayPal Email Id" +PLG_PAYPAL_PAYMENET_GATEWAY_EMAIL_ID_DESCRIPTION="Email id for PayPal" +PLG_PAYPAL_PAYMENET_GATEWAY_PARAMETERS="PayPal plugin parameters" +PLG_ADAPTIVE_PAYPAL_PAYMENET_GATEWAY_EMAIL_ID="Adaptive PayPal Email id" +PLG_PAYPAL_PRO_PAYMENET_GATEWAY_EMAIL_ID="PayPal Pro Email id" +PLG_ADAPTIVE_PAYPAL_PAYMENET_GATEWAY_EMAIL_ID_DESCRIPTION="Enter the email id for PayPal adaptive." COM_TJVENDOR_PAYMENT_DETAILS_DEFAULT="Select payment gateway" ; Generic COM_TJVENDORS_SITEADMIN="Siteadmin" diff --git a/src/com_tjvendors/site/controller.php b/src/com_tjvendors/site/controller.php index c0aef5de..0b88ac4d 100755 --- a/src/com_tjvendors/site/controller.php +++ b/src/com_tjvendors/site/controller.php @@ -31,7 +31,7 @@ class TjvendorsController extends BaseController * * @since 1.0.0 */ - public function display($cachable = false, $urlparams = false) + public function display($cachable = false, $urlparams = array()) { $view = Factory::getApplication()->input->getCmd('view', 'vendors'); Factory::getApplication()->input->set('view', $view); diff --git a/src/com_tjvendors/site/helpers/fronthelper.php b/src/com_tjvendors/site/helpers/fronthelper.php index ef08661d..12b12316 100644 --- a/src/com_tjvendors/site/helpers/fronthelper.php +++ b/src/com_tjvendors/site/helpers/fronthelper.php @@ -191,6 +191,8 @@ public static function getClientsForVendor($vendor_id) /** * Get vendor for that user * + * @deprecated __DEPLOY_VERSION__ use the alternative method TJVendors::vendor()->loadByUserId + * * @return integer */ public static function getvendor() @@ -294,6 +296,8 @@ public static function getPaymentDetails($vendor_id, $client) * * @param string $client client * + * @deprecated __DEPLOY_VERSION__ use the alternative method from TJVendorsVendor class + * * @return mixed * * @since 1.1 @@ -634,6 +638,8 @@ public function getPaymentGatewayConfig($vendorId, $client = "", $global = true) * @param string $client client * @param integer $vendorId Venodor ID * + * @deprecated __DEPLOY_VERSION__ use the alternative method TJVendors::vendor()->isAssociatedToClient + * * @return Boolean Client exist or not * * @since 1.3.0 diff --git a/src/com_tjvendors/site/includes/tjvendors.php b/src/com_tjvendors/site/includes/tjvendors.php index 87b340c5..2d18ed2a 100644 --- a/src/com_tjvendors/site/includes/tjvendors.php +++ b/src/com_tjvendors/site/includes/tjvendors.php @@ -22,6 +22,9 @@ * * This class perform the helpful operation required to TJVendors package * + * @method TjvendorsVersion version() + * @method TjvendorsVendor vendor() + * * @since __DEPLOY_VERSION__ */ class TJVendors diff --git a/src/com_tjvendors/site/includes/vendor.php b/src/com_tjvendors/site/includes/vendor.php new file mode 100644 index 00000000..5e2aed02 --- /dev/null +++ b/src/com_tjvendors/site/includes/vendor.php @@ -0,0 +1,297 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +defined('_JEXEC') or die(); + +use Joomla\CMS\Factory; +use Joomla\CMS\Uri\Uri; + +/** + * Vendor class. + * + * This class hold the property of the vendor entity and perform the appropriate operations + * + * @since __DEPLOY_VERSION__ + */ +class TjvendorsVendor +{ + /** + * primary key of the vendor record. + * + * @var int + * @since __DEPLOY_VERSION__ + */ + public $vendor_id = 0; + + /** + * primary key of the joomla user + * + * @var int + * @since __DEPLOY_VERSION__ + */ + private $user_id = 0; + + /** + * The name of the vendor. + * + * @var String + * @since __DEPLOY_VERSION__ + */ + private $vendor_title = ''; + + /** + * Unique string representation of the vendor + * + * @var string + * @since __DEPLOY_VERSION__ + */ + private $alias = ''; + + /** + * Vendor description + * + * @var String + * @since __DEPLOY_VERSION__ + */ + private $vendor_description = ''; + + /** + * The path of the vendo logo + * + * @var String + * @since __DEPLOY_VERSION__ + */ + private $vendor_logo = ''; + + /** + * State of the vendor + * + * @var int + * @since __DEPLOY_VERSION__ + */ + private $state = 0; + + /** + * Orderign of the record. + * + * @var int + * @since __DEPLOY_VERSION__ + */ + private $ordering = 0; + + /** + * Joomla user id who is currentaly checked out the item + * + * @var int + * @since __DEPLOY_VERSION__ + */ + private $checked_out = 0; + + /** + * Timestamp when the user checked out the record + * + * @var string + * @since __DEPLOY_VERSION__ + */ + private $checked_out_time = ''; + + /** + * Hold the other required information in the JSON format + * + * @var string + * @since __DEPLOY_VERSION__ + */ + private $params = ''; + + /** + * holds the already loaded instances of the vendor + * + * @var array + * @since __DEPLOY_VERSION__ + */ + protected static $vendorObj = array(); + + /** + * Constructor activating the default information of the vendor + * + * @param int $id The unique vendor id to load. + * + * @since __DEPLOY_VERSION__ + */ + public function __construct($id = 0) + { + if (!empty($id)) + { + $this->load($id); + } + else + { + $this->checked_out_time = Factory::getDbo()->getNullDate(); + } + } + + /** + * Returns the global vendor object + * + * @param integer $id The primary key of the vendor to load (optional). if id is empty the empty instance will be returned + * + * @return TjvendorsVendor The vendor object. + * + * @since __DEPLOY_VERSION__ + */ + public static function getInstance($id = 0) + { + if (!$id) + { + return new TjvendorsVendor; + } + + // Check if the coupon id is already cached. + if (empty(self::$vendorObj[$id])) + { + self::$vendorObj[$id] = new TjvendorsVendor($id); + } + + return self::$vendorObj[$id]; + } + + /** + * Method to load a vendor properties + * + * @param int $id The vendor id + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + public function load($id) + { + $table = TJVendors::table("vendor"); + + if (!$table->load($id)) + { + return false; + } + + $this->vendor_id = (int) $table->get('vendor_id'); + $this->user_id = (int) $table->get('user_id'); + $this->vendor_title = $table->get('vendor_title'); + $this->alias = $table->get('alias'); + $this->vendor_description = $table->get('vendor_description'); + $this->vendor_logo = $table->get('vendor_logo'); + $this->state = (int) $table->get('state'); + $this->ordering = (int) $table->get('ordering'); + $this->checked_out = (int) $table->get('checked_out'); + $this->checked_out_time = $table->get('checked_out_time'); + $this->params = $table->get('params'); + + return true; + } + + /** + * Method to load a vendor properties by using the joomla user id + * + * @param int $id The joomla user id + * + * @return TjvendorsVendor The vendor object. + * + * @since __DEPLOY_VERSION__ + */ + public function loadByUserId($id = null) + { + if (is_null($id)) + { + $id = Factory::getUser()->id; + } + + /** @var $table TjvendorsTableVendor */ + $table = TJVendors::table("vendor"); + + if (!$table->load(array('user_id' => $id))) + { + // If no record return blank object + return new TjvendorsVendor; + } + + return self::getInstance($table->vendor_id); + } + + /** + * Get the title of the vendor + * + * @return String + * + * @since __DEPLOY_VERSION__ + */ + public function getTitle() + { + return $this->vendor_title; + } + + /** + * Get the description of the vendor + * + * @return String + * + * @since __DEPLOY_VERSION__ + */ + public function getDescription() + { + return $this->vendor_description; + } + + /** + * Get the logo of the vendor + * + * @return String + * + * @since __DEPLOY_VERSION__ + */ + public function getLogo() + { + if (empty($this->vendor_logo)) + { + return Uri::root() . "administrator/components/com_tjvendors/assets/images/default.png"; + } + + return Uri::root() . $this->vendor_logo; + } + + /** + * Check whether the vendor is associated with the provided client + * + * @param string $client The client name to cehck integration eg. com_jticketing, com_tjllms + * + * @return bool True on success + * + * @since __DEPLOY_VERSION__ + */ + public function isAssociatedToClient($client = '') + { + static $clientExist = null; + + if (!$this->vendor_id) + { + return false; + } + + if ($clientExist[$client] != null) + { + return $clientExist[$client]; + } + + /** @var $table TjvendorsTableVendor */ + $table = TJVendors::table("vendor"); + + $clientExist[$client] = $table->load(array('vendor_id' => $this->vendor_id, 'client' => $client)); + + return $clientExist[$client]; + } +} diff --git a/src/com_tjvendors/site/models/forms/vendor.xml b/src/com_tjvendors/site/models/forms/vendor.xml index f6a32847..370090a6 100755 --- a/src/com_tjvendors/site/models/forms/vendor.xml +++ b/src/com_tjvendors/site/models/forms/vendor.xml @@ -1,36 +1,146 @@ - +
- - - - - - - -
-
- + + groupByFieldset="false" />
+ diff --git a/src/com_tjvendors/site/models/vendor.php b/src/com_tjvendors/site/models/vendor.php index 03977667..bdd2724b 100644 --- a/src/com_tjvendors/site/models/vendor.php +++ b/src/com_tjvendors/site/models/vendor.php @@ -8,41 +8,43 @@ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access. defined('_JEXEC') or die; -jimport('joomla.application.component.modeladmin'); JLoader::import('fronthelper', JPATH_SITE . '/components/com_tjvendors/helpers'); JLoader::import('tjvendors', JPATH_ADMINISTRATOR . '/components/com_tjvendors/helpers'); +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\AdminModel; +use Joomla\CMS\Table\Table; + /** * Tjvendors model. * - * @since 1.6 + * @since 1.0.0 */ -class TjvendorsModelVendor extends JModelAdmin +class TjvendorsModelVendor extends AdminModel { /** * @var string client data - * @since 1.6 + * @since 1.0.0 */ private $vendor_client = ''; /** * @var string The prefix to use with controller messages. - * @since 1.6 + * @since 1.0.0 */ protected $text_prefix = 'COM_TJVENDORS'; /** * @var string Alias to manage history control - * @since 3.2 + * @since 1.0.0 */ public $typeAlias = 'com_tjvendors.vendor'; /** * @var null Item data - * @since 1.6 + * @since 1.0.0 */ protected $item = null; @@ -55,15 +57,13 @@ class TjvendorsModelVendor extends JModelAdmin * * @return JTable A database object * - * @since 1.6 + * @since 1.0.0 */ public function getTable($type = 'Vendor', $prefix = 'TjvendorsTable', $config = array()) { - // Load tables to fix - unable to load the vendors data using the model object, - // When it is created outside the tjvendors component - JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjvendors/tables'); + Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjvendors/tables'); - return JTable::getInstance($type, $prefix, $config); + return Table::getInstance($type, $prefix, $config); } /** @@ -74,14 +74,10 @@ public function getTable($type = 'Vendor', $prefix = 'TjvendorsTable', $config = * * @return JForm A JForm object on success, false on failure * - * @since 1.6 + * @since 1.0.0 */ public function getForm($data = array(), $loadData = true) { - // Initialise variables. - $app = JFactory::getApplication(); - - // Get the form. $form = $this->loadForm( 'com_tjvendors.vendor', 'vendor', array('control' => 'jform', @@ -89,12 +85,7 @@ public function getForm($data = array(), $loadData = true) ) ); - if (empty($form)) - { - return false; - } - - return $form; + return empty($form) ? false: $form; } /** @@ -102,7 +93,7 @@ public function getForm($data = array(), $loadData = true) * * @return mixed The data for the form. * - * @since 1.6 + * @since 1.0.0 */ protected function loadFormData() { @@ -110,11 +101,14 @@ protected function loadFormData() $input = $app->input; $client = $input->get('client', '', 'STRING'); - $data = JFactory::getApplication()->getUserState('com_tjvendors.edit.vendor.data', array()); + $data = Factory::getApplication()->getUserState('com_tjvendors.edit.vendor.data', array()); if (empty($data)) { - if ($this->item === null) + $data = $this->getItem(); + + /** + * if ($this->item === null) { $this->item = $this->getItem(); } @@ -131,12 +125,10 @@ protected function loadFormData() $this->item->payment_gateway = json_decode($gatewayDetails->params)->payment_gateway; } } - } - - $data = $this->item; + } */ } - return $this->item; + return $data; } /** @@ -144,13 +136,16 @@ protected function loadFormData() * * @param integer $pk The id of the primary key. * - * @return mixed Object on success, false on failure. + * @return TjvendorsVendor Object on success, false on failure. * - * @since 1.6 + * @since 1.0.0 */ public function getItem($pk = null) { - $item = parent::getItem($pk); + return TJVendors::vendor(); + /* + * + *$item = parent::getItem($pk); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjvendors/tables'); $vendorXref = JTable::getInstance('VendorClientXref', 'TjvendorsTable'); @@ -158,6 +153,7 @@ public function getItem($pk = null) $item->params = $vendorXref->params; return $item; + */ } /** @@ -209,7 +205,7 @@ public function addMultiVendor($vendor_id, $payment_gateway, $paymentDetails) * * @return array|boolean * - * @since 1.6 + * @since 1.0.0 */ public function checkDuplicateUser($user_id) { @@ -253,7 +249,7 @@ public function checkDuplicateUser($user_id) * * @return array result * - * @since 1.6 + * @since 1.0.0 */ public function generateGatewayFields($payment_gateway, $parentTag) { diff --git a/src/com_tjvendors/site/views/vendor/tmpl/default.php b/src/com_tjvendors/site/views/vendor/tmpl/default.php index 65fe16ed..9cf96095 100755 --- a/src/com_tjvendors/site/views/vendor/tmpl/default.php +++ b/src/com_tjvendors/site/views/vendor/tmpl/default.php @@ -1,78 +1,48 @@ - * @copyright 2016 Parth Lawate - * @license GNU General Public License version 2 or later; see LICENSE.txt + * @package TJVendors + * @subpackage com_tjvendors + * + * @author Techjoomla + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access + defined('_JEXEC') or die(); + +use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; + +/** @var $this TjvendorsViewVendor */ ?> -vendor_id) ) - { - ?> -

- -

- -
-
-

- VendorDetail->vendor_title, ENT_COMPAT, 'UTF-8');?> - - - - - - -

+

+ +

+ +
+
+

+ escape($this->vendor->getTitle());?> + + + + + + +

+
+
+ +
+
+
+
+ escape($this->vendor->getDescription());?> +
- VendorDetail->vendor_logo)) - { - ?> -
- -
- -
- " width="100%"> -
- -
-
-
- escape($this->VendorDetail->vendor_description);?> -
-
-
- id && !$this->vendor_id) - { - $app = JFactory::getApplication(); - $client = $app->input->get('client', '', 'STRING'); - $link =JRoute::_('index.php?option=com_tjvendors&view=vendor&layout=edit&client=' . $client); - $app->enqueueMessage(JText::_('COM_TJVENDOR_REGISTRATION_VENDOR_ERROR'), 'warning'); - $app->redirect($link); - } - else - { - $link =JRoute::_('index.php?option=com_users'); - $app = JFactory::getApplication(); - $app->redirect($link); - } - ?> +
+ diff --git a/src/com_tjvendors/site/views/vendor/tmpl/edit.php b/src/com_tjvendors/site/views/vendor/tmpl/edit.php index 3f3aa93e..923dacae 100755 --- a/src/com_tjvendors/site/views/vendor/tmpl/edit.php +++ b/src/com_tjvendors/site/views/vendor/tmpl/edit.php @@ -1,92 +1,82 @@ - * @website http://techjoomla.com - * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. - * @license GNU General Public License version 2 or later; see LICENSE.txt + * @package TJVendors + * @subpackage com_tjvendors + * + * @author Techjoomla + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access defined('_JEXEC') or die; -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); -JHtml::_('behavior.tooltip'); -JHtml::_('behavior.formvalidation'); -JHtml::_('formbehavior.chosen', 'select'); -JHtml::_('behavior.keepalive'); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); +HTMLHelper::_('behavior.tooltip'); +HTMLHelper::_('behavior.formvalidation'); +HTMLHelper::_('formbehavior.chosen', 'select'); +HTMLHelper::_('behavior.keepalive'); + +/** @var $this TjvendorsViewVendor */ + ?> -
-id ) -{ - ?>

- +

-
- isClientExist): ?> + vendor->isAssociatedToClient($this->client)){ ?> - - +
-
- - - - - input; - - if ($this->vendor_id != 0) - { - ?> -
- - vendor->vendor_id) + { ?> - - - escape($this->VendorDetail->vendor_title);?> - - isClientExist) +
+ + + escape($this->vendor->getTitle());?> + vendor->isAssociatedToClient($this->client)) { - echo " " . JText::_('COM_TJVENDORS_DISPLAY_DO_YOU_WANT_TO_ADD'); + echo " " . Text::_('COM_TJVENDORS_DISPLAY_DO_YOU_WANT_TO_ADD'); $tjvendorFrontHelper = new TjvendorFrontHelper; - echo $client = $tjvendorFrontHelper->getClientName($this->client); - echo JText::_('COM_TJVENDORS_DISPLAY_AS_A_CLIENT'); + echo $tjvendorFrontHelper->getClientName($this->client); + echo Text::_('COM_TJVENDORS_DISPLAY_AS_A_CLIENT'); } ?> -
- - - - vendor_id == 0) - { - ?> +
+ + + + vendor->vendor_id) + { + ?>
form->renderField('vendor_title'); ?> @@ -94,105 +84,88 @@ form->renderField('vendor_description'); ?>
- - vendor->vendor_logo)) - { - ?> -
-
-
- -
-
-
- vendor->vendor_logo)) - { - ?> - -
-
-
- "> -
-
-
- form->renderField('vendor_logo'); ?> +
+
+
+
- +
+ form->renderField('vendor_logo'); ?> +
+
+ + vendor->vendor_logo)) + { + ?> + + + +
- params->get('image_size', '', 'STRING'));?> + params->get('image_size', '', 'STRING'));?>
+ } + ?> + + + form->renderField('checked_out_time'); ?> + form->renderField('checked_out'); ?> + form->renderField('ordering'); ?> + + +
- - -
form->getInput('payment_gateway');?>
-
-
- vendor_id == 0) - { - ?> -
- - - -
+ if ($this->vendor->vendor_id == 0) + { + ?> +
+ + +
isClientExist) - { + } + elseif (!$this->vendor->isAssociatedToClient($this->client)) + { + ?> +
+ + +
+ -
- - -
- - +
- redirect($link); -} -?>
- + diff --git a/src/com_tjvendors/site/views/vendor/tmpl/profile.php b/src/com_tjvendors/site/views/vendor/tmpl/profile.php index 5e93f758..935a5f7f 100644 --- a/src/com_tjvendors/site/views/vendor/tmpl/profile.php +++ b/src/com_tjvendors/site/views/vendor/tmpl/profile.php @@ -1,60 +1,52 @@ - * @copyright 2016 Parth Lawate - * @license GNU General Public License version 2 or later; see LICENSE.txt + * @package TJVendors + * @subpackage com_tjvendors + * + * @author Techjoomla + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access + defined('_JEXEC') or die; -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); -JHtml::_('behavior.tooltip'); -JHtml::_('behavior.formvalidation'); -JHtml::_('formbehavior.chosen', 'select'); -JHtml::_('behavior.keepalive'); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); +HTMLHelper::_('behavior.tooltip'); +HTMLHelper::_('behavior.formvalidation'); +HTMLHelper::_('formbehavior.chosen', 'select'); +HTMLHelper::_('behavior.keepalive'); + +/** @var $this TjvendorsViewVendor */ ?>
-id ) - { - ?>

- vendor->vendor_title, ENT_COMPAT, 'UTF-8'); - ?> + escape($this->vendor->getTitle()); ?>

-
-
-
- - - - - -
form->renderField('vendor_title'); ?> @@ -62,81 +54,49 @@ form->renderField('vendor_description'); ?>
- vendor->vendor_logo)) - { - ?> -
-
-
- -
-
-
-
- " class="img-thumbnail"> +
-
form->renderField('vendor_logo'); ?>
- params->get('image_size', '', 'STRING'));?> + params->get('image_size', '', 'STRING'));?>
- + + + form->renderField('checked_out_time'); ?> + form->renderField('checked_out'); ?> + form->renderField('ordering'); ?> + +
- - -
form->getInput('payment_gateway');?> -
+
-
-
-
- + -
-redirect($link); - } - ?>
- + diff --git a/src/com_tjvendors/site/views/vendor/view.html.php b/src/com_tjvendors/site/views/vendor/view.html.php index 17bcb087..6bea7f9d 100755 --- a/src/com_tjvendors/site/views/vendor/view.html.php +++ b/src/com_tjvendors/site/views/vendor/view.html.php @@ -1,47 +1,61 @@ - * @copyright Copyright 2009-2017 TechJoomla. All rights reserved. - * @license GNU General Public License version 2 or later. + * @package TJVendors + * @subpackage com_tjvendors + * + * @author Techjoomla + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access + defined('_JEXEC') or die; -jimport('joomla.application.component.view'); +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Uri\Uri; /** - * View to edit + * Vendor view class * - * @since 1.6 + * @since 1.0.0 */ -class TjvendorsViewVendor extends JViewLegacy +class TjvendorsViewVendor extends HtmlView { - protected $state; - - protected $item; - + /** + * Object of the vendor class + * + * @var \Joomla\CMS\Form\Form; + * @since __DEPLOY_VERSION__ + */ protected $form; - protected $vendor_id; - - protected $VendorDetail; - - protected $vendorClientXrefTable; - - protected $layout; - + /** + * Object of the vendor class + * + * @var TjvendorsVendor + * @since __DEPLOY_VERSION__ + */ protected $vendor; - protected $input; - + /** + * The current client of the vendor + * eg. com_jticketing, com_jgive + * + * @var string + * @since __DEPLOY_VERSION__ + */ protected $client; + /** + * params of the component + * + * @var Joomla\Registry\Registry + * @since __DEPLOY_VERSION__ + */ protected $params; - protected $isClientExist; - /** * Display the view * @@ -53,53 +67,55 @@ class TjvendorsViewVendor extends JViewLegacy */ public function display($tpl = null) { - $this->params = JComponentHelper::getParams('com_tjvendors'); - $this->state = $this->get('State'); - $this->vendor = $this->get('Item'); + $app = Factory::getApplication(); + $this->params = TJVendors::config(); $this->form = $this->get('Form'); - $this->input = JFactory::getApplication()->input; - $this->client = $this->input->get('client', '', 'STRING'); + $input = Factory::getApplication()->input; + $this->client = $input->get('client', '', 'STRING'); + $layout = $input->get('layout', '', 'STRING'); + $vendorId = $input->getInt('vendor_id'); + $this->vendor = TJVendors::vendor()->loadByUserId(); - JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_tjvendors/models', 'vendor'); - $tjvendorsModelVendor = JModelLegacy::getInstance('Vendor', 'TjvendorsModel'); - $tjvendorFrontHelper = new TjvendorFrontHelper; - $this->vendor_id = $tjvendorFrontHelper->getvendor(); - $this->client = $this->input->get('client', '', 'STRING'); - $this->isClientExist = $tjvendorFrontHelper->isClientExist($this->client, $this->vendor_id); - $this->vendorClientXrefTable = JTable::getInstance('vendorclientxref', 'TjvendorsTable', array()); - $this->vendorClientXrefTable->load(array('vendor_id' => $this->vendor_id, 'client' => $this->client)); - $this->VendorDetail = $tjvendorsModelVendor->getItem($this->vendor_id); + $user = Factory::getUser(); - $app = JFactory::getApplication(); - $app->setUserState("vendor.client", $this->client); - $app->setUserState("vendor.vendor_id", $this->vendor->vendor_id); - $this->layout = $this->input->get('layout', '', 'STRING'); - JText::script('COM_TJVENDOR_PAYMENTGATEWAY_NO_FIELD_MESSAGE'); - JText::script('COM_TJVENDOR_DESCRIPTION_READ_MORE'); - JText::script('COM_TJVENDOR_DESCRIPTION_READ_LESS'); - - if ($this->layout == 'profile' && $this->vendor_id != $this->vendor->vendor_id) + if ($user->guest) { - throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); + $return = base64_encode(Uri::getInstance()); + $loginUrlWithReturn = Route::_('index.php?option=com_users&view=login&return=' . $return); + $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'notice'); + $app->redirect($loginUrlWithReturn, 403); } - - if (!empty($this->vendor_id) && $this->layout == "edit") + else { - if (!empty($this->clientsForVendor)) + if ($layout == 'profile' && ($this->vendor->vendor_id !== $vendorId || !$user->authorise('core.edit.own'))) { - foreach ($this->clientsForVendor as $client) + $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'notice'); + $app->redirect(Route::_('index.php'), 403); + } + elseif ($layout == 'edit') + { + // Do nothing + } + else + { + // Change to vendor provided in the url + if (!empty($vendorId)) { - if ($client == $this->client) - { - $link = JRoute::_('index.php?option=com_tjvendors&view=vendor&layout=profile&client=' . $this->client . '&vendor_id=' . $this->vendor_id); - $app = JFactory::getApplication(); - $app->enqueueMessage(JText::_('COM_TJVENDOR_REGISTRATION_REDIRECT_MESSAGE')); - $app->redirect($link); - } + $this->vendor = TJVendors::vendor($vendorId); + } + + if (empty($this->vendor->vendor_id)) + { + $app->enqueueMessage(Text::_('The vendor is not exist'), 'notice'); + $app->redirect(Route::_('index.php'), 403); } } } + Text::script('COM_TJVENDOR_PAYMENTGATEWAY_NO_FIELD_MESSAGE'); + Text::script('COM_TJVENDOR_DESCRIPTION_READ_MORE'); + Text::script('COM_TJVENDOR_DESCRIPTION_READ_LESS'); + // Check for errors if (count($errors = $this->get('Errors'))) { From 685705a005854b104f2f1aad107580f995554fa9 Mon Sep 17 00:00:00 2001 From: Amol Thite Date: Mon, 18 Nov 2019 23:33:18 +0530 Subject: [PATCH 4/5] Task #153273 feat: Implement the vendor class methods --- src/com_tjvendors/admin/models/vendor.php | 4 +- .../admin/tables/vendorclientxref.php | 8 +- src/com_tjvendors/admin/tjvendors.php | 2 + .../site/helpers/fronthelper.php | 4 +- src/com_tjvendors/site/includes/vendor.php | 121 ++++++++++++++++-- src/com_tjvendors/site/models/vendor.php | 71 +++++----- .../site/views/vendor/tmpl/edit.php | 2 +- .../site/views/vendor/view.html.php | 22 ++-- 8 files changed, 162 insertions(+), 72 deletions(-) diff --git a/src/com_tjvendors/admin/models/vendor.php b/src/com_tjvendors/admin/models/vendor.php index 5f1d7eba..7154b29a 100644 --- a/src/com_tjvendors/admin/models/vendor.php +++ b/src/com_tjvendors/admin/models/vendor.php @@ -8,13 +8,11 @@ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access. defined('_JEXEC') or die; -jimport('joomla.application.component.modeladmin'); /** * Tjvendors model. * - * @since 1.6 + * @since 1.0.0 */ JLoader::import('com_tjvendors.models.vendor', JPATH_SITE . '/components'); diff --git a/src/com_tjvendors/admin/tables/vendorclientxref.php b/src/com_tjvendors/admin/tables/vendorclientxref.php index 341288a8..52333658 100644 --- a/src/com_tjvendors/admin/tables/vendorclientxref.php +++ b/src/com_tjvendors/admin/tables/vendorclientxref.php @@ -8,15 +8,16 @@ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access defined('_JEXEC') or die; +use Joomla\CMS\Table\Table; + /** * vendor Table class * - * @since 1.6 + * @since 1.0.0 */ -class TjvendorsTablevendorclientxref extends JTable +class TjvendorsTablevendorclientxref extends Table { /** * Constructor @@ -27,6 +28,7 @@ public function __construct(&$db) { $tableName = 'TjvendorsTablevendorclientxref'; JObserverMapper::addObserverClassToClass('JTableObserverContenthistory', $tableName, array('typeAlias' => 'com_tjvendors.vendorclientxref')); + parent::__construct('#__vendor_client_xref', 'vendor_id', $db); } } diff --git a/src/com_tjvendors/admin/tjvendors.php b/src/com_tjvendors/admin/tjvendors.php index c1c24d9e..8caeee9c 100755 --- a/src/com_tjvendors/admin/tjvendors.php +++ b/src/com_tjvendors/admin/tjvendors.php @@ -17,6 +17,8 @@ throw new Exception(JText::_('JERROR_ALERTNOAUTHOR')); } +include_once JPATH_SITE . '/components/com_tjvendors/includes/tjvendors.php'; + // Include dependancies jimport('joomla.application.component.controller'); diff --git a/src/com_tjvendors/site/helpers/fronthelper.php b/src/com_tjvendors/site/helpers/fronthelper.php index 12b12316..cf5881ea 100644 --- a/src/com_tjvendors/site/helpers/fronthelper.php +++ b/src/com_tjvendors/site/helpers/fronthelper.php @@ -24,6 +24,8 @@ class TjvendorFrontHelper * * @param string $name Model name * + * @deprecated __DEPLOY_VERSION__ use the alternative method TJVendors::model + * * @return null|object */ public static function getModel($name) @@ -98,7 +100,7 @@ public static function getUniqueClients($user_id) * * @param string $currency integer * - * @return amount + * @return array */ public static function getTotalDetails($vendor_id, $client, $currency) { diff --git a/src/com_tjvendors/site/includes/vendor.php b/src/com_tjvendors/site/includes/vendor.php index 5e2aed02..25b1fd23 100644 --- a/src/com_tjvendors/site/includes/vendor.php +++ b/src/com_tjvendors/site/includes/vendor.php @@ -11,7 +11,9 @@ defined('_JEXEC') or die(); use Joomla\CMS\Factory; +use Joomla\CMS\Object\CMSObject; use Joomla\CMS\Uri\Uri; +use Joomla\Registry\Registry; /** * Vendor class. @@ -20,7 +22,7 @@ * * @since __DEPLOY_VERSION__ */ -class TjvendorsVendor +class TjvendorsVendor extends CMSObject { /** * primary key of the vendor record. @@ -110,6 +112,31 @@ class TjvendorsVendor */ private $params = ''; + /** + * Integrated component client name eg. com_tjlms, com_jticketing + * + * @var string + * @since __DEPLOY_VERSION__ + */ + private $client = ''; + + /** + * Is vendor approved by the client + * By default the vendor is approved + * + * @var int + * @since __DEPLOY_VERSION__ + */ + private $approved = 1; + + /** + * Payment gateway details configured by the vendor + * + * @var string + * @since __DEPLOY_VERSION__ + */ + private $payment_gateway = ''; + /** * holds the already loaded instances of the vendor * @@ -121,15 +148,16 @@ class TjvendorsVendor /** * Constructor activating the default information of the vendor * - * @param int $id The unique vendor id to load. + * @param int $id The unique vendor id to load. + * @param string $client the client name whose properties need to load while creating object * * @since __DEPLOY_VERSION__ */ - public function __construct($id = 0) + public function __construct($id = 0, $client = '') { if (!empty($id)) { - $this->load($id); + $this->load($id, $client); } else { @@ -140,13 +168,14 @@ public function __construct($id = 0) /** * Returns the global vendor object * - * @param integer $id The primary key of the vendor to load (optional). if id is empty the empty instance will be returned + * @param integer $id The primary key of the vendor to load (optional). if id is empty the empty instance will be returned + * @param string $client the client name whose properties need to load while creating object * * @return TjvendorsVendor The vendor object. * * @since __DEPLOY_VERSION__ */ - public static function getInstance($id = 0) + public static function getInstance($id = 0, $client = '') { if (!$id) { @@ -156,7 +185,7 @@ public static function getInstance($id = 0) // Check if the coupon id is already cached. if (empty(self::$vendorObj[$id])) { - self::$vendorObj[$id] = new TjvendorsVendor($id); + self::$vendorObj[$id] = new TjvendorsVendor($id, $client); } return self::$vendorObj[$id]; @@ -165,13 +194,14 @@ public static function getInstance($id = 0) /** * Method to load a vendor properties * - * @param int $id The vendor id + * @param int $id The vendor id + * @param string $client the client name whose properties need to load while creating object * * @return boolean True on success * * @since __DEPLOY_VERSION__ */ - public function load($id) + public function load($id, $client = '') { $table = TJVendors::table("vendor"); @@ -180,6 +210,14 @@ public function load($id) return false; } + // Check for the client in the xref + $xreftable = TJVendors::table("vendorclientxref"); + + if (!$xreftable->load(array('vendor_id' => $id, 'client' => $client))) + { + return false; + } + $this->vendor_id = (int) $table->get('vendor_id'); $this->user_id = (int) $table->get('user_id'); $this->vendor_title = $table->get('vendor_title'); @@ -191,6 +229,7 @@ public function load($id) $this->checked_out = (int) $table->get('checked_out'); $this->checked_out_time = $table->get('checked_out_time'); $this->params = $table->get('params'); + $this->setClient($client); return true; } @@ -267,8 +306,8 @@ public function getLogo() /** * Check whether the vendor is associated with the provided client * - * @param string $client The client name to cehck integration eg. com_jticketing, com_tjllms - * + * @param string $client The client name to check integration eg. com_jticketing, com_tjllms + * * @return bool True on success * * @since __DEPLOY_VERSION__ @@ -289,9 +328,67 @@ public function isAssociatedToClient($client = '') /** @var $table TjvendorsTableVendor */ $table = TJVendors::table("vendor"); - $clientExist[$client] = $table->load(array('vendor_id' => $this->vendor_id, 'client' => $client)); return $clientExist[$client]; } + + /** + * Set client properties to the vendor object + * + * @param string $client The client name to check integration eg. com_jticketing, com_tjllms + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function setClient($client) + { + // Check for the client in the xref + $xreftable = TJVendors::table("vendorclientxref"); + + if (!$xreftable->load(array('vendor_id' => $this->vendor_id, 'client' => $client))) + { + return false; + } + + $this->client = $xreftable->get('client'); + $this->approved = (int) $xreftable->get('approved'); + + // State property override by the client + $this->state = (int) $xreftable->get('state'); + + // Expecting RuntimeException thrown by the Joomla\Registry\Format\Json class + try + { + // Params properties are overrided by the client params + $clientParams = new Registry($xreftable->get('params')); + $vendorParam = new Registry($this->params); + $vendorParam->merge($clientParams); + $this->params = $vendorParam->toString(); + + if (!empty($this->params)) + { + $this->payment_gateway = $vendorParam->get('payment_gateway'); + } + } + catch (Exception $e) + { + // Don't throw an error + } + + return true; + } + + /** + * Returns an associative array of object properties. + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function getProperties() + { + return get_object_vars($this); + } } diff --git a/src/com_tjvendors/site/models/vendor.php b/src/com_tjvendors/site/models/vendor.php index bdd2724b..4995750e 100644 --- a/src/com_tjvendors/site/models/vendor.php +++ b/src/com_tjvendors/site/models/vendor.php @@ -88,6 +88,30 @@ public function getForm($data = array(), $loadData = true) return empty($form) ? false: $form; } + /** + * Method to auto-populate the model state. + * + * Note. Calling getState in this method will result in recursion. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + protected function populateState() + { + $app = Factory::getApplication(); + $params = TJVendors::config(); + $vendorId = $app->input->getInt('vendor_id')? $app->input->getInt('vendor_id') : $app->getUserState('com_tjvendors.edit.vendor.id'); + $vendorId = !empty($vendorId) ? $vendorId : (int) TJVendors::vendor()->loadByUserId()->vendor_id; + $this->setState('vendor.id', $vendorId); + + $client = $app->input->getString('client', null); + $client = $client ? $client : $app->getUserState('com_tjvendors.client.name'); + + $this->setState('client.name', $client); + $this->setState('params', $params); + } + /** * Method to get the data that should be injected in the form. * @@ -97,35 +121,11 @@ public function getForm($data = array(), $loadData = true) */ protected function loadFormData() { - $app = JFactory::getApplication(); - $input = $app->input; - $client = $input->get('client', '', 'STRING'); - $data = Factory::getApplication()->getUserState('com_tjvendors.edit.vendor.data', array()); if (empty($data)) { - $data = $this->getItem(); - - /** - * if ($this->item === null) - { - $this->item = $this->getItem(); - } - - if (!empty($this->item->vendor_id)) - { - if (!empty($client)) - { - $tjvendorFrontHelper = new TjvendorFrontHelper; - $gatewayDetails = $tjvendorFrontHelper->getPaymentDetails($this->item->vendor_id, $client); - - if (!empty($gatewayDetails) && !empty($gatewayDetails->params)) - { - $this->item->payment_gateway = json_decode($gatewayDetails->params)->payment_gateway; - } - } - } */ + $data = $this->getItem()->getProperties(); } return $data; @@ -134,26 +134,19 @@ protected function loadFormData() /** * Method to get a single record. * - * @param integer $pk The id of the primary key. + * @param integer $pk The id of the primary key. + * @param string $client the client name whose properties need to load while creating object * * @return TjvendorsVendor Object on success, false on failure. * * @since 1.0.0 */ - public function getItem($pk = null) + public function getItem($pk = null, $client = '') { - return TJVendors::vendor(); - /* - * - *$item = parent::getItem($pk); - - JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjvendors/tables'); - $vendorXref = JTable::getInstance('VendorClientXref', 'TjvendorsTable'); - $vendorXref->load(array('vendor_id' => $item->vendor_id)); - $item->params = $vendorXref->params; + $pk = (!empty($pk)) ? $pk : (int) $this->getState($this->getName() . '.id'); + $client = (!empty($client)) ? $client : $this->getState($this->getName() . '.client'); - return $item; - */ + return TJVendors::vendor($pk, $client); } /** @@ -203,6 +196,8 @@ public function addMultiVendor($vendor_id, $payment_gateway, $paymentDetails) * * @param integer $user_id user name. * + * @deprecated __DEPLOY_VERSION__ use the alternative method TJVendors::vendor()->loadByUserId + * * @return array|boolean * * @since 1.0.0 diff --git a/src/com_tjvendors/site/views/vendor/tmpl/edit.php b/src/com_tjvendors/site/views/vendor/tmpl/edit.php index 923dacae..3d871ea7 100755 --- a/src/com_tjvendors/site/views/vendor/tmpl/edit.php +++ b/src/com_tjvendors/site/views/vendor/tmpl/edit.php @@ -58,7 +58,7 @@ echo Text::_('COM_TJVENDORS_DISPLAY_YOU_ARE_ALREADY_A_VENDOR_AS'); ?> - escape($this->vendor->getTitle());?> + escape($this->vendor->getTitle());?> vendor->isAssociatedToClient($this->client)) { diff --git a/src/com_tjvendors/site/views/vendor/view.html.php b/src/com_tjvendors/site/views/vendor/view.html.php index 6bea7f9d..a0eb5608 100755 --- a/src/com_tjvendors/site/views/vendor/view.html.php +++ b/src/com_tjvendors/site/views/vendor/view.html.php @@ -67,16 +67,16 @@ class TjvendorsViewVendor extends HtmlView */ public function display($tpl = null) { - $app = Factory::getApplication(); - $this->params = TJVendors::config(); + $app = Factory::getApplication(); + $this->vendor = $this->get('Item'); $this->form = $this->get('Form'); - $input = Factory::getApplication()->input; + $this->state = $this->get('State'); + $this->params = $this->state->get('params'); + $input = $app->input; $this->client = $input->get('client', '', 'STRING'); - $layout = $input->get('layout', '', 'STRING'); - $vendorId = $input->getInt('vendor_id'); - $this->vendor = TJVendors::vendor()->loadByUserId(); - - $user = Factory::getUser(); + $layout = $input->get('layout', '', 'STRING'); + $vendorId = $input->getInt('vendor_id'); + $user = Factory::getUser(); if ($user->guest) { @@ -98,12 +98,6 @@ public function display($tpl = null) } else { - // Change to vendor provided in the url - if (!empty($vendorId)) - { - $this->vendor = TJVendors::vendor($vendorId); - } - if (empty($this->vendor->vendor_id)) { $app->enqueueMessage(Text::_('The vendor is not exist'), 'notice'); From 327d7aceeb18aa9db473e1253e28893974f14de1 Mon Sep 17 00:00:00 2001 From: Amol Thite Date: Sat, 4 Jan 2020 14:26:37 +0530 Subject: [PATCH 5/5] Issue #53 feat: Vendor class implementation --- .../admin/views/vendor/tmpl/edit.php | 16 ++++++++-------- .../admin/views/vendor/tmpl/update.php | 12 ++++++------ src/com_tjvendors/site/controllers/vendor.php | 13 ++++++------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/com_tjvendors/admin/views/vendor/tmpl/edit.php b/src/com_tjvendors/admin/views/vendor/tmpl/edit.php index 44f46c57..518e16ea 100644 --- a/src/com_tjvendors/admin/views/vendor/tmpl/edit.php +++ b/src/com_tjvendors/admin/views/vendor/tmpl/edit.php @@ -40,10 +40,10 @@
- - - - + + + + input; $client=$input->get('client', '', 'STRING'); ?> - - - + + + form->renderField('user_id');?>
item->vendor_title.""; + echo $this->item->getTitle() . ""; echo " ".JText::_('COM_TJVENDORS_DISPLAY_DO_YOU_WANT_TO_ADD'); $tjvendorFrontHelper = new TjvendorFrontHelper(); echo $clientTitle = $tjvendorFrontHelper->getClientName($client); diff --git a/src/com_tjvendors/admin/views/vendor/tmpl/update.php b/src/com_tjvendors/admin/views/vendor/tmpl/update.php index 9c11617a..38c93141 100644 --- a/src/com_tjvendors/admin/views/vendor/tmpl/update.php +++ b/src/com_tjvendors/admin/views/vendor/tmpl/update.php @@ -32,7 +32,7 @@
- +
'personal')); ?> @@ -40,10 +40,10 @@
- - - - + + + +
- + item->vendor_logo)) : ?>
diff --git a/src/com_tjvendors/site/controllers/vendor.php b/src/com_tjvendors/site/controllers/vendor.php index ce4c4247..e46e85bd 100755 --- a/src/com_tjvendors/site/controllers/vendor.php +++ b/src/com_tjvendors/site/controllers/vendor.php @@ -8,18 +8,17 @@ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access defined('_JEXEC') or die(); -jimport('joomla.application.component.controllerform'); -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/tjvendors.php'); +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Controller\FormController; /** * Vendor controller class. * - * @since 1.6 + * @since 1.0.0 */ -class TjvendorsControllerVendor extends JControllerForm +class TjvendorsControllerVendor extends FormController { /** * Constructor @@ -28,8 +27,8 @@ class TjvendorsControllerVendor extends JControllerForm */ public function __construct() { - $this->view_list = 'vendors'; - $this->input = JFactory::getApplication()->input; + $this->view_list = 'vendors'; + $this->input = Factory::getApplication()->input; $this->vendor_client = $this->input->get('client', '', 'STRING');