~fabiocbalbuquerque/sahana-agasti/web-services

« back to all changes in this revision

Viewing changes to apps/frontend/lib/form/doctrine/agEmbeddedGeoAddressForm.class.php

  • Committer: Nils Stolpe
  • Date: 2011-07-25 05:44:44 UTC
  • mto: (1.26.1 push-trunk)
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: nils.stolpe@mail.cuny.edu-20110725054444-mo2uz3wwu1jcoikg
Geo data has been fully implemented for staff and facilities.

Errors will display after form submit if incorrect data has been entered into the geofields, or if one of lat and long has been left blank.
Both filled and both empty will submit normally.
Geo data can be unlinked from an address by clearing geo fields in the address form and saving the address otherwise unaltered.
Saving an address form with only geo data, but no address data, will save nothing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
    unset($this['created_at'], $this['updated_at']);
21
21
 
22
 
    $this->setValidator('longitude', new sfValidatorNumber(array('required' => false)));
23
 
    $this->setValidator('latitude', new sfValidatorNumber(array('required' => false)));
 
22
    $this->setValidator('longitude', new sfValidatorNumber(array('required' => false, 'min' => 0, 'max' => 180)));
 
23
    $this->setValidator('latitude', new sfValidatorNumber(array('required' => false, 'min' => 0, 'max' => 90)));
24
24
//    $this->setValidators(array(
25
25
//      'id'         => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
26
26
//      'longitude'  => new sfValidatorNumber(),
30
30
//    ));
31
31
 
32
32
    $this->getWidget('latitude')->setLabel('Lat');
33
 
    $this->getWidget('latitude')->setAttribute('class', 'inputGray');
 
33
    $this->getWidget('latitude')->setAttribute('class', 'inputGray address-geo');
34
34
 
35
35
    $this->getWidget('longitude')->setLabel('Long');
36
 
    $this->getWidget('longitude')->setAttribute('class', 'inputGray');
 
36
    $this->getWidget('longitude')->setAttribute('class', 'inputGray address-geo');
37
37
 
38
38
    $custDeco = new agFormatterTopLabel($this->getWidgetSchema());
39
39
    $this->getWidgetSchema()->addFormFormatter('custDeco', $custDeco);
40
40
    $this->getWidgetSchema()->setFormFormatterName('custDeco');
 
41
 
 
42
    $this->validatorSchema->setPostValidator(
 
43
      new sfValidatorCallback(array('callback' => array($this, 'checkStateBoth')))
 
44
    );
 
45
  }
 
46
 
 
47
  /*
 
48
   * A function to validate whether longitude and latitude have both been passed
 
49
   * in with the form. Errors when one is NULL and the other not NULL.
 
50
   */
 
51
  public function checkStateBoth($validator, $values)
 
52
  {
 
53
    if(($values['latitude'] == NULL && $values['longitude'] <> NULL) ||
 
54
       ($values['latitude'] <> NULL && $values['longitude'] == NULL)
 
55
    ) {
 
56
      throw new sfValidatorError($validator, 'Please set both latitude and longitude');
 
57
    }
 
58
    return $values;
41
59
  }
42
60
}