Skip to content

Instantly share code, notes, and snippets.

@Jiwoks
Last active December 11, 2015 06:29
Show Gist options
  • Select an option

  • Save Jiwoks/4560020 to your computer and use it in GitHub Desktop.

Select an option

Save Jiwoks/4560020 to your computer and use it in GitHub Desktop.
Class that extends the joomla Component Helper. You can update components parameters with this class, get the manifest vars and the version of the component
<?php
// Code under GPL V3 Licence http://www.gnu.org/licenses/gpl.html
// no direct access
defined('_JEXEC') or die;
jimport('joomla.application.component.helper');
class myComponentComponentHelper extends JComponentHelper {
/**
* Method to set config parameters
* @param string $option
* @param array $datas
* @return boolean
*/
public function setParams($option,$datas){
$component = self::getComponent($option);
$table = JTable::getInstance('extension');
// Load the previous Data
if (!$table->load($component->id,false)) {
return false;
}
$d = json_decode($table->params);
foreach ($datas as $key => $data) {
$d->$key = $data;
}
$table->params = json_encode($d);
// Bind the data.
if (!$table->bind($datas)) {
return false;
}
// Check the data.
if (!$table->check()) {
return false;
}
// Store the data.
if (!$table->store()) {
return false;
}
unset(self::$components[$option]);
return true;
}
/**
* Method to get the version of a component
* @param string $option
* @return null
*/
public function getVersion($option){
$manifest = self::getManifest($option);
if(property_exists($manifest, 'version')){
return $manifest->version;
}
return null;
}
/**
* Method to get an object containing the manifest values
* @param string $option
* @return object
*/
public function getManifest($option){
$component = self::getComponent($option);
$table = JTable::getInstance('extension');
// Load the previous Data
if (!$table->load($component->id,false)) {
return false;
}
return json_decode($table->manifest_cache);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment