How to get parameters in JFormField from a disabled plugin in Joomla 1.6/2.5? - joomla

How i can get some parameters from a disabled/not yet actived plugin in joomla 1.6/2.5?
$module = JPluginHelper::getPlugin('system','myplugin');
$moduleParams = new JParameter($module->params);
$val = $moduleParams->get("key");
This method didn't work becouse i need to use within an element JFormField generator.
Thanks for help!

With JPluginHelper::getPlugin it's possible to access only enabled plugins, so here's the code for direct access to database.
// Build query
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select( 'params' )
->from( '#__extensions' )
->where( 'type = ' . $db->q('plugin') )
->where( 'folder = ' . $db->q('authentication') ) // Plugin type
->where( 'element = ' . $db->q('gmail') ) // Plugin element
;
// Execute query
$db->setQuery($query);
try
{
$result = $db->loadResult();
}
catch (RuntimeException $e)
{
return false;
}
// Parse parameters
if (!empty($result))
{
$params = new JRegistry($result);
$val = $params->get('key', 'defaultValue');
}
You may store query results in in the JFormField Object so save database queries in case field is availabile multiple times.
protected $results = null;

Perhaps you may want to try this:
// Get plugin parameters
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('`params`')
->from ('`#__extensions`')
->where ("`type` = 'plugin'")
->where ("`folder` = 'system'")
->where ("`element` = 'myplugin'");
$db->setQuery($query);
$res = json_decode($db->loadResult(), true);
$val = $res['key'];

Just find the answer by myself.
$data = null;
foreach ((array) $this->form as $k => $v) {
if($val instanceof JRegistry){
$data = &$v;
break;
}
}
$data = $data->toArray();
$val = $data['params']['key'];
Thanks! Bye!

Related

joomla - router change url when getting the name of product

I have build my own component in joomla and client wants now a friendly urls f.e
website.com/someplace/{product-id}-{product-name}. So i Build my own router like this.
function componentBuildRoute(&$query)
{
$segments = [];
if (isset($query['view'])) {
$segments[] = "szkolenie";
unset($query['view']);
}
if (isset($query['product_id'])) {
$productName = JFilterOutput::stringURLSafe(strtolower(getProductName($query['product_id'])));
$newName = $query['product_id'] . '-' . $productName;
$segments[] = $newName;
unset($query['product_id']);
}
return $segments;
}
and parse route function
function componentParseRoute($segments)
{
$app = JFactory::getApplication();
$menu = $app->getMenu();
$item =& $menu->getActive();
$count = count($segments);
switch ($item->query['view']) {
case 'catalogue' : {
$view = 'training';
$id = $segments[1];
}
break;
}
$data = [
'view' => $view,
'product_id' => $id
];
return $data;
}
While on the end of buildroute function segments are ok I have exactly what I want that on the beginning of parse route I have something like
website.com/szkolenie/1-krakow <-- I dont know wtf is this krakow( I know it is city i Poland) but still where is it get from ? The getProductName function implementation is
function getProductName($productId)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('#__component_training.id as id, #__component_product' . name)
->from($db->quoteName('#__component_training'))
->where('#__s4edu_product.product_id = ' . $productId)
->leftJoin('#__component_product ON
#__component_training.product_id=#__component_product.product_id');
$training = $db->loadObject();
return trim($training->name);
}
So taking all this into consideration I think that something is happening between the buildRoute and parseRoute, something what filters the $segment[1] variable, but how to disable that and why is it happening ?
P.S
Please do not send me to https://docs.joomla.org/Joomla_Routes_%26_SEF
I already know all the tutorials on joomla website which contains anything with sef.
P.S.S
It is built on joomla 3.7.0
You do not have a product named "krakow" ?
If not you can try to remove the $productName from the build function, just to check if this "krakow" is added automaticaly or it's from the getProductName() function.
Also i noticed that you have an error i guess in the function getProductName()
->where('#__s4edu_product.product_id = ' . $productId)
It's should be
->where('#__component_product.product_id = ' . $productId)

