示例#1
0
 public function __construct($label = "", $name = "", $descriptiom = "")
 {
     parent::__construct($label, $name, $description);
     for ($i = 1900; $i < 2200; $i++) {
         $this->addOption($i);
     }
 }
示例#2
0
 /**
  * Add an option to the composite.	
  * 
  * @param object ReusableOption &$option  The option to be added to the composite.
  * @return boolean	True if options could be added (composite), false otherwise.
  * @access public
  */
 function addChild(&$option)
 {
     if (is_a($option, 'RadioButtonOption')) {
         //all radiobuttons in a group must have the name of the group
         $option->setOptionName($this->getName());
         return parent::addChild($option);
     }
     return false;
 }
示例#3
0
 /**
  * Add an option to the composite.	
  * 
  * @param object ReusableOption &$option  The option to be added to the composite.
  * @return boolean	True if options could be added (composite), false otherwise.
  * @access public
  */
 function addChild(&$option)
 {
     if (is_a($option, 'RO_CheckBoxListOption')) {
         //all checkboxes in a list must have the name of the group
         $option->setOptionName($this->getName());
         return parent::addChild($option);
     }
     return false;
 }
示例#4
0
 public function __construct($label = "", $name = "", $descriptiom = "")
 {
     parent::__construct($label, $name, $description);
     $this->addOption("January", "01");
     $this->addOption("February", "02");
     $this->addOption("March", "03");
     $this->addOption("April", "04");
     $this->addOption("May", "05");
     $this->addOption("June", "06");
     $this->addOption("July", "07");
     $this->addOption("August", "08");
     $this->addOption("September", "09");
     $this->addOption("October", "10");
     $this->addOption("November", "11");
     $this->addOption("December", "12");
 }
 /**
  * Returns a form to be used to filter the report. This method analyses the
  * XML file and uses the fields specified in there to generate a very form
  * which allows you to define filter for the form. The form generated also
  * gives you options to sort and group the reports.
  * @return Form
  */
 public function getForm()
 {
     $this->initializeForm();
     $filters = array();
     $fieldInfos = array();
     $queries = $this->xml->xpath("/rapi:report/rapi:query");
     $tables = $this->xml->xpath("/rapi:report/rapi:table");
     /// Filters and sorting.
     foreach ($tables as $table) {
         $numConcatFields = 0;
         $fields = $table->xpath("/rapi:report/rapi:table[@name='{$table["name"]}']/rapi:fields/rapi:field");
         $labels = $table->xpath("/rapi:report/rapi:table[@name='{$table["name"]}']/rapi:fields/rapi:field/@label");
         $filters = new TableLayout(count($fields) + 1, 5);
         $filters->add(Element::create("Label", "Field")->addCssClass("header-label"), 0, 0)->add(Element::create("Label", "Options")->addCssClass("header-label"), 0, 1)->add(Element::create("Label", "Exclude")->addCssClass("header-label"), 0, 4)->resetCssClasses()->addCssClass("filter-table")->setRenderer("default");
         $sortingField = new SelectionList("Sorting Field", "{$table["name"]}_sorting_field");
         $grouping1 = new SelectionList();
         $i = 1;
         foreach ($fields as $key => $field) {
             if (isset($field["labelsField"])) {
                 continue;
             }
             if (count(explode(",", (string) $field)) == 1) {
                 $fieldInfo = Model::resolvePath((string) $field);
                 $model = Model::load($fieldInfo["model"]);
                 $fieldName = $fieldInfo["field"];
                 $fieldInfo = $model->getFields(array($fieldName));
                 $fieldInfo = $fieldInfo[0];
                 $fields[$key] = (string) $field;
                 $sortingField->addOption(str_replace("\\n", " ", $fieldInfo["label"]), $model->getDatabase() . "." . $fieldInfo["name"]);
                 $grouping1->addOption(str_replace("\\n", " ", $field["label"]), (string) $field);
                 if (array_search($model->getKeyField(), $this->referencedFields) === false || $fieldInfo["type"] == "double" || $fieldInfo["type"] == "date") {
                     switch ($fieldInfo["type"]) {
                         case "integer":
                         case "double":
                             $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Equals", "EQUALS")->addOption("Greater Than", "GREATER")->addOption("Less Than", "LESS")->addOption("Between", "BETWEEN")->setValue("BETWEEN"), $i, 1)->add(Element::create("TextField", "", "{$table["name"]}.{$fieldInfo["name"]}_start_value")->setAsNumeric(), $i, 2)->add(Element::create("TextField", "", "{$table["name"]}.{$fieldInfo["name"]}_end_value")->setAsNumeric(), $i, 3);
                             //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4);
                             break;
                         case "date":
                         case "datetime":
                             $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Before", "LESS")->addOption("After", "GREATER")->addOption("On", "EQUALS")->addOption("Between", "BETWEEN")->setValue("BETWEEN"), $i, 1)->add(Element::create("DateField", "", "{$table["name"]}.{$fieldInfo["name"]}_start_date")->setId("{$table["name"]}_{$fieldInfo["name"]}_start_date"), $i, 2)->add(Element::create("DateField", "", "{$table["name"]}.{$fieldInfo["name"]}_end_date")->setId("{$table["name"]}_{$fieldInfo["name"]}_end_date"), $i, 3);
                             //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4);
                             break;
                         case "enum":
                             $enum_list = new SelectionList("", "{$table["name"]}.{$fieldInfo["name"]}_value");
                             $enum_list->setMultiple(true);
                             foreach ($fieldInfo["options"] as $value => $label) {
                                 $enum_list->addOption($label, $value);
                             }
                             if (!isset($field["value"])) {
                                 $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Is any of", "INCLUDE")->addOption("Is none of", "EXCLUDE")->setValue("INCLUDE"), $i, 1)->add($enum_list, $i, 2);
                             }
                             //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4);
                             break;
                         case "string":
                         case "text":
                             $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Is exactly", "EXACTLY")->addOption("Contains", "CONTAINS")->setValue("CONTAINS"), $i, 1)->add(Element::create("TextField", "", "{$table["name"]}.{$fieldInfo["name"]}_value"), $i, 2);
                             //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4);
                             break;
                     }
                     if (isset($field["hide"])) {
                         $filters->add(Element::create("HiddenField", "{$table["name"]}.{$fieldInfo["name"]}_ignore", "1"), $i, 4);
                     } else {
                         $filters->add(Element::create("Checkbox", "", "{$table["name"]}.{$fieldInfo["name"]}_ignore", "", "1"), $i, 4);
                     }
                 } else {
                     $enum_list = new ModelSearchField();
                     $enum_list->setName("{$table["name"]}.{$fieldInfo["name"]}_value");
                     $enum_list->setModel($model, $fieldInfo["name"]);
                     $enum_list->addSearchField($fieldInfo["name"]);
                     $enum_list->boldFirst = false;
                     $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Is any of", "IS_ANY_OF")->addOption("Is none of", "IS_NONE_OF")->setValue("IS_ANY_OF"), $i, 1)->add(Element::create("MultiFields")->setTemplate($enum_list), $i, 2)->add(Element::create("Checkbox", "", "{$table["name"]}.{$fieldInfo["name"]}_ignore", "", "1"), $i, 4);
                 }
             } else {
                 $grouping1->addOption(str_replace("\\n", " ", $field["label"]), $field);
                 $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}_concat_{$numConcatFields}_option")->addOption("Is exactly", "EXACTLY")->addOption("Contains", "CONTAINS")->setValue("CONTAINS"), $i, 1)->add(Element::create("TextField", "", "{$table["name"]}_concat_{$numConcatFields}_value"), $i, 2)->add(Element::create("Checkbox", "", "{$table["name"]}_concat_{$numConcatFields}_ignore", "", "1"), $i, 4);
                 $numConcatFields++;
             }
             $i++;
         }
         $grouping1->setName("{$table["name"]}_grouping[]")->setLabel("Grouping Field 1");
         $g1Paging = new Checkbox("Start on a new page", "grouping_1_newpage", "", "1");
         $g1Logo = new Checkbox("Repeat Logos", "grouping_1_logo", "", "1");
         $g1Summarize = new Checkbox("Summarize", "grouping_1_summary", "", "1");
         $grouping2 = clone $grouping1;
         $grouping2->setName("{$table["name"]}_grouping[]")->setLabel("Grouping Field 2");
         $g2Paging = new Checkbox("Start on a new page", "grouping_2_newpage", "", "1");
         $g2Logo = new Checkbox("Repeat Logos", "grouping_2_logo", "", "1");
         $grouping3 = clone $grouping1;
         $grouping3->setName("{$table["name"]}_grouping[]")->setLabel("Grouping Field 3");
         $g3Paging = new Checkbox("Start on a new page", "grouping_3_newpage", "", "1");
         $g3Logo = new Checkbox("Repeat Logos", "grouping_3_logo", "", "1");
         $sortingField->setLabel("Sorting Field");
         $sortingField->setName($table["name"] . "_sorting");
         $groupingTable = new TableLayout(3, 4);
         $groupingTable->add($grouping1, 0, 0);
         $groupingTable->add($g1Paging, 0, 1);
         $groupingTable->add($g1Logo, 0, 2);
         $groupingTable->add($g1Summarize, 0, 3);
         $groupingTable->add($grouping2, 1, 0);
         /* $groupingTable->add($g2Paging, 1, 1);
            $groupingTable->add($g2Logo, 1, 2); */
         $groupingTable->add($grouping3, 2, 0);
         $container = new FieldSet($table["name"]);
         $container->setId("{$table["name"]}_options");
         $container->add(Element::create("FieldSet", "Filters")->add($filters)->setId("table_{$table['name']}"), Element::create("FieldSet", "Sorting & Limiting")->add($sortingField, Element::create("SelectionList", "Direction", "{$table["name"]}.sorting_direction")->addOption("Ascending", "ASC")->addOption("Descending", "DESC"), Element::create('TextField', 'Limit', "{$table['name']}.limit")->setAsNumeric())->setId("{$table['name']}_sorting_fs"), Element::create("FieldSet", "Grouping")->setId("{$table['name']}_grouping_fs")->add($groupingTable));
         $sortingField->setName($table["name"] . "_sorting");
         $this->form->add($container);
     }
     $this->form->setSubmitValue("Generate");
     $this->form->addAttribute("action", $this->path . "/generate");
     $this->form->addAttribute("target", "blank");
     return $this->form;
 }
