Welcome, Guest
Username: Password: Remember me

TOPIC: Table + pivot on another table combined on cpanel

Table + pivot on another table combined on cpanel 15 Oct 2017 22:38 #15374

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
Hi

I'm scratching my head a bit - I want to create a cpanel page, where I have an output from latest orders table, but also to summarize using a pivot table positions (cash amount) on currencies.
See www.dropbox.com/s/1hthbr2ob8m90ea/table-...d-on-cpanel.png?dl=0

Can I load 2 sets of items in my model somehow?

EDIT: Added on wrong forum - should have been coding inside your component... sorry
Last Edit: 15 Oct 2017 22:39 by dyvel.
The administrator has disabled public write access.

Table + pivot on another table combined on cpanel 16 Oct 2017 11:21 #15376

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 290
  • Thank you received: 125
  • Karma: 48
If you want to create a cpanel like in your image I would suggest:

- create a view in one of the tabels you want (like orders)
- fork the grid
- you can get any data you want with orm, so you can get whatever collection you want with $data = YourComponentHelper::getData('yourothermodel',array(<orm statements here>));
- build the cpanel you want with divs, tables, etc :)
The administrator has disabled public write access.
The following user(s) said Thank You: dyvel

Table + pivot on another table combined on cpanel 16 Oct 2017 11:24 #15377

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
That's really interesting - didn't know I could access other model data this way!
Thank you :-)
The administrator has disabled public write access.

Table + pivot on another table combined on cpanel 16 Oct 2017 11:35 #15378

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 290
  • Thank you received: 125
  • Karma: 48
ORM is really powerful

www.j-cook.pro/index.php/o/orm-system
The administrator has disabled public write access.

Table + pivot on another table combined on cpanel 16 Oct 2017 17:37 #15379

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
I'm getting there - I can now get my data, but only by requesting them in my view. To do it right (the MVC way), I believe I should request the data in my model, not in the view...

I added this to my view.html.php
$this->statistics	= $statistics = BankmanagerHelper::getData(
		'currencies',array(
			'select' => array(
					'currency_name',
					'currency_short_name',
					'currency_symbol',
					'ordering'
				),
				'relation' => array(
		
					// LOAD Positions (N:1 relation)
					'positions' => array(
						'select' => 'amount'
					)
				)
			)
		);

so now I can access it in my view file through $this->statistics

I just think this more or less belongs in the model...
Last Edit: 16 Oct 2017 17:42 by dyvel.
The administrator has disabled public write access.

Table + pivot on another table combined on cpanel 17 Oct 2017 07:42 #15381

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 290
  • Thank you received: 125
  • Karma: 48
MVC is just a pattern for separation.
There is nothing wrong with using multiple models in 1 view.
The administrator has disabled public write access.

Table + pivot on another table combined on cpanel 17 Oct 2017 08:38 #15385

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3702
  • Thank you received: 975
  • Karma: 141
Yes that's discutable. It is just a question of preference.
In facts, if you are a purist, you can create SQL query profiles (context) for every request, but to my opinion it is too excessive.

Ask you the question : Why such convention ?
-> Because if you add some SQL restriction feature to your table (published for instance), then you must apply it to all your SQL calls and not forget anything. The model is made for that.

So I would say, until you always USE the model for requesting datas it is fine. Just put all restrictions in prepareQuery() which is common for all calls. Then you will have much more confort in calling datas with ORM where you want. It is precisely the idea for a clean and readable code. Until you don't repeat yourself (DRY), all is fine and clean.
Sometimes you will need datas called from a helper, sometimes in the controller to check something... I don't know it can be anywhere.
Joomla has enough conventions, don't limit yourself and your creativity, creating a mess of requests and context profiles.

Profiles are made to be reusable, but sometimes you don't need all the columns selected by a reused profile and you can loose in performances, so.... It all depends your style.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: dyvel

Table + pivot on another table combined on cpanel 17 Oct 2017 10:25 #15395

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 290
  • Thank you received: 125
  • Karma: 48
Like admin said, you can also fork the Helper with functions.
I did in one of my components, to calculate some prices which I needed in different area's.
If you need help, that's what we are here for.
The administrator has disabled public write access.
The following user(s) said Thank You: dyvel
Time to create page: 0.082 seconds

Get Started