Abacus in Dynamic Get #507

Closed
opened 2020-01-01 23:59:36 +00:00 by Manfred · 7 comments
Member

Steps to reproduce the issue

Do some calculations in Abacus (getcustom) and store values in variables according the naming convention.

Expected result

Numbers should be added to the $data array otherwise the results are lost

Actual result

Nothing happens with the results in the variables.

Code generated by JCB:

	// Here I have to start my calculations
	
	$query->select('count(*) as counter, sum(id) as summe');
	
	$db->setQuery($query);
	$temp=$db->loadObject();
	
	$cal_xxxxxxx=$temp->counter;
	$cal_xxxxxxy=$temp->summe;
	

	// return data object.
	return $data;

System information (as much as possible)

  • OS Name & Version:
  • MySql Version: 5.7.28
  • Apache Version: 2.x
  • PHP Version: 7.2
  • Joomla Version: 3.9.14
  • JCB Version: 2.10.9
  • Browser:

Additional comments

Code I have inserted into the abacus code field:

// Here I have to start my calculations

$query->select('count(*) as counter, sum(id) as summe');

$db->setQuery($query);
$temp=$db->loadObject();

$cal_xxxxxxx = $temp->counter;
$cal_xxxxxxy = $temp->summe;

### Steps to reproduce the issue Do some calculations in Abacus (getcustom) and store values in variables according the naming convention. ### Expected result Numbers should be added to the $data array otherwise the results are lost ### Actual result Nothing happens with the results in the variables. Code generated by JCB: // Here I have to start my calculations $query->select('count(*) as counter, sum(id) as summe'); $db->setQuery($query); $temp=$db->loadObject(); $cal_xxxxxxx=$temp->counter; $cal_xxxxxxy=$temp->summe; // return data object. return $data; ### System information (as much as possible) - OS Name & Version: - MySql Version: 5.7.28 - Apache Version: 2.x - PHP Version: 7.2 - Joomla Version: 3.9.14 - JCB Version: 2.10.9 - Browser: ### Additional comments Code I have inserted into the abacus code field: // Here I have to start my calculations $query->select('count(*) as counter, sum(id) as summe'); $db->setQuery($query); $temp=$db->loadObject(); $cal_xxxxxxx = $temp->counter; $cal_xxxxxxy = $temp->summe;
Owner

The query object is not available in the Abacus area. Can you give us a screenshot of the method code being generated in the model? Since I suspect this code is probably giving errors.

The query object is not available in the Abacus area. Can you give us a screenshot of the method code being generated in the model? Since I suspect this code is probably giving errors.
Author
Member

Hi Llewellyn,
I have put in the code of Generator up in the issue. The $query object is available as I use the Abacus in the "getcustom" custom get. My code works if I put my calculations into the $data object. The JCB code is written in the custom get function,

Manfred

Full code here:

class DemoModelLooks extends JModelList
{
	/**
	 * Model user data.
	 *
	 * @var        strings
	 */
	protected $user;
	protected $userId;
	protected $guest;
	protected $groups;
	protected $levels;
	protected $app;
	protected $input;
	protected $uikitComp;

	/**
	 * Method to build an SQL query to load the list data.
	 *
	 * @return      string  An SQL query
	 */
	protected function getListQuery()
	{
		// Get the current user for authorisation checks
		$this->user = JFactory::getUser();
		$this->userId = $this->user->get('id');
		$this->guest = $this->user->get('guest');
		$this->groups = $this->user->get('groups');
		$this->authorisedGroups = $this->user->getAuthorisedGroups();
		$this->levels = $this->user->getAuthorisedViewLevels();
		$this->app = JFactory::getApplication();
		$this->input = $this->app->input;
		$this->initSet = true; 
		// Get a db connection.
		$db = JFactory::getDbo();

		// Create a new query object.
		$query = $db->getQuery(true);

		// Get from #__demo_look as a
		$query->select('a.*');
		$query->from($db->quoteName('#__demo_look', 'a'));
		// Get where a.published is 1
		$query->where('a.published = 1');
		// Get where a.catid is $this->state->get('parameters.menu')->get('catid')
		$query->where('a.catid = ' . $db->quote($this->state->get('parameters.menu')->get('catid')));
		$query->order('a.name ASC');

		// return the query object
		return $query;
	}

