Skip to content

Commit

Permalink
Task #53 feat: Create a bootstrap file (#54)
Browse files Browse the repository at this point in the history
* Task #53 feat: Create a bootsrap file

* Task #53 feat: Create a bootstrap file
  • Loading branch information
thite-amol authored and manojLondhe committed Nov 6, 2019
1 parent 44e6c5f commit 3cb3c9c
Show file tree
Hide file tree
Showing 5 changed files with 323 additions and 39 deletions.
17 changes: 8 additions & 9 deletions src/com_tjvendors/site/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
}
191 changes: 191 additions & 0 deletions src/com_tjvendors/site/includes/tjvendors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php
/**
* @package TJVendors
* @subpackage com_tjvendors
*
* @author Techjoomla <[email protected]>
* @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\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 TJVendors
{
/**
* 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;
}

$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;
}
}
114 changes: 114 additions & 0 deletions src/com_tjvendors/site/includes/version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/**
* @package TJVendors
* @subpackage com_tjvendors
*
* @author Techjoomla <[email protected]>
* @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();
}
}
6 changes: 3 additions & 3 deletions src/com_tjvendors/site/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -19,7 +21,7 @@
*
* @since 3.3
*/
class TjvendorsRouter extends JComponentRouterBase
class TjvendorsRouter extends RouterBase
{
/**
* Build method for URLs
Expand Down Expand Up @@ -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))
{
Expand Down
Loading

0 comments on commit 3cb3c9c

Please sign in to comment.