Source of file AncestryField.php
Size: 4,595 Bytes - Last Modified: 2021-12-23T10:47:29+00:00
/var/www/docs.ssmods.com/process/src/code/forms/AncestryField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 | <?php /** * * @package userforms * @subpackage relatives */ class AncestryField extends FormField { /** * @var nameField */ //level 1 protected static $array_of_ancestors = array( "mField" => "Mother", "fField" => "Father", //level 2 "mmField" => "Mother's Mother", "mfField" => "Mother's Father", "fmField" => "Father's Mother", "ffField" => "Father's Father", //level 3 "mmmField" => "Mother's Mother's Mother", "mmfField" => "Mother's Mother's Father", "mfmField" => "Mother's Father's Mother", "mffField" => "Mother's Father's Father", "fmmField" => "Father's Mother's Mother", "fmfField" => "Father's Mother's Father", "ffmField" => "Father's Father's Mother", "fffField" => "Father's Father's Father", //level 4 "mmmmField" => "Mother's Mother's Mother's Mother", "mmmfField" => "Mother's Mother's Mother's Father", "mmfmField" => "Mother's Mother's Father's Mother", "mmffField" => "Mother's Mother's Father's Father", "mfmmField" => "Mother's Father's Mother's Mother", "mfmfField" => "Mother's Father's Mother's Father", "mffmField" => "Mother's Father's Father's Mother", "mfffField" => "Mother's Father's Father's Father", "fmmmField" => "Father's Mother's Mother's Mother", "fmmfField" => "Father's Mother's Mother's Father", "fmfmField" => "Father's Mother's Father's Mother", "fmffField" => "Father's Mother's Father's Father", "ffmmField" => "Father's Father's Mother's Mother", "ffmfField" => "Father's Father's Mother's Father", "fffmField" => "Father's Father's Father's Mother", "ffffField" => "Father's Father's Father's Father" ); public static function get_array_of_ancestors() { return self::$array_of_ancestors; } public static function set_array_of_ancestors($a) { self::$array_of_ancestors = $a; } protected $fieldHolder = array(); public function __construct($name, $title = null, $value = "") { foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { $this->fieldHolder[$key] = new TextField($name . '['.$key.']', $fieldTitle); } parent::__construct($name, $title, $value); } public function setForm($form) { parent::setForm($form); foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { $this->fieldHolder[$key]->setForm($form); } } public function Field() { Requirements::themedCSS("AncestryField"); Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); Requirements::javascript("userforms_relatives/javascript/AncestryField.js"); $html = ""; foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { $levelClass = "level".(strlen($key)-5); $nextLevels = ".".str_replace("Field", "mField", $key).", .".str_replace("Field", "fField", $key); $html .= "<div class=\"$key $levelClass ancestorNode \" rel=\"$nextLevels\">".$this->fieldHolder[$key]->SmallFieldHolder()."</div>"; } return $html; } /** */ public function setValue($val) { if (empty($val)) { foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { $this->fieldHolder[$key]->setValue(null); } } else { // String setting is only possible from the database, so we don't allow anything but ISO format if (is_string($val)) { //TO DO } // Setting from form submission elseif (is_array($val)) { foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { $myValue = isset($val[$key]) ? $val[$key] : ""; $this->fieldHolder[$key]->setValue($myValue); } } else { $this->nameField->setValue($val); $this->dobField->setValue($val); $this->sexField->setValue($val); } } } public function dataValue() { $array = array(); foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { $array[$key] = $this->fieldHolder[$key]->dataValue(); } return $array; } public function Icon() { return 'userforms/images/' . strtolower($this->class) . '.png'; } } |