<field name="downloadid" type="text" default=""
label="COMMON_DOWNLOADID_LABEL" description ="COMMON_DOWNLOADID_DESCRIPTION" class="text-long" />
/*
* This code is called in frontend with every page load
* which is consuming resources unnecessarily
* Todo: find a way to make this code run on template backend on save only
* possible solution: extention plug-in which hooks into gantry template save event
*/
class GantryFeatureDownloadId extends GantryFeature
{
var $_feature_name = 'downloadId';
var $_extra_query = "";
function isEnabled() {
global $gantry;
$dID = $gantry->get('downloadid');
if (!empty($dID)){
$this->_extra_query= "downloadid=$dID";
return true;
}
return false;
}
function init() {
global $gantry;
parent::init();
if (!empty($this->_extra_query)) {
$this->SetUpdateSite($this->_extra_query, $this->GetExtensionId());
}
}
private function GetExtensionId()
{
global $gantry;
$templateName= $gantry->_template->getName();
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('extension_id')
->from($db->qn('#__extensions'))
->where($db->qn('client_id') . ' = ' . $db->q(0))
->where($db->qn('type') . ' = ' . $db->q('template'))
->where($db->qn('name') . ' = ' . $db->q($templateName))
;
$db->setQuery($query);
return $db->loadResult();
}
private function SetUpdateSite($extra_query, $extensionId)
{
if(empty($extra_query) || empty($extensionId)) return; // do nothing
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('update_site_id')
->from($db->qn('#__update_sites_extensions'))
->where($db->qn('extension_id') . ' = ' . $db->q($extensionId));
$db->setQuery($query);
$updateSiteId = $db->loadResult();
if ($updateSiteId) {
// Update the update site record
$query = $db->getQuery(true)
->update($db->qn('#__update_sites'))
->set(array(
$db->quoteName('extra_query') . ' = ' . $db->q($extra_query),
$db->quoteName('enabled') . ' = ' . 1,
$db->quoteName('last_check_timestamp') . ' = ' . 0,
))
->where($db->qn('update_site_id') . ' = ' . $db->q($updateSiteId));
$db->setQuery($query);
$db->execute();
// Delete any existing updates (essentially flushes the updates cache for this update site)
$query = $db->getQuery(true)
->delete($db->qn('#__updates'))
->where($db->qn('update_site_id') . ' = ' . $db->q($updateSiteId));
$db->setQuery($query);
$db->execute();
}
}
}
Time to create page: 0.059 seconds