	/**
	 * Method to get an array of data items.
	 *
	 * @return  mixed  An array of data items on success, false on failure.
	 */
	public function getItems()
	{
		$user = JFactory::getUser();
		// check if this user has permission to access item
		if (!$user->authorise('site.looks.access', 'com_demo'))
		{
			$app = JFactory::getApplication();
			$app->enqueueMessage(JText::_('COM_DEMO_NOT_AUTHORISED_TO_VIEW_LOOKS'), 'error');
			// redirect away to the home page if no access allowed.
			$app->redirect(JURI::root());
			return false;
		}
		// load parent items
		$items = parent::getItems();

		// Get the global params
		$globalParams = JComponentHelper::getParams('com_demo', true);

		// Insure all item fields are adapted where needed.
		if (DemoHelper::checkArray($items))
		{
			foreach ($items as $nr => &$item)
			{
				// Always create a slug for sef URL's
				$item->slug = (isset($item->alias) && isset($item->id)) ? $item->id.':'.$item->alias : $item->id;
			}
		}


		// do a quick build of all edit links links
		if (isset($items) && $items)
		{
			foreach ($items as $nr => &$item)
			{
				$canDo = DemoHelper::getActions('look',$item,'looks');
				if ($canDo->get('look.edit'))
				{
					$item->editLink = '<br /><br /><a class="uk-button uk-button-primary uk-width-1-1" href="';
					$item->editLink .= JRoute::_('index.php?option=com_demo&view=look&task=look.edit&id=' . $item->id);
					$item->editLink .= '"><i class="uk-icon-pencil"></i><span class="uk-hidden-small">';
					$item->editLink .= JText::_('COM_DEMO_EDIT_LOOK');
					$item->editLink .= '</span></a>';
				}
				else
				{
					$item->editLink = '';
				}
			}
		}

		// return items
		return $items;
	}

	/**
	 * Custom Method
	 *
	 * @return mixed  item data object on success, false on failure.
	 *
	 */
	public function getLookSum()
	{

		if (!isset($this->initSet) || !$this->initSet)
		{
			$this->user = JFactory::getUser();
			$this->userId = $this->user->get('id');
			$this->guest = $this->user->get('guest');
			$this->groups = $this->user->get('groups');
			$this->authorisedGroups = $this->user->getAuthorisedGroups();
			$this->levels = $this->user->getAuthorisedViewLevels();
			$this->initSet = true;
		}

		// Get a db connection.
		$db = JFactory::getDbo();

		// Create a new query object.
		$query = $db->getQuery(true);

		// Get from #__demo_look as a
		$query->select($db->quoteName(
			array('a.id','a.name'),
			array('id','name')));
		$query->from($db->quoteName('#__demo_look', 'a'));
		// Get where a.published is 1
		$query->where('a.published = 1');

		// Reset the query using our newly populated query object.
		$db->setQuery($query);
		// Load the results as a stdClass object.
		$data = $db->loadObject();

		if (empty($data))
		{
			return false;
		}
		// Here I have to start my calculations
		
		$query->select('count(*) as counter, sum(id) as summe');
		
		$db->setQuery($query);
		$temp=$db->loadObject();
		
		$data->counter = $temp->counter;
		$data->summe = $temp->summe;
		

		// return data object.
		return $data;
	}