示例#6
0
 public function constraints($params)
 {
     //Load necessary Models
     $roleModel = Model::load('auth.roles');
     $constraintModel = Model::load('auth.constraints');
     $role = $roleModel->getWithField('role_id', $params[0]);
     $constraints = $constraintModel->getWithField("role_id", "{$params['0']}");
     //Label at the top of the inner template
     $this->label = "Login Constraints for the '" . $role[0]['role_name'] . "' role";
     //create a new form
     $form = new Form();
     $form->setRenderer("default");
     //Fieldset to group days of week checkboxes
     $daysFieldset = Element::create('ColumnContainer', 7);
     //create checkbox fields and set their respective values
     $mon = Element::create("Checkbox", "Monday", "mon", "", "1");
     $mon->setValue(($constraints[0]['days_of_week_value'] & 1) == 1 ? "1" : "0");
     $daysFieldset->add($mon);
     $tue = Element::create("Checkbox", "Tuesday", "tue", "", "2");
     $tue->setValue(($constraints[0]['days_of_week_value'] & 2) == 2 ? "2" : "0");
     $daysFieldset->add($tue);
     $wed = Element::create("Checkbox", "Wednesday", "wed", "", "4");
     $wed->setValue(($constraints[0]['days_of_week_value'] & 4) == 4 ? "4" : "0");
     $daysFieldset->add($wed);
     $thu = Element::create("Checkbox", "Thursday", "thu", "", "8");
     $thu->setValue(($constraints[0]['days_of_week_value'] & 8) == 8 ? "8" : "0");
     $daysFieldset->add($thu);
     $fri = Element::create("Checkbox", "Friday", "fri", "", "16");
     $fri->setValue(($constraints[0]['days_of_week_value'] & 16) == 16 ? "16" : "0");
     $daysFieldset->add($fri);
     $sat = Element::create("Checkbox", "Saturday", "sat", "", "32");
     $sat->setValue(($constraints[0]['days_of_week_value'] & 32) == 32 ? "32" : "0");
     $daysFieldset->add($sat);
     $sun = Element::create("Checkbox", "Sunday", "sun", "", "64");
     $sun->setValue(($constraints[0]['days_of_week_value'] & 64) == 64 ? "64" : "0");
     $daysFieldset->add($sun);
     $form->add($daysFieldset);
     //FieldSet to group beginning time section
     $beginningTimeFieldset = Element::create('ColumnContainer', 2);
     //Starting times
     $timeRangeStartFieldSet = Element::create("FieldSet", "Beginning Time");
     $hourStartSelection = Element::create("SelectionList", "Hour", "hour_start");
     //add all options to the hour start selection field
     for ($i = 0; $i <= 23; $i++) {
         $hourStartSelection->addOption(sprintf("%02d", $i));
     }
     //add hour start to begin time range field set
     $beginningTimeFieldset->add($hourStartSelection);
     $minuteStartSelection = Element::create("SelectionList", "Minutes", "minutes_start");
     //add all options to the minute start selection field
     for ($i = 0; $i <= 59; $i++) {
         $minuteStartSelection->addOption(sprintf("%02d", $i));
     }
     //add minute start to begin time range field set
     $beginningTimeFieldset->add($minuteStartSelection)->addAttribute('style', 'width:30%');
     //Add the column container fieldset to the main fieldset
     $timeRangeStartFieldSet->add($beginningTimeFieldset);
     $endingTimeFieldset = Element::create('ColumnContainer', 2);
     //Ending times
     $timeRangeEndFieldSet = Element::create("FieldSet", "Ending Time");
     $hourEndSelection = Element::create("SelectionList", "Hour", "hour_end");
     //add all options to the hour end selection field
     for ($i = 0; $i <= 23; $i++) {
         $hourEndSelection->addOption(sprintf("%02d", $i));
     }
     $endingTimeFieldset->add($hourEndSelection);
     $minuteEndSelection = Element::create("SelectionList", "Minutes", "minutes_end");
     //add all options to the minute end selection field
     for ($i = 0; $i <= 59; $i++) {
         $minuteEndSelection->addOption(sprintf("%02d", $i));
     }
     $endingTimeFieldset->add($minuteEndSelection)->addAttribute('style', 'width:30%');
     //Add the column container fieldset to the main fieldset
     $timeRangeEndFieldSet->add($endingTimeFieldset);
     $modeSelection = new SelectionList("Mode", "mode");
     $modeSelection->addOption("Allow", "allow");
     $modeSelection->addOption("Deny", "deny");
     $roleIdHiddenField = Element::create("HiddenField", "role_id", $params[0]);
     //populate fields with values from database if the data for that partular role already exists
     if ($constraints[0] != null) {
         $hourStartSelection->setValue(substr($constraints[0]['time_range_start'], 0, 2));
         $hourEndSelection->setValue(substr($constraints[0]['time_range_end'], 0, 2));
         $minuteStartSelection->setValue(substr($constraints[0]['time_range_start'], 3));
         $minuteEndSelection->setValue(substr($constraints[0]['time_range_end'], 3));
         $modeSelection->setValue($constraints[0]['mode']);
     }
     //Add components to the form
     $form->add($timeRangeStartFieldSet);
     $form->add($timeRangeEndFieldSet);
     $form->add($modeSelection);
     $form->add($roleIdHiddenField);
     $form->setValidatorCallback("{$this->getClassName()}::constraint_callback");
     $form->setShowClear(false);
     //render the form
     return $form->render();
 }
