Author: sevein
Date: Sat Nov 28 18:08:29 2009
New Revision: 3991

Log:
Experimenting with fields less simples. ISDIAH -> Location and address.

Added:
   trunk/lib/QubitValidatorIsdiahLocationAndAddress.class.php   (contents, 
props changed)
Modified:
   trunk/apps/qubit/modules/repository/actions/showIsdiahAction.class.php

Modified: trunk/apps/qubit/modules/repository/actions/showIsdiahAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/repository/actions/showIsdiahAction.class.php      
Sat Nov 28 17:12:32 2009        (r3990)
+++ trunk/apps/qubit/modules/repository/actions/showIsdiahAction.class.php      
Sat Nov 28 18:08:29 2009        (r3991)
@@ -37,14 +37,14 @@
     $validatorSchema = new sfValidatorSchema;
     $validatorSchema->authorizedFormOfName = new 
sfValidatorString(array('required' => true), array('required' => 
$this->context->i18n->__('%1%Authorized form of name%2% - This is a mandatory 
field.', array('%1%' => '<a 
href="http://ica-atom.org/docs/index.php?title=RS-3#4.7";>', '%2%' => '</a>'))));
     $validatorSchema->identifier = new sfValidatorString(array('required' => 
true), array('required' => $this->context->i18n->__('%1%Identifier%2% - This is 
a mandatory field.', array('%1%' => '<a 
href="http://ica-atom.org/docs/index.php?title=RS-3#4.7";>', '%2%' => '</a>'))));
-    $validatorSchema->locationAndAddress = new 
QubitValidatorCountable(array('required' => true), array('required' => 
$this->context->i18n->__('%1%Location and address%2% - This is a mandatory 
field.', array('%1%' => '<a 
href="http://ica-atom.org/docs/index.php?title=RS-3#4.7";>', '%2%' => '</a>'))));
+    $validatorSchema->locationAndAddress = new 
QubitValidatorIsdiahLocationAndAddress;
 
     try
     {
       $validatorSchema->clean(array(
         'authorizedFormOfName' => $this->repository->authorizedFormOfName,
         'identifier' => $this->repository->identifier,
-        'locationAndAddress' => $this->repository->getContactInformation()));
+        'locationAndAddress' => $this->repository));
     }
     catch (sfValidatorErrorSchema $e)
     {

Added: trunk/lib/QubitValidatorIsdiahLocationAndAddress.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/lib/QubitValidatorIsdiahLocationAndAddress.class.php  Sat Nov 28 
18:08:29 2009        (r3991)
@@ -0,0 +1,61 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class QubitValidatorIsdiahLocationAndAddress extends sfValidatorBase
+{
+  /**
+   * @see sfValidatorBase
+   */
+  protected function configure($options = array(), $messages = array())
+  {
+    $this->setMessage('required', 'Location and address - %error%.');
+    $this->setOption('required', true);
+  }
+
+  /**
+   * @see sfValidatorBase
+   */
+  protected function doClean($value)
+  {
+    if (1 > strlen($value->getPrimaryContact()->getStreetAddress()) &&
+        1 > strlen($value->getPrimaryContact()->getCity()) &&
+        1 > strlen($value->getPrimaryContact()->getRegion()) &&
+        1 > strlen($value->getPrimaryContact()->getCountryCode()) &&
+        1 > strlen($value->getPrimaryContact()->getPostalCode()))
+    {
+
+      throw new sfValidatorError($this, 'required', array('error' => 'Primary 
contact exists but all fields about location and address are empty'));
+    }
+
+    return $value;
+  }
+
+  /**
+   * @see sfValidatorBase
+   */
+  protected function isEmpty($value)
+  {
+    if (1 > count($value->getPrimaryContact()))
+    {
+      throw new sfValidatorError($this, 'required', array('error' => 'A 
primary contact must be set.'));
+    }
+
+    return false;
+  }
+}

--

You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.


Reply via email to