codeigniter get array data in controller

I have sql query in controller, this query produces number of rows.
$q1 = $this->db->query("SELECT product_code,product_quantity FROM tbl_order_details WHERE order_id='$order_no' AND location='$location'")->row();
foreach($q1 as $v_barcode){
$result = $this->settings_model->update_cancel_stock($v_barcode->product_code,$v_barcode->product_quantity);
}
then i pass this data to my model,
public function update_cancel_stock($code,$qty)
{
$this->db->set('product_quantity', $qty , FALSE);
$this->db->where('product_id', $order );
$this->db->update("tbl_inventory6");
}
but no any update. please check above code. thanx
Try this
$cond = array("order_id" => $order_no, "location" => $location);
$q1 = $this->db->select("product_code,product_quantity")->from("tbl_order_details")->where($cond)->row();
$result = $this->settings_model->update_cancel_stock($q1->product_code,$q1->product_quantity);
and then model ($code was not used)
public function update_cancel_stock($code,$qty){
$this->db->set('product_quantity', $qty , FALSE);
$this->db->where('product_id', $code);
$this->db->update('tbl_inventory6');
}
You are using row() function of Active Record. It already return only one row. So there is no requirement of foreach. Try this:
$q1 = $this->db->query("SELECT product_code,product_quantity FROM tbl_order_details WHERE order_id='$order_no' AND location='$location'")->row();
$result = $this->settings_model->update_cancel_stock($q1->product_code,$q1->product_quantity);
If you are getting multiple records and you are using foreach, you should use result().
$q1 = $this->db->query("SELECT product_code,product_quantity FROM tbl_order_details WHERE order_id='$order_no' AND location='$location'")->result();
foreach($q1 as $v_barcode){
$result = $this->settings_model->update_cancel_stock($v_barcode->product_code,$v_barcode->product_quantity);
}

How to pass variable $data to controller?

I've no idea to pass $data variable from Model to Controller.
In Model:
function active(){
$query = $this->db->query(" SELECT * FROM `event` WHERE DATE_FORMAT( NOW( ) , '%m-%d-%Y' ) BETWEEN START AND END ");
foreach($query->result_array() as $row){
$ev_name = $row['ev_name'];
$image = $row['ev_image'];
$start = $row['start'];
$end = $row['end'];
$desc = $row['ev_dec'];
$ev_id = $row['ev_id'];
}
$data = array('ev_name' => $ev_name,
'ev_image' => $image,
'start' => $start,
'end' => $end,
'ev_desc' =>$desc,
'ev_id'=> $ev_id
);
echo $data;
}
In Controller:
function active_event()
{
$this->load->view('active_event');
$this->load->model('Usermodel', Sdata);
}
You should use return keyword which is used for passing data from one function to another. You also need to load and call model method before loading view so that you can use data from modal in view. I think you need to check MVC pattern and Codeigniter userguide.
In your model,
function active(){
$query = $this->db->query(" SELECT * FROM `event` WHERE DATE_FORMAT( NOW( ) , '%m-%d-%Y' ) BETWEEN START AND END ");
foreach($query->result_array() as $row){
$ev_name = $row['ev_name'];
$image = $row['ev_image'];
$start = $row['start'];
$end = $row['end'];
$desc = $row['ev_dec'];
$ev_id = $row['ev_id'];
}
$data = array('ev_name' => $ev_name,
'ev_image' => $image,
'start' => $start,
'end' => $end,
'ev_desc' =>$desc,
'ev_id'=> $ev_id
);
return $data;
}
In your controller,
function active_event()
{
$this->load->model('YOUR MODEL NAME');
$data = $this->YOURMODELNAME->active();
$this->load->view('active_event', $data);
}

Joomla 2.5 pagination