	/**
	 * Get the uikit needed components
	 *
	 * @return mixed  An array of objects on success.
	 *
	 */
	public function getUikitComp()
	{
		if (isset($this->uikitComp) && DemoHelper::checkArray($this->uikitComp))
		{
			return $this->uikitComp;
		}
		return false;
	}
}
Hi Llewellyn, I have put in the code of Generator up in the issue. The $query object is available as I use the Abacus in the "getcustom" custom get. My code works if I put my calculations into the $data object. The JCB code is written in the custom get function, Manfred Full code here: ``` class DemoModelLooks extends JModelList { /** * Model user data. * * @var strings */ protected $user; protected $userId; protected $guest; protected $groups; protected $levels; protected $app; protected $input; protected $uikitComp; /** * Method to build an SQL query to load the list data. * * @return string An SQL query */ protected function getListQuery() { // Get the current user for authorisation checks $this->user = JFactory::getUser(); $this->userId = $this->user->get('id'); $this->guest = $this->user->get('guest'); $this->groups = $this->user->get('groups'); $this->authorisedGroups = $this->user->getAuthorisedGroups(); $this->levels = $this->user->getAuthorisedViewLevels(); $this->app = JFactory::getApplication(); $this->input = $this->app->input; $this->initSet = true; // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); // Get from #__demo_look as a $query->select('a.*'); $query->from($db->quoteName('#__demo_look', 'a')); // Get where a.published is 1 $query->where('a.published = 1'); // Get where a.catid is $this->state->get('parameters.menu')->get('catid') $query->where('a.catid = ' . $db->quote($this->state->get('parameters.menu')->get('catid'))); $query->order('a.name ASC'); // return the query object return $query; } /** * Method to get an array of data items. * * @return mixed An array of data items on success, false on failure. */ public function getItems() { $user = JFactory::getUser(); // check if this user has permission to access item if (!$user->authorise('site.looks.access', 'com_demo')) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('COM_DEMO_NOT_AUTHORISED_TO_VIEW_LOOKS'), 'error'); // redirect away to the home page if no access allowed. $app->redirect(JURI::root()); return false; } // load parent items $items = parent::getItems(); // Get the global params $globalParams = JComponentHelper::getParams('com_demo', true); // Insure all item fields are adapted where needed. if (DemoHelper::checkArray($items)) { foreach ($items as $nr => &$item) { // Always create a slug for sef URL's $item->slug = (isset($item->alias) && isset($item->id)) ? $item->id.':'.$item->alias : $item->id; } } // do a quick build of all edit links links if (isset($items) && $items) { foreach ($items as $nr => &$item) { $canDo = DemoHelper::getActions('look',$item,'looks'); if ($canDo->get('look.edit')) { $item->editLink = '<br /><br /><a class="uk-button uk-button-primary uk-width-1-1" href="'; $item->editLink .= JRoute::_('index.php?option=com_demo&view=look&task=look.edit&id=' . $item->id); $item->editLink .= '"><i class="uk-icon-pencil"></i><span class="uk-hidden-small">'; $item->editLink .= JText::_('COM_DEMO_EDIT_LOOK'); $item->editLink .= '</span></a>'; } else { $item->editLink = ''; } } } // return items return $items; } /** * Custom Method * * @return mixed item data object on success, false on failure. * */ public function getLookSum() { if (!isset($this->initSet) || !$this->initSet) { $this->user = JFactory::getUser(); $this->userId = $this->user->get('id'); $this->guest = $this->user->get('guest'); $this->groups = $this->user->get('groups'); $this->authorisedGroups = $this->user->getAuthorisedGroups(); $this->levels = $this->user->getAuthorisedViewLevels(); $this->initSet = true; } // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); // Get from #__demo_look as a $query->select($db->quoteName( array('a.id','a.name'), array('id','name'))); $query->from($db->quoteName('#__demo_look', 'a')); // Get where a.published is 1 $query->where('a.published = 1'); // Reset the query using our newly populated query object. $db->setQuery($query); // Load the results as a stdClass object. $data = $db->loadObject(); if (empty($data)) { return false; } // Here I have to start my calculations $query->select('count(*) as counter, sum(id) as summe'); $db->setQuery($query); $temp=$db->loadObject(); $data->counter = $temp->counter; $data->summe = $temp->summe; // return data object. return $data; } /** * Get the uikit needed components * * @return mixed An array of objects on success. * */ public function getUikitComp() { if (isset($this->uikitComp) && DemoHelper::checkArray($this->uikitComp)) { return $this->uikitComp; } return false; } } ```
Owner

What values do you get in the $temp variable if you do a var_dump($temp) after the database call? You do realize if there is no values in the database it will never get to your code right? Since data will be empty and return false.

What values do you get in the `$temp` variable if you do a `var_dump($temp)` after the database call? You do realize if there is no values in the database it will never get to your code right? Since data will be empty and return false.
Owner

Wow, I think you are right, this area has changed and the $cal__xxxxxx convention is gone. I am not sure where and when this happened. But a closer look just confirmed that this feature is broken, or missing.

But hey being able to move the values into the object should be okay right?

