Welcome, Guest
Username: Password: Remember me

TOPIC:

Re: Version 2 - Manipulating data upon save 08 Nov 2012 00:48 #5106

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
or revert c. aliases back to m. if you wish...

It looks like you were selecting them from the table you're in already - you are in the cities table right?
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 08 Nov 2012 00:53 #5107

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
nope, in another table, but whatever
maDB->setQuery ("SELECT c.id FROM #__xxx_countries as c WHERE c.id = $this->city");
this can't work i guess... Selecting the country id from the countries table only if the country id = city id, i can't see how it would possibly be correct.

My query works the second time i save an item. The first time i save it, at creation, there it doesn't store the country, it only stores the city. The second time, it works very good

Please Log in or Create an account to join the conversation.

Last edit: by VeCrea.

Re: Version 2 - Manipulating data upon save 08 Nov 2012 01:02 #5108

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100

admin wrote: So I don't know.
It is in your hands. You will find.
Dump is your friend ;-)

Table > store() is the last call before the physical write in DB.

dumping the var for the $city gives me the correct INT
So why isn't my query working at the initial save, the initial store, although it's working if i edit and save...

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 08 Nov 2012 01:09 #5109

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Sorry you need a join...
maDB->setQuery ("SELECT DISTINCT c.id FROM #__xxx_countries as c 
LEFT JOIN (c.id ON #__xxx_cities.country);

Does that do it?
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Last edit: by JoomGuy. Reason: removed where

Re: Version 2 - Manipulating data upon save 08 Nov 2012 01:10 #5110

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
see edit
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 08 Nov 2012 01:21 #5111

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Sorry, you'll need a WHERE clause:

WHERE c.id = $this->city
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 08 Nov 2012 11:29 #5118

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
Hi... Doesn't really change anything, but once again, the problem is not in the query : this query works if i edit and save an item that was created. But at creation, the STORE function doesn't do its job with this query.

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 08 Nov 2012 11:58 #5119

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
The original query you had was taking the existing value in the current table - this is why it works on an edit...

That's why a join is needed in the save query. Otherwise (I believe) that this will not work on an edit if for instance you change the city to one from a different country.

The syntax might not be completely right but the principle is I believe... Not got time to look at this atm I'm afraid.

Hope it helps!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 13 Nov 2012 20:33 #5341

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
@VeCrea,

Did you get this sorted?

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 13 Nov 2012 20:42 #5342

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
Yes my dear
		if ($this->factwork != null) {
		$collabId = JFactory::getUser()->get('id');
		$maDB = $this->getDbo();
		$requete = $maDB->getQuery(true);
		$maDB->setQuery
		  ("SELECT w.role
		  FROM #__raptechs_workers AS w
		  WHERE w.technicien = $collabId");
		  $resultat = $maDB->loadResult();
		 
		$role = $resultat;
		  
		$maDB = $this->getDbo();
		$requete = $maDB->getQuery(true);
		$maDB->setQuery
		  ("SELECT r.rate
		  FROM #__raptechs_rates AS r
		  WHERE r.id = $role");
		$resultat = $maDB->loadResult();
		$rate = $resultat ;
		$duree = (($this->hfin * 60) + $this->mfin) - (($this->hdeb * 60) + $this->mdeb);
		$amount = $rate / 60 * $duree; 
		$this->factwork = $amount;
Thanks for the help.
The following user(s) said Thank You: JoomGuy

Please Log in or Create an account to join the conversation.

Last edit: by VeCrea.

Re: Version 2 - Manipulating data upon save 13 Nov 2012 21:14 #5343

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
This should shorten it and avoid loading the DBO twice/making 2 separate selects. It's using loadAssoc instead of 2 instances of load result so you can get the individual results in one, targetting the vars from $resultat->value where value is equal to any of the aliases set in the query... Should be a fair bit faster and less overhead...

Obviously, untested as I don't have your db and data so double check I've not mis-spelled anything but, it should work fine:
if ($this->factwork != null) {
	$collabId = JFactory::getUser()->get('id');
	$maDB = $this->getDbo();
	$requete = $maDB->getQuery(true);
	$maDB->setQuery
		("SELECT w.role AS role, r.rate as rate
		FROM #__raptechs_workers w
		LEFT JOIN #__raptechs_rates r ON(r.id = w.role)
		WHERE w.technicien =  $collabId");
	$resultat = $maDB->loadAssoc();
	
	$duree = (($this->hfin * 60) + $this->mfin) - (($this->hdeb * 60) + $this->mdeb);
	$this->factwork = $resultat->rate / 60 * $duree; 
}
Also, I've condensed the lines:
$amount = $rate / 60 * $duree; 
$this->factwork = $amount;
as you can see in the last line as I don't see the need to do the calculation, setting it as a local variable, only to set another by it.

Hope it helps,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The following user(s) said Thank You: VeCrea

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 13 Nov 2012 21:38 #5344

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Did it work?
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 14 Nov 2012 13:30 #5350

If you want to manipulate the data before saving you can do it like this:
public function save($data)
{
	$custom_value = 'Hello World';
	$data['table-field-name'] = $custom_value;
	parent::save($data);

	return true;
}

:-)
The following user(s) said Thank You: twev, JoomGuy

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 14 Nov 2012 14:37 #5351

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Thanks for sharing your solution @goslingcools!

@VeCrea - did the joined query work for you?

Cheers,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: Version 2 - Manipulating data upon save 21 Nov 2012 07:09 #5527

  • mark d
  • mark d's Avatar
  • Visitor
  • Visitor
Instead

e.data.myField = "constantPrefix" + e.data.myField;

use

var value = "constantPrefix" + e.get('myField');
e.set('myField', value);

model.set() is responsible to trigger necessary events, which the dataview does catch.

Please Log in or Create an account to join the conversation.

Time to create page: 0.092 seconds

I would like to Thank you for the Speed and the Quality of your work.
Pantelis (Forum)

Get Started