示例#7
0
 protected function addEnumerationFilter($label, $name, $options)
 {
     $enum_list = new SelectionList("", "{$name}_value");
     $enum_list->setMultiple(true);
     foreach ($options as $value => $label) {
         $enum_list->addOption($label, $value);
     }
     $this->filters->add(Element::create("Label", str_replace("\\n", " ", $label)), $this->numFilters, 0)->add(Element::create("SelectionList", "", "{$name}_option")->addOption("Is any of", "INCLUDE")->addOption("Is none of", "EXCLUDE")->setValue("INCLUDE"), $this->numFilters, 1)->add($enum_list, $this->numFilters, 2);
     $this->numFilters++;
 }
示例#8
0
 /**
  * Returns the form that this controller uses to manipulate the data stored
  * in its model. As stated earlier the form is either automatically generated
  * or it is loaded from an existing file which is located in the same
  * directory as the model and bears the model's name.
  *
  * @return Form
  */
 protected function getForm()
 {
     // Load a local form if it exists.
     if ($this->redirected) {
         $formName = $this->redirectedPackageName . Application::camelize($this->mainRedirectedPackage) . "Form";
         $formPath = $this->redirectPath . "/" . str_replace(".", "/", $this->mainRedirectedPackage) . "/" . $formName . ".php";
     } else {
         $formName = Application::camelize($this->model->package) . "Form";
         $formPath = $this->localPath . "/" . $formName . ".php";
     }
     if (is_file($formPath)) {
         include_once $formPath;
         $form = new $formName();
     } else {
         if (is_file($this->localPath . "/" . $this->name . "Form.php")) {
             include_once $this->localPath . "/" . $this->name . "Form.php";
             $formclass = $this->name . "Form";
             $form = new $formclass();
             $form->setModel($this->model);
         } else {
             // Generate a form automatically
             $fieldNames = array();
             $fields = $this->model->getFields();
             $form = new Form();
             $form->setModel($this->model);
             $names = array_keys($fields);
             for ($i = 0; $i < count($fields); $i++) {
                 $field = $fields[$names[$i]];
                 if ($field['key'] == 'primary') {
                     continue;
                 }
                 if ($fieldNames[$i]["renderer"] == "") {
                     if ($field["reference"] == "") {
                         switch ($field["type"]) {
                             case "boolean":
                                 $element = new Checkbox($field["label"], $field["name"], $field["description"], 1);
                                 break;
                             case "enum":
                                 $element = new SelectionList($field["label"], $field["name"]);
                                 foreach ($field["options"] as $value => $option) {
                                     $element->addOption($option, $value . "");
                                 }
                                 break;
                             case "date":
                             case "datetime":
                                 $element = new DateField($field["label"], $field["name"]);
                                 break;
                             case "integer":
                             case "double":
                                 $element = new TextField($field["label"], $field["name"], $field["description"]);
                                 $element->setAsNumeric();
                                 break;
                             case "textarea":
                                 $element = new TextArea($field["label"], $field["name"], $field["description"]);
                                 break;
                             default:
                                 $element = new TextField($field["label"], $field["name"], $field["description"]);
                                 break;
                         }
                     } else {
                         $element = new ModelField($field["reference"], $field["referenceValue"]);
                     }
                     foreach ($field["validators"] as $validator) {
                         switch ($validator["type"]) {
                             case "required":
                                 $element->setRequired(true);
                                 break;
                             case "unique":
                                 $element->setUnique(true);
                                 break;
                             case "regexp":
                                 $element->setRegexp((string) $validator["parameter"]);
                                 break;
                         }
                     }
                 } else {
                     $renderer = (string) $fieldNames[$i]["renderer"];
                     $element = new $renderer();
                 }
                 $form->add($element);
             }
             $form->addAttribute("style", "width:50%");
             $form->useAjax(true, false);
         }
     }
     return $form;
 }