I want to add pagination to my component, i've created a simple model with query. I must be missing something. What else do I need here ?
MODEL
jimport('joomla.application.component.modellist');
class PaieskaModelPradinis extends JModelList
{
public function getListQuery()
{
$db = JFactory::getDBO();
$query = "SELECT * FROM #__content";
$db->setQuery( $query );
$db->query( $query );
$result = $db->LoadObjectList();
return $result;
}
}
VIEW
jimport( 'joomla.application.component.view');
class PaieskaViewPradinis extends JView
{
protected $items;
protected $pagination;
function display ($tpl = null)
{
$this->items = $this->get('ListQuery');
$this->pagination = $this->get('Pagination');
parent::display($tpl);
}
}
TPL
foreach ($this->items as $item) {
echo $item->title;
}
EDITED:
I edited a bit code, so now it works fine, almost. Button display(number of rows to display) is not working. And I wonder if this part can be done in a different way ?
$limit = JRequest::getVar('limit' , 25);
$start = JRequest::getVar('start' , 0);
$query = "SELECT * FROM #__content LIMIT $start, $limit";
-
class PaieskaModelPradinis extends JModelList
{
public function getItems()
{
$db = JFactory::getDBO();
$limit = JRequest::getVar('limit' , 25);
$start = JRequest::getVar('start' , 0);
$query = "SELECT * FROM #__content LIMIT $start, $limit";
$db->setQuery( $query );
$db->query( $query );
$lists = $db->LoadObjectList();
return $lists;
}
function getPagination()
{
$main = JFactory::getApplication();
$db = JFactory::getDBO();
$limit = JRequest::getVar('limit' , 25);
$limitstart = JRequest::getVar('limitstart', 0);
$query = "SELECT count(title) FROM #__content";
$db->setQuery( $query );
$total = $db->loadResult();
// include a pagination library
jimport('joomla.html.pagination');
$pagination = new JPagination($total, $limitstart, $limit);
return $pagination;
}
}
VIEW
jimport( 'joomla.application.component.view');
class PaieskaViewPradinis extends JView
{
function display($tpl = null)
{
$this->items = $this->get('items');
$this->pagination = $this->get('pagination');
parent::display($tpl);
}
}
Going off your original code, not the edited version.
The getListQuery method only builds your database query, so you don't execute your query here. Use com_weblinks as an example for building out your model: https://github.com/joomla/joomla-cms/blob/2.5.x/components/com_weblinks/models/category.php
follow this link http://docs.joomla.org/J1.5:Using_JPagination_in_your_component properly.
I have used Joomla pagination. You'll be able to use Joomla pagination easily, if you follow documentation properly. BTW its very simple.

joomla loadformdata

how to show data from 3 tables in one view, because using JTable i can show data only bind to that JTable, please help me with this one.
my code so far(not working) in models:
public function getEntireProject(){
$item_id = $this->getItem()->id;
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__project_part_1 AS a');
$query->leftJoin('#__project_part_2 AS u ON a.uuid = u.uuid');
$query->leftJoin('#__project_part_3 AS y ON a.uuid = y.uuid');
$query->where('a.id = '. (int) $item_id);
$db->setQuery($query);
return $db->loadResult();
}
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_web_projects.edit.webproject.data', array());
if (empty($data)) {
$data = $this->getEntireProject();
}
return $data;
}
try to overwrite getItem function.This will also be helpful if you are calling get('Item') in view. -
public function getItem($pk = null){
if ($item = parent::getItem($pk)) {
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__project_part_1 AS a');
$query->leftJoin('#__project_part_2 AS u ON a.uuid = u.uuid');
$query->leftJoin('#__project_part_3 AS y ON a.uuid = y.uuid');
$query->where('a.id = '. (int) $item->id);
$db->setQuery($query);
$item = $db->loadAssoc();
}
return $item;
}
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_web_projects.edit.webproject.data', array());
if (empty($data)) {
$data = $this->getItem();
}
return $data;
}
For Multi-Row Results use loadRowList(), loadAssocList(), loadAssocList($key), loadObjectList(), loadObjectList('key'). $db->loadResult() only load one result. Read more.
If I understand your question right this should fix your problem. If you not please ask.

Resources