本文整理汇总了PHP中Element::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Element::create方法的具体用法?PHP Element::create怎么用?PHP Element::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Element
的用法示例。
在下文中一共展示了Element::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getContents
public function getContents()
{
$this->label = 'Change Your Password';
$this->description = 'Please use this form to change your current password';
$form = Element::create('Form')->add(Element::create('PasswordField', 'Current Password', 'current_password')->setRequired(true)->setEncrypted(false), Element::create('PasswordField', 'New Password', 'new_password')->setRequired(true)->setEncrypted(false), Element::create('PasswordField', 'Retype New Password', 'repeat_new_password')->setRequired(true)->setEncrypted(false));
$form->addAttribute('style', 'width:500px');
$form->setCallback($this->getClassName() . '::callback', $this);
return $form->render();
}
示例2: __construct
/**
* Element constructor.
*
* @param array $variables
* A theme hook variables array.
*/
public function __construct(array &$variables)
{
$this->array =& $variables;
if (isset($variables['element'])) {
$this->element = Element::create($variables['element']);
} elseif (isset($variables['elements'])) {
$this->element = Element::create($variables['elements']);
}
}
示例3: create_category
/**
* Creates and returns a category object
*
* @param string $name
* @param int $parent_id
*
* @return Element | boolean
*/
private function create_category($name, $parent_id = 0)
{
$category = Element::get($this->modx, 'modCategory', $name);
if (!$category) {
$category = Element::create($this->modx, 'modCategory', $name);
}
$properties = array('parent' => $parent_id);
if ($category->set_properties($properties)) {
return $category;
}
return false;
}
示例4: setupList
protected function setupList()
{
parent::setupList();
$this->selectionLists = $this->retrieveSelectionLists();
foreach ($this->selectionLists as $list) {
$selectionList = Element::create("SelectionListToolbarItem", "{$list['filter_label']}");
$this->addListItems($selectionList, $list);
$this->filterFieldModel = $this->model;
$selectionList->onchange = "wyf.updateFilter('{$this->table->name}', '{$this->filterFieldModel->database}.{$list['filter_field']}', this.value)";
$this->toolbar->add($selectionList);
}
}
示例5: getImporterForm
public function getImporterForm()
{
$key = $this->parentController->model->getKeyField();
$form = parent::getForm();
$list = Element::create('SelectionList', Utils::singular($this->parentController->model->getEntity()), $key);
$items = $this->parentController->model->get();
foreach ($items as $item) {
$this->parentController->model->setData($item);
$list->addOption((string) $this->parentController->model, $item[$key]);
}
$form->add($list);
return $form;
}
示例6: roles
public function roles($params)
{
//Load necessary models
$usersModel = Model::load("auth.users");
$usersRolesModel = Model::load("auth.users_roles");
$rolesModel = Model::load("auth.roles");
//required queries
$user = $usersModel->getWithField("user_id", $params[0]);
$usersRoles = $usersRolesModel->getWithField("user_id", $params[0]);
$loggedInUsersRoles = $usersRolesModel->getWithField("user_id", $_SESSION['user_id']);
$roles = $rolesModel->get();
$this->label = "Select Role(s) for " . $user[0]['first_name'] . " " . $user[0]['last_name'];
//create a new form
$form = new Form();
$form->setRenderer("table");
$fieldset = Element::create('ColumnContainer', 3);
$form->add($fieldset);
foreach ($roles as $role) {
if ($role['role_id'] == 1) {
//Boolean to determine if the outer foreach loop should "continue" particular loop or not
$continueBool = false;
//Loop through all the current user's
foreach ($loggedInUsersRoles as $userRole) {
if ($userRole['role_id'] == 1) {
$continueBool = false;
break;
} else {
$continueBool = true;
}
}
if ($continueBool) {
continue;
}
}
$checkbox = Element::create("Checkbox", $role['role_name'], self::underscore($role['role_name']), "", $role['role_id']);
foreach ($usersRoles as $userRole) {
if ($userRole['role_id'] == $role['role_id']) {
$checkbox->setValue($role['role_id']);
}
}
$fieldset->add($checkbox);
}
$userIdHiddenField = Element::create("HiddenField", "user_id", $params[0]);
$form->add($userIdHiddenField);
$form->setValidatorCallback("{$this->getClassName()}::roles_callback");
$form->setShowClear(false);
//render the form
return $form->render();
}
示例7: manage
public function manage()
{
if (isset($_POST['is_form_sent'])) {
$this->postNewNote();
return;
}
$notes = SQLDBDataStore::getMulti(array('fields' => array('system.notes.note_id', 'system.notes.note', 'system.notes.note_time', 'system.users.first_name', 'system.users.last_name'), 'filter' => 'item_type = ? and item_id = ?', 'bind' => [$this->model->package, $params[0]]));
foreach ($notes as $i => $note) {
$attachments = $noteAttachments->getWithField2('note_id', $note['note_id']);
foreach ($attachments as $j => $attachment) {
$attachments[$j]['path'] = PgFileStore::getFilePath($attachment['object_id'], $attachment['description']);
}
$notes[$i]['attachments'] = $attachments;
}
$form = Element::create('Form')->add(Element::create('TextArea', 'Note', 'note'), Element::create('FieldSet', 'Add Attachments')->add(Element::create('UploadField', 'Attachment', 'attachment_1'), Element::create('UploadField', 'Attachment', 'attachment_2'), Element::create('UploadField', 'Attachment', 'attachment_3'), Element::create('UploadField', 'Attachment', 'attachment_4'))->setId('attachments')->setCollapsible(true))->setRenderer('default');
return $this->arbitraryTemplate('lib/controllers/notes.tpl', array('form' => $form->render(), 'notes' => $notes, 'route' => $this->path, 'id' => $params[0]));
}
示例8: getElement
private function getElement($element, $field)
{
return Element::create($element, $field['label'], $field['name'], $field['description']);
}
示例9: getForm
/**
* 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");
//.........这里部分代码省略.........
示例10: __construct
public function __construct()
{
parent::__construct();
$this->add(Element::create("TextField", "Username", "user_name"), Element::create("TextField", "Firstname", "first_name"), Element::create("TextField", "Lastname", "last_name"), Element::create("TextField", "Othernames", "other_names"), Element::create("ModelField", ".roles.role_id", "role_name"), Element::create("TextField", "Email", "email"), Element::create("HiddenField", "password"));
$this->addAttribute("style", "width:450px");
}
示例11: constraints
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();
}
示例12: addEnumerationFilter
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++;
}
示例13: import
/**
* Provides all the necessary forms needed to start an update.
* @param $params
* @return string
*/
public function import()
{
$this->label = "Import " . $this->label;
$form = new Form();
$form->add(Element::create("UploadField", "File", "file", "Select the file you want to upload."), Element::create("Checkbox", "Break on errors", "break_on_errors", "", "1")->setValue("1"));
$form->addAttribute("style", "width:50%");
$form->setCallback($this->getClassName() . '::importCallback', $this);
$form->setSubmitValue('Import Data');
return $this->arbitraryTemplate(Application::getWyfHome('model_controller/import.tpl'), array('form' => $form->render(), 'template' => "{$this->path}/export/csv?template=yes"));
}
示例14: __construct
public function __construct()
{
parent::__construct();
$this->add(Element::create('ModelField', '.users.user_id', 'user_name'), Element::create('TextField', 'API Key', 'key')->addAttribute('disabled', 'disabled'), Element::create('TextField', 'Secret', 'secret')->addAttribute('disabled', 'disabled'));
}
示例15: rows
/**
* Set the table's rows
*
* @param array $rows
*
* @return self
*/
public function rows(array $rows = array())
{
// Cancel if no rows
if (!$rows) {
return $this;
}
// Create tbody
$tbody = Element::create('tbody');
foreach ($rows as $row) {
$tr = Element::create('tr');
foreach ($row as $column => $value) {
$td = Element::create('td', $value);
$tr->setChild($td);
}
$tbody->setChild($tr);
}
// Nest into table
$this->nest(array('tbody' => $tbody));
return $this;
}