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

TOPIC: New Data Type! Simple Calculation

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

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
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.
Last Edit: 03 Oct 2012 13:46 by admin.
The administrator has disabled public write access.
The following user(s) said Thank You: VeCrea, Tomaselli

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

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

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

  • LJ01
  • LJ01's Avatar
  • Offline
  • Senior Member
  • Posts: 78
  • Thank you received: 2
  • Karma: 0
how the 'so easy '?
LJ
Ce sont les fils qui font les cordes
ingall-niger.org
The administrator has disabled public write access.

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

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
Well you simply use the math operators of php...
$a + $b or things like that
The administrator has disabled public write access.

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

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

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

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
In a collection or one-item view ?
The administrator has disabled public write access.

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

  • LJ01
  • LJ01's Avatar
  • Offline
  • Senior Member
  • Posts: 78
  • Thank you received: 2
  • Karma: 0
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
The administrator has disabled public write access.

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

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
$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;
The administrator has disabled public write access.

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

  • LJ01
  • LJ01's Avatar
  • Offline
  • Senior Member
  • Posts: 78
  • Thank you received: 2
  • Karma: 0
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
Last Edit: 06 Sep 2012 16:17 by LJ01.
The administrator has disabled public write access.

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

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
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.
The administrator has disabled public write access.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
@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
The administrator has disabled public write access.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
... 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
The administrator has disabled public write access.

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

  • LJ01
  • LJ01's Avatar
  • Offline
  • Senior Member
  • Posts: 78
  • Thank you received: 2
  • Karma: 0
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
The administrator has disabled public write access.

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

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
I didn't even know it was possible to write it like this...
The administrator has disabled public write access.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
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
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.131 seconds

Get Started