I may just need to update that field description, or add the convention back in the compiler. I just search in all the relevant areas and I can't find it anymore. I mean the implementation of this $cal__xxxxxx convention.

It is obviously not being used since you are the first to pickup it is missing.

The whole purpose of the Abacus area was to work in the loop of the items (if you have items)... but this seems to have been broken. I just checked the compiler and you will see it is added in these places:

The field is dynamically update here:

Both of these areas where massively improved, and refactored last year so I suppose somewhere that convention was lost and miss placed. I will look back at older versions of JCB to see how it worked and if it is worth adding it back, or just do a whole new thing... since it clearly is not working as expected anyway. Oops, my mistake! many things moving around, and since I do not use this area myself... I did not notice the break.

Wow, I think you are right, this area has changed and the `$cal__xxxxxx` convention is gone. I am not sure where and when this happened. But a closer look just confirmed that this feature is broken, or missing. But hey being able to move the values into the object should be okay right? I may just need to update that field description, or add the convention back in the compiler. I just search in all the relevant areas and I can't find it anymore. I mean the implementation of this `$cal__xxxxxx` convention. It is obviously not being used since you are the first to pickup it is missing. The whole purpose of the Abacus area was to work in the loop of the items (if you have items)... but this seems to have been broken. I just checked the compiler and you will see it is added in these places: - Interpretation class - [Line 2555](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/e_Interpretation.php#L2555) - Interpretation class - [Line 3297](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/e_Interpretation.php#L3297) The field is dynamically update here: - Get class - [Line 3454](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/a_Get.php#L3454) Both of these areas where massively improved, and refactored last year so I suppose somewhere that convention was lost and miss placed. I will look back at older versions of JCB to see how it worked and if it is worth adding it back, or just do a whole new thing... since it clearly is not working as expected anyway. Oops, my mistake! many things moving around, and since I do not use this area myself... I did not notice the break.
Author
Member

Hi Llewellyn,
my code is working but I was missing the integration. Good to hear that you found a bug.

To have such a "abacus code field" is not necessary as you could also add some code to the PHP section "after getting items", which might be usable for calculations as mine.

If you have some time to add some functionality, it would be great if one could use SQL aggregate functions in the standard views (e.g. count(*) as counter etc.). At this point it is only possible by a custom "custom get" or by tweaking the items after getting the items ;-)

Did you have noticed my post in the Google group regarding the missing filters ("categories" e.g.)? This would also be a nice addition.

Regards
Manfred

Hi Llewellyn, my code is working but I was missing the integration. Good to hear that you found a bug. To have such a "abacus code field" is not necessary as you could also add some code to the PHP section "after getting items", which might be usable for calculations as mine. If you have some time to add some functionality, it would be great if one could use SQL aggregate functions in the standard views (e.g. count(*) as counter etc.). At this point it is only possible by a custom "custom get" or by tweaking the items after getting the items ;-) Did you have noticed my post in the Google group regarding the missing filters ("categories" e.g.)? This would also be a nice addition. Regards Manfred
Owner

time to add some functionality...

I actually do not have time, I can hardly believe that JCB exist... since I build it while not having time... with the purpose of saving time. lol

I am at the moment working on adding an Assistant to JCB to target the 80% of the Joomla world that is not yet programmers, but want to use JCB to build simple components with list, view, and edit for the front-end (site-views). You will see the staging branch already has parts of the GUI in it. Since I have been getting many requests to improve the front-end part of JCB. Which I am reluctant to do... (since i like the freedom it has) but with this Assistant I think we will solve many issues all in one.

> time to add some functionality... I actually do not have time, I can hardly believe that JCB exist... since I build it while not having time... with the purpose of saving time. lol I am at the moment working on adding an Assistant to JCB to target the 80% of the Joomla world that is not yet programmers, but want to use JCB to build simple components with list, view, and edit for the front-end (site-views). You will see the staging branch already has parts of the GUI in it. Since I have been getting many requests to improve the front-end part of JCB. Which I am reluctant to do... (since i like the freedom it has) but with this Assistant I think we will solve many issues all in one.
Author
Member

You can be sure to have the highest respect of the active community!

You can be sure to have the highest respect of the active community!
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#507
No description provided.