Exemplo n.º 1
0
 /**
  * @covers Dropdown::toString
  */
 public function testToStringWithLink()
 {
     $optionValue = array("Fruition Brazil");
     $this->drop->setValue($optionValue);
     $this->drop = $this->drop->addOption("brazilia", "Fruition Brazil");
     $this->drop->setReadonlyLink(new \Link("fruitionsciences.com", "Fruition Sciences"));
     $actual = $this->drop->toString();
     $excepted = '<option value="Fruition Brazil">brazilia</option>';
     $this->assertEquals($excepted, $actual);
 }
Exemplo n.º 2
0
 protected function editObject(Model $oObject, $template = '')
 {
     $form = new Form();
     if ($_POST) {
         $this->save($oObject);
         $this->assign('updates', $this->updates);
         $this->assign('errors', $form->getErrors());
     }
     $fields = $oObject->getTableStructure();
     $isSetting = false;
     if ($oObject instanceof Setting) {
         $isSetting = true;
         $this->readOnlyFields[] = 'name';
         $this->readOnlyFields[] = 'info';
     }
     foreach ($fields as $fieldName => $field) {
         if ($isSetting && $fieldName == 'value') {
             $settingType = str_replace('BOOLEAN', 'tinyint(1)', $settingType);
             $settingType = str_replace('INTEGER', 'VARCHAR', $settingType);
             $settingType = str_replace('FLOAT', 'VARCHAR', $settingType);
             $field['Type'] = strtolower($settingType);
         }
         if (!is_numeric($fieldName) && !in_array($fieldName, $this->hideFields)) {
             $value = $oObject->{$fieldName};
             $fieldTable = convertDbFieldToTable($fieldName);
             if ($fieldName != 'nefub_id' && substr($fieldName, -3, 3) == '_id') {
                 // left join
                 if (substr($fieldName, -9, 9) == '_nefub_id') {
                     // left join on nefub_id
                     $split = explode('_nefub_id', $fieldName);
                     $valueField = 'nefub_id';
                 } else {
                     // left join on id
                     $split = explode('_id', $fieldName);
                     $valueField = 'id';
                 }
                 $fieldTable = convertDbFieldToTable($fieldName);
                 if ($fieldTable == 'Game') {
                     $input = new GameDropdown($fieldName, $value, $oObject->getGame());
                 } elseif ($fieldTable == 'Team') {
                     $input = new TeamDropdown($fieldName, $value);
                 } elseif ($fieldTable == 'Location') {
                     $input = new LocationDropdown($fieldName, $value);
                 } else {
                     $input = new ModelDropdown($fieldName, $value, $fieldTable, $valueField);
                 }
             } else {
                 if (substr(strtolower($field['Type']), 0, 4) == 'enum') {
                     $input = new EnumDropdown($fieldName, $value, $field['Type']);
                     if ($isSetting) {
                         $settingType = $value;
                     }
                 } else {
                     if ($fieldName != 'nefub_id' && substr($field['Type'], 0, 3) == 'int') {
                         $length = substr($field['Type'], 4, strlen($field['Type']) - 2);
                         if ($length >= 5) {
                             $input = new InputText($fieldName, $value);
                             $input->addValidator(new IntegerValidator(true, 0, pow(10, $length)));
                         } else {
                             $input = new NumericDropdown($fieldName, $value, 0, pow(10, $length) - 1);
                         }
                     } else {
                         if ($fieldName == 'Period') {
                             $values = array(1 => 1, 2 => 2, 3 => 3);
                             $input = new RadioButton($fieldName, $values, $value);
                         } else {
                             if ($field['Type'] == 'int(1)' || $field['Type'] == 'tinyint(1)') {
                                 $input = new RadioBoolean($fieldName, $value);
                             } else {
                                 if ($field['Type'] == 'time' && $oObject->getTable() != 'GameAction') {
                                     $input = new Dropdown($fieldName, $value);
                                     for ($i = 0; $i < 24; $i++) {
                                         $hour = $i;
                                         if ($hour < 10) {
                                             $hour = '0' . $hour;
                                         }
                                         for ($j = 0; $j < 60; $j += 10) {
                                             $minute = $j;
                                             if ($minute < 10) {
                                                 $minute = '0' . $minute;
                                             }
                                             $time = $hour . ':' . $minute;
                                             $input->addOption($time, $time . ':00');
                                         }
                                     }
                                 } elseif ($field['Type'] == 'text') {
                                     $input = new TextArea($fieldName, $value);
                                 } else {
                                     $input = new InputText($fieldName, $value);
                                 }
                             }
                         }
                     }
                 }
             }
             // read-only fields
             if (in_array($fieldName, $this->readOnlyFields)) {
                 $input->setExtraAttribute('disabled', 'disabled');
             }
             if ($field['Null'] == 'NO') {
                 $input->addValidator(new Validator());
             }
             $form->addElement($input, $fieldName);
         }
     }
     $this->assign('form', $form);
     $this->assign('subject', $this->subject);
     $this->assign('backUrl', '/' . $this->subject);
     $this->assign('o' . get_class($oObject), $oObject);
     $this->showObjectView($oObject, $template);
 }
Exemplo n.º 3
0
 private function getPMDropdown()
 {
     $selectPM = new Dropdown("_" . $this->getName() . "_pm");
     $selectPM->set("id", "_" . $this->getName() . "_pm");
     $selectPM->addOption("am", "am")->addOption("pm", "pm");
     $selectPM->set("class", "dateBox");
     $selectPM->set("onchange", "updateHiddenTimeField('" . $this->getName() . "')");
     return $selectPM;
 }