Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
Person.php
Go to the documentation of this file.
1 <?php
15  function buildAttributes(){
16  $this->fieldnames = array();
17  $this->attributes = array();
18 
19  $email = null;
20  // First let's find the email field.
21 
22  // First we'll check to see if any fields have been explicitly
23  // flagged as email address fields.
24  foreach ( $this->table->fields(false,true) as $field ){
25  if ( @$field['email'] ){
26  $email = $field['name'];
27  break;
28  }
29  }
30  if ( !isset($email) ){
31  // Next lets see if any of the fields actually contain the word
32  // email in the name
33  $candidates = preg_grep('/(email)/i', array_keys($this->table->fields()));
34  foreach ( $candidates as $candidate ){
35  if ( $this->table->isChar($candidate) ){
36  $email = $candidate;
37  break;
38  }
39  }
40  }
41 
42  if ( isset($email) ){
43  $field =& $this->table->getField($email);
44  $this->attributes['email'] =& $field;
45  unset($field);
46  $this->fieldnames['email'] = $email;
47  }
48 
49  return true;
50 
51  }
52 
53  function validate_email($value, $allowBlanks=true){
54  if ( !$allowBlanks and !trim($value) ) return false;
55 
56  return preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $value);
57  }
58 
59 }