示例#9
0
 private function createDefaultForm()
 {
     // Generate a form automatically
     $fieldNames = array();
     $fields = $this->model->getFields();
     $form = new Form();
     $names = array_keys($fields);
     for ($i = 0; $i < count($fields); $i++) {
         $field = $fields[$names[$i]];
         if ($field['key'] == 'primary') {
             continue;
         }
         if ($fieldNames[$i]["renderer"] == "") {
             if ($field["reference"] == "") {
                 switch ($field["type"]) {
                     case "boolean":
                         $element = new Checkbox($field["label"], $field["name"], $field["description"], 1);
                         break;
                     case "enum":
                         $element = new SelectionList($field["label"], $field["name"]);
                         foreach ($field["options"] as $value => $option) {
                             $element->addOption($option, $value . "");
                         }
                         break;
                     case "date":
                     case "datetime":
                         $element = new DateField($field["label"], $field["name"]);
                         break;
                     case "integer":
                     case "double":
                         $element = new TextField($field["label"], $field["name"], $field["description"]);
                         $element->setAsNumeric();
                         break;
                     case "textarea":
                         $element = new TextArea($field["label"], $field["name"], $field["description"]);
                         break;
                     default:
                         $element = new TextField($field["label"], $field["name"], $field["description"]);
                         break;
                 }
             } else {
                 $element = new ModelField($field["reference"], $field["referenceValue"]);
             }
             foreach ($field["validators"] as $validator) {
                 switch ($validator["type"]) {
                     case "required":
                         $element->setRequired(true);
                         break;
                     case "unique":
                         $element->setUnique(true);
                         break;
                     case "regexp":
                         $element->setRegexp((string) $validator["parameter"]);
                         break;
                 }
             }
         } else {
             $renderer = (string) $fieldNames[$i]["renderer"];
             $element = new $renderer();
         }
         $form->add($element);
     }
     $form->addAttribute("style", "width:50%");
     $form->useAjax(true, false);
     return $form;
 }