Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC:

New Data Type! Simple Calculation 27 Apr 2012 23:39 #2172

  • edwardcox
  • edwardcox's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
OMG, this one just came to mind and I guess it's mainly for 'dummies' like me (i.e. real entry level Cook users LOL).

A new Data Type (or Wizard): Simple Calculation. Allowing as a start 2 existing Fields to be selected AND an Operand (i.e. Addition, Subtraction, Multiplication, Divide).

So that a beginner can include simple math calculations in their Layouts.

i.e.

Value 1: Field number_of_days (int)
Value 2: Field amount (int xx.xx)
Operand: MULTIPLY
Simple Calculation Field: Result (Value 1 multiplied by Value 2)

I think that might put the idea across. Please ask if unclear.

To me this would be a fantastic addition.

Thank you,

Edward.
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
The following user(s) said Thank You: VeCrea, Tomaselli

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

Last edit: by admin.

Re: New Data Type! Simple Calculation 28 Apr 2012 13:14 #2174

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
+1
So easy to add in code afterwards, but why not have a wizard for it...

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

Re: New Data Type! Simple Calculation 06 Sep 2012 13:45 #3393

  • LJ01
  • LJ01's Avatar
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 78
  • Thank you received: 2
how the 'so easy '?
LJ
Ce sont les fils qui font les cordes
ingall-niger.org

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

Re: New Data Type! Simple Calculation 06 Sep 2012 14:04 #3394

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
Well you simply use the math operators of php...
$a + $b or things like that

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

Re: New Data Type! Simple Calculation 06 Sep 2012 16:08 #3396

  • LJ01
  • LJ01's Avatar
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 78
  • Thank you received: 2
yes but how to register the result in a field ?
LJ
Ce sont les fils qui font les cordes
ingall-niger.org

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

Re: New Data Type! Simple Calculation 06 Sep 2012 16:09 #3397

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
In a collection or one-item view ?

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

Re: New Data Type! Simple Calculation 06 Sep 2012 16:12 #3398

  • LJ01
  • LJ01's Avatar
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 78
  • Thank you received: 2
this is the code for a field
<?php echo JDom::_('html.form.input.text', array(
					'dataKey' => 'year',
					'dataObject' => $this->climatpraticitem,
					'size' => "5",
					'validatorHandler' => "numeric"
					));
				?>
i want to include the result variable '$variable'
how to include it automaticly
Ce sont les fils qui font les cordes
ingall-niger.org

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

Re: New Data Type! Simple Calculation 06 Sep 2012 16:15 #3399

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
$a = JDom::_('html.form.input.text', array(
					'dataKey' => 'year',
					'dataObject' => $this->climatpraticitem,
					'size' => "5",
					'validatorHandler' => "numeric"
					));
$b = JDom::_('html.form.input.text', array(
					'dataKey' => 'year',
					'dataObject' => $this->otherfield,
					'size' => "5",
					'validatorHandler' => "numeric"
					));
$result = $a + b;
echo $result;

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

Re: New Data Type! Simple Calculation 06 Sep 2012 16:17 #3400

  • LJ01
  • LJ01's Avatar
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 78
  • Thank you received: 2
yes but i want that the result registering in a field existing in my bd
LJ
Ce sont les fils qui font les cordes
ingall-niger.org

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

Last edit: by LJ01.

Re: New Data Type! Simple Calculation 06 Sep 2012 16:21 #3401

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
I think that better coders than me would have to answer this, but i don't think there's any need in storing the result of two db fields in a third field...
Anyway, if you want this, i think you have to add a field to your table manually via phpmyadmin, then modify the model file, or the corresponding table field in the administrator part of your component.
That's my 2 cents, but i believe Admin will have a more definitive approach on this.

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

Re: New Data Type! Simple Calculation 06 Sep 2012 17:05 #3402

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
@VeCrea,

Your solution is incorrect.
JDom return strings, so it is not only incorrect but also dangerous.


Why always searching for complexity ?
echo $this->climatpraticitem->year + $this->otherfield->year;
Coding is now a piece of cake

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

Re: New Data Type! Simple Calculation 06 Sep 2012 17:06 #3403

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
... And if you want this result stored in DB, go in your table and write this operation before to save in table.
Coding is now a piece of cake

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

Re: New Data Type! Simple Calculation 06 Sep 2012 17:46 #3405

  • LJ01
  • LJ01's Avatar
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 78
  • Thank you received: 2
i want to stored my result '$result' in the field 'calcul' that existing in my db
where put the code before save, what file ?
lj
Ce sont les fils qui font les cordes
ingall-niger.org

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

Re: New Data Type! Simple Calculation 06 Sep 2012 17:58 #3407

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
I didn't even know it was possible to write it like this...

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

Re: New Data Type! Simple Calculation 06 Sep 2012 18:09 #3408

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
1. open the concerned table php file

2. go to the check() function.
(Executed everytime before to save)

3. Write all the new values coming from the result of your calcul

That's it

PS : As you know, I prefer you try to find by yourself, and understand how the MVC works.
Coding is now a piece of cake

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

  • Page:
  • 1
  • 2
Time to create page: 0.092 seconds

This is what you call a component builder. I was able to master using this in a very short time and the resulting component works like a charm. Not just a basic component builder but a fully working component builder with forms fields tables all ready to go. You can make the list and item views to display in the front and back end. Also there is a great forum just starting to evolve and I'm sure this will grow very rapidly when you all realise how good this tool is.
Kevin (JED)

         

Get Started