本文整理汇总了PHP中SectionManager::edit方法的典型用法代码示例。如果您正苦于以下问题:PHP SectionManager::edit方法的具体用法?PHP SectionManager::edit怎么用?PHP SectionManager::edit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SectionManager
的用法示例。
在下文中一共展示了SectionManager::edit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
public function view()
{
$items = $_REQUEST['items'];
if (!is_array($items) || empty($items)) {
return;
}
$destination = self::kREORDER_UNKNOWN;
if ($this->_context[0] == 'blueprints' && $this->_context[1] == 'pages') {
$destination = self::kREORDER_PAGES;
} elseif ($this->_context[0] == 'blueprints' && $this->_context[1] == 'sections') {
$destination = self::kREORDER_SECTIONS;
} elseif ($this->_context[0] == 'extensions') {
$destination = self::kREORDER_EXTENSION;
}
switch ($destination) {
case self::kREORDER_PAGES:
foreach ($items as $id => $position) {
if (!PageManager::edit($id, array('sortorder' => $position))) {
$this->setHttpStatus(self::HTTP_STATUS_ERROR);
$this->_Result->setValue(__('A database error occurred while attempting to reorder.'));
break;
}
}
break;
case self::kREORDER_SECTIONS:
foreach ($items as $id => $position) {
if (!SectionManager::edit($id, array('sortorder' => $position))) {
$this->setHttpStatus(self::HTTP_STATUS_ERROR);
$this->_Result->setValue(__('A database error occurred while attempting to reorder.'));
break;
}
}
break;
case self::kREORDER_EXTENSION:
// TODO
break;
case self::kREORDER_UNKNOWN:
default:
$this->setHttpStatus(self::HTTP_STATUS_BAD_REQUEST);
break;
}
}
示例2: __actionEdit
public function __actionEdit()
{
if (@array_key_exists('save', $_POST['action']) || @array_key_exists('done', $_POST['action'])) {
$canProceed = true;
$fields = $_POST['fields'];
$meta = $_POST['meta'];
$section_id = $this->_context[1];
$sectionManager = new SectionManager($this->_Parent);
$existing_section = $sectionManager->fetch($section_id);
$fieldManager = new FieldManager($this->_Parent);
$this->_errors = array();
## Check to ensure all the required section fields are filled
if (!isset($meta['name']) || trim($meta['name']) == '') {
$required = array('Name');
$this->_errors['name'] = __('This is a required field.');
$canProceed = false;
} elseif ($meta['name'] != $existing_section->get('name') && Symphony::Database()->fetchRow(0, "SELECT * FROM `tbl_sections` WHERE `name` = '" . $meta['name'] . "' AND `id` != {$section_id} LIMIT 1")) {
$this->_errors['name'] = __('A Section with the name <code>%s</code> name already exists', array($meta['name']));
$canProceed = false;
}
## Check to ensure all the required section fields are filled
if (!isset($meta['navigation_group']) || strlen(trim($meta['navigation_group'])) == 0) {
$required = array('Navigation Group');
$this->_errors['navigation_group'] = __('This is a required field.');
$canProceed = false;
} elseif (is_array($fields) && !empty($fields)) {
## Check for duplicate CF names
if ($canProceed) {
$name_list = array();
foreach ($fields as $position => $data) {
if (trim($data['element_name']) == '') {
$data['element_name'] = $fields[$position]['element_name'] = Lang::createHandle($data['label'], NULL, '-', false, true, array('@^[\\d-]+@i' => ''));
}
if (trim($data['element_name']) != '' && in_array($data['element_name'], $name_list)) {
$this->_errors[$position] = array('label' => __('Two custom fields have the same element name. All element names must be unique.'));
$canProceed = false;
break;
}
$name_list[] = $data['element_name'];
}
}
if ($canProceed) {
$fieldManager = new FieldManager($this->_Parent);
$unique = array();
foreach ($fields as $position => $data) {
$required = NULL;
$field = $fieldManager->create($data['type']);
$field->setFromPOST($data);
if ($field->mustBeUnique() && !in_array($field->get('type'), $unique)) {
$unique[] = $field->get('type');
} elseif ($field->mustBeUnique() && in_array($field->get('type'), $unique)) {
## Warning. cannot have 2 of this field!
$canProceed = false;
$this->_errors[$position] = array('label' => __('There is already a field of type <code>%s</code>. There can only be one per section.', array($field->name())));
}
$errors = array();
if (Field::__OK__ != $field->checkFields($errors, false, false) && !empty($errors)) {
$this->_errors[$position] = $errors;
$canProceed = false;
break;
}
}
}
}
if ($canProceed) {
$meta['handle'] = Lang::createHandle($meta['name']);
$meta['hidden'] = isset($meta['hidden']) ? 'yes' : 'no';
if (!$sectionManager->edit($section_id, $meta)) {
$this->pageAlert(__('An unknown database occurred while attempting to create the section.'), Alert::ERROR);
} else {
## Delete missing CF's
$id_list = array();
if (is_array($fields) && !empty($fields)) {
foreach ($fields as $position => $data) {
if (isset($data['id'])) {
$id_list[] = $data['id'];
}
}
}
$missing_cfs = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '{$section_id}' AND `id` NOT IN ('" . @implode("', '", $id_list) . "')");
if (is_array($missing_cfs) && !empty($missing_cfs)) {
foreach ($missing_cfs as $id) {
$fieldManager->delete($id);
}
}
## Save each custom field
if (is_array($fields) && !empty($fields)) {
foreach ($fields as $position => $data) {
$field = $fieldManager->create($data['type']);
$field->setFromPOST($data);
$field->set('sortorder', (string) $position);
$field->set('parent_section', $section_id);
$bEdit = true;
if (!$field->get('id')) {
$bEdit = false;
}
## Creation
if ($field->commit()) {
$field_id = $field->get('id');
###
//.........这里部分代码省略.........
示例3: commit
/**
* Commit the settings of this section from the section editor to
* create an instance of this section in `tbl_sections`. This function
* loops of each of the fields in this section and calls their commit
* function.
*
* @see toolkit.Field#commit()
* @return boolean
* true if the commit was successful, false otherwise.
*/
public function commit()
{
$settings = $this->_data;
$section_id = null;
if (isset($settings['id'])) {
$id = $settings['id'];
unset($settings['id']);
$section_id = SectionManager::edit($id, $settings);
if ($section_id) {
$section_id = $id;
}
} else {
$section_id = SectionManager::add($settings);
}
if (is_numeric($section_id) && $section_id !== false) {
for ($ii = 0, $length = count($this->_fields); $ii < $length; $ii++) {
$this->_fields[$ii]->set('parent_section', $section_id);
$this->_fields[$ii]->commit();
}
}
}
示例4: __viewIndex
public function __viewIndex()
{
$sectionManager = new SectionManager($this->_Parent);
if (!($section_id = $sectionManager->fetchIDFromHandle($this->_context['section_handle']))) {
Administration::instance()->customError(__('Unknown Section'), __('The Section you are looking, <code>%s</code> for could not be found.', array($this->_context['section_handle'])));
}
$section = $sectionManager->fetch($section_id);
$this->setPageType('table');
$this->setTitle(__('%1$s – %2$s', array(__('Symphony'), $section->get('name'))));
$this->Form->setAttribute("class", $this->_context['section_handle']);
$entryManager = new EntryManager($this->_Parent);
$filter = $filter_value = $where = $joins = NULL;
$current_page = isset($_REQUEST['pg']) && is_numeric($_REQUEST['pg']) ? max(1, intval($_REQUEST['pg'])) : 1;
if (isset($_REQUEST['filter'])) {
list($field_handle, $filter_value) = explode(':', $_REQUEST['filter'], 2);
$field_names = explode(',', $field_handle);
foreach ($field_names as $field_name) {
$filter_value = rawurldecode($filter_value);
$filter = Symphony::Database()->fetchVar('id', 0, "SELECT `f`.`id`\n\t\t\t\t\t\t\t\t\t\t FROM `tbl_fields` AS `f`, `tbl_sections` AS `s`\n\t\t\t\t\t\t\t\t\t\t WHERE `s`.`id` = `f`.`parent_section`\n\t\t\t\t\t\t\t\t\t\t AND f.`element_name` = '{$field_name}'\n\t\t\t\t\t\t\t\t\t\t AND `s`.`handle` = '" . $section->get('handle') . "' LIMIT 1");
$field =& $entryManager->fieldManager->fetch($filter);
if ($field instanceof Field) {
// For deprecated reasons, call the old, typo'd function name until the switch to the
// properly named buildDSRetrievalSQL function.
$field->buildDSRetrivalSQL(array($filter_value), $joins, $where, false);
$filter_value = rawurlencode($filter_value);
}
}
if (!is_null($where)) {
$where = str_replace('AND', 'OR', $where);
// multiple fields need to be OR
$where = trim($where);
$where = ' AND (' . substr($where, 2, strlen($where)) . ')';
// replace leading OR with AND
}
}
if (isset($_REQUEST['sort']) && is_numeric($_REQUEST['sort'])) {
$sort = intval($_REQUEST['sort']);
$order = $_REQUEST['order'] ? strtolower($_REQUEST['order']) : 'asc';
if ($section->get('entry_order') != $sort || $section->get('entry_order_direction') != $order) {
$sectionManager->edit($section->get('id'), array('entry_order' => $sort, 'entry_order_direction' => $order));
redirect(Administration::instance()->getCurrentPageURL() . ($filter ? "?filter={$field_handle}:{$filter_value}" : ''));
}
} elseif (isset($_REQUEST['unsort'])) {
$sectionManager->edit($section->get('id'), array('entry_order' => NULL, 'entry_order_direction' => NULL));
redirect(Administration::instance()->getCurrentPageURL());
}
$this->Form->setAttribute('action', Administration::instance()->getCurrentPageURL() . '?pg=' . $current_page . ($filter ? "&filter={$field_handle}:{$filter_value}" : ''));
$this->appendSubheading($section->get('name'), Widget::Anchor(__('Create New'), Administration::instance()->getCurrentPageURL() . 'new/' . ($filter ? '?prepopulate[' . $filter . ']=' . $filter_value : ''), __('Create a new entry'), 'create button', NULL, array('accesskey' => 'c')));
if (is_null($entryManager->getFetchSorting()->field) && is_null($entryManager->getFetchSorting()->direction)) {
$entryManager->setFetchSortingDirection('DESC');
}
$entries = $entryManager->fetchByPage($current_page, $section_id, Symphony::Configuration()->get('pagination_maximum_rows', 'symphony'), $where, $joins);
$aTableHead = array();
$visible_columns = $section->fetchVisibleColumns();
if (is_array($visible_columns) && !empty($visible_columns)) {
foreach ($visible_columns as $column) {
$label = $column->get('label');
if ($column->isSortable()) {
if ($column->get('id') == $section->get('entry_order')) {
$link = Administration::instance()->getCurrentPageURL() . '?pg=' . $current_page . '&sort=' . $column->get('id') . '&order=' . ($section->get('entry_order_direction') == 'desc' ? 'asc' : 'desc') . ($filter ? "&filter={$field_handle}:{$filter_value}" : '');
$anchor = Widget::Anchor($label, $link, __('Sort by %1$s %2$s', array($section->get('entry_order_direction') == 'desc' ? __('ascending') : __('descending'), strtolower($column->get('label')))), 'active');
} else {
$link = Administration::instance()->getCurrentPageURL() . '?pg=' . $current_page . '&sort=' . $column->get('id') . '&order=asc' . ($filter ? "&filter={$field_handle}:{$filter_value}" : '');
$anchor = Widget::Anchor($label, $link, __('Sort by %1$s %2$s', array(__('ascending'), strtolower($column->get('label')))));
}
$aTableHead[] = array($anchor, 'col', array('id' => 'field-' . $column->get('id'), 'class' => 'field-' . $column->get('type')));
} else {
$aTableHead[] = array($label, 'col', array('id' => 'field-' . $column->get('id'), 'class' => 'field-' . $column->get('type')));
}
}
} else {
$aTableHead[] = array(__('ID'), 'col');
}
$child_sections = array();
$associated_sections = $section->fetchAssociatedSections(true);
if (is_array($associated_sections) && !empty($associated_sections)) {
foreach ($associated_sections as $key => $as) {
$child_sections[$key] = $sectionManager->fetch($as['child_section_id']);
$aTableHead[] = array($child_sections[$key]->get('name'), 'col');
}
}
/**
* Allows the creation of custom entries tablecolumns. Called
* after all the Section Visible columns have been added as well
* as the Section Associations
*
* @delegate AddCustomPublishColumn
* @since Symphony 2.2
* @param string $context
* '/publish/'
* @param array $tableHead
* An array of the current columns, passed by reference
* @param integer $section_id
* The current Section ID
*/
Symphony::ExtensionManager()->notifyMembers('AddCustomPublishColumn', '/publish/', array('tableHead' => &$aTableHead, 'section_id' => $section->get('id')));
## Table Body
$aTableBody = array();
if (!is_array($entries['records']) || empty($entries['records'])) {
$aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', NULL, count($aTableHead))), 'odd'));
//.........这里部分代码省略.........
示例5: __actionNew
public function __actionNew()
{
if (@array_key_exists('save', $_POST['action']) || @array_key_exists('done', $_POST['action'])) {
$canProceed = true;
$edit = $this->_context[0] == "edit";
$this->_errors = array();
$fields = isset($_POST['fields']) ? $_POST['fields'] : array();
$meta = $_POST['meta'];
if ($edit) {
$section_id = $this->_context[1];
$existing_section = SectionManager::fetch($section_id);
}
// Check to ensure all the required section fields are filled
if (!isset($meta['name']) || strlen(trim($meta['name'])) == 0) {
$this->_errors['name'] = __('This is a required field.');
$canProceed = false;
} elseif ($edit) {
$s = SectionManager::fetchIDFromHandle(Lang::createHandle($meta['name']));
if ($meta['name'] !== $existing_section->get('name') && !is_null($s) && $s !== $section_id) {
$this->_errors['name'] = __('A Section with the name %s already exists', array('<code>' . $meta['name'] . '</code>'));
$canProceed = false;
}
} elseif (!is_null(SectionManager::fetchIDFromHandle(Lang::createHandle($meta['name'])))) {
$this->_errors['name'] = __('A Section with the name %s already exists', array('<code>' . $meta['name'] . '</code>'));
$canProceed = false;
}
// Check to ensure all the required section fields are filled
if (!isset($meta['navigation_group']) || strlen(trim($meta['navigation_group'])) == 0) {
$this->_errors['navigation_group'] = __('This is a required field.');
$canProceed = false;
}
// Basic custom field checking
if (is_array($fields) && !empty($fields)) {
// Check for duplicate CF names
if ($canProceed) {
$name_list = array();
foreach ($fields as $position => $data) {
if (trim($data['element_name']) == '') {
$data['element_name'] = $fields[$position]['element_name'] = $_POST['fields'][$position]['element_name'] = Lang::createHandle($data['label'], 255, '-', false, true, array('@^[\\d-]+@i' => ''));
}
if (trim($data['element_name']) != '' && in_array($data['element_name'], $name_list)) {
$this->_errors[$position] = array('element_name' => __('A field with this handle already exists. All handle must be unique.'));
$canProceed = false;
break;
}
$name_list[] = $data['element_name'];
}
}
if ($canProceed) {
$unique = array();
foreach ($fields as $position => $data) {
$field = FieldManager::create($data['type']);
$field->setFromPOST($data);
if (isset($existing_section)) {
$field->set('parent_section', $existing_section->get('id'));
}
if ($field->mustBeUnique() && !in_array($field->get('type'), $unique)) {
$unique[] = $field->get('type');
} elseif ($field->mustBeUnique() && in_array($field->get('type'), $unique)) {
// Warning. cannot have 2 of this field!
$canProceed = false;
$this->_errors[$position] = array('label' => __('There is already a field of type %s. There can only be one per section.', array('<code>' . $field->handle() . '</code>')));
}
$errors = array();
if (Field::__OK__ != $field->checkFields($errors, false) && !empty($errors)) {
$this->_errors[$position] = $errors;
$canProceed = false;
}
}
}
}
if ($canProceed) {
$meta['handle'] = Lang::createHandle($meta['name']);
// If we are creating a new Section
if (!$edit) {
$meta['sortorder'] = SectionManager::fetchNextSortOrder();
/**
* Just prior to saving the Section settings. Use with caution as
* there is no additional processing to ensure that Field's or Section's
* are unique.
*
* @delegate SectionPreCreate
* @since Symphony 2.2
* @param string $context
* '/blueprints/sections/'
* @param array $meta
* The section's settings, passed by reference
* @param array $fields
* An associative array of the fields that will be saved to this
* section with the key being the position in the Section Editor
* and the value being a Field object, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('SectionPreCreate', '/blueprints/sections/', array('meta' => &$meta, 'fields' => &$fields));
if (!($section_id = SectionManager::add($meta))) {
$this->pageAlert(__('An unknown database occurred while attempting to create the section.'), Alert::ERROR);
}
} else {
$meta['hidden'] = isset($meta['hidden']) ? 'yes' : 'no';
/**
* Just prior to updating the Section settings. Use with caution as
//.........这里部分代码省略.........
示例6: SectionManager
function __viewIndex()
{
$sectionManager = new SectionManager($this->_Parent);
if (!($section_id = $sectionManager->fetchIDFromHandle($this->_context['section_handle']))) {
$this->_Parent->customError(E_USER_ERROR, __('Unknown Section'), __('The Section you are looking, <code>%s</code> for could not be found.', array($this->_context['section_handle'])), false, true);
}
$section = $sectionManager->fetch($section_id);
$this->setPageType('table');
$this->setTitle(__('%1$s – %2$s', array(__('Symphony'), $section->get('name'))));
$this->Form->setAttribute("class", $this->_context['section_handle']);
$entryManager = new EntryManager($this->_Parent);
$authors = AuthorManager::fetch();
$filter = $filter_value = $where = $joins = NULL;
$current_page = isset($_REQUEST['pg']) && is_numeric($_REQUEST['pg']) ? max(1, intval($_REQUEST['pg'])) : 1;
if (isset($_REQUEST['filter'])) {
list($field_handle, $filter_value) = explode(':', $_REQUEST['filter'], 2);
$field_names = explode(',', $field_handle);
foreach ($field_names as $field_name) {
$filter_value = rawurldecode($filter_value);
$filter = Symphony::Database()->fetchVar('id', 0, "SELECT `f`.`id` \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM `tbl_fields` AS `f`, `tbl_sections` AS `s` \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE `s`.`id` = `f`.`parent_section` \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND f.`element_name` = '{$field_name}' \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND `s`.`handle` = '" . $section->get('handle') . "' LIMIT 1");
$field =& $entryManager->fieldManager->fetch($filter);
if (is_object($field)) {
$field->buildDSRetrivalSQL(array($filter_value), $joins, $where, false);
$filter_value = rawurlencode($filter_value);
}
}
if ($where != null) {
$where = str_replace('AND', 'OR', $where);
// multiple fields need to be OR
$where = trim($where);
$where = ' AND (' . substr($where, 2, strlen($where)) . ')';
// replace leading OR with AND
}
}
if (isset($_REQUEST['sort']) && is_numeric($_REQUEST['sort'])) {
$sort = intval($_REQUEST['sort']);
$order = $_REQUEST['order'] ? strtolower($_REQUEST['order']) : 'asc';
if ($section->get('entry_order') != $sort || $section->get('entry_order_direction') != $order) {
$sectionManager->edit($section->get('id'), array('entry_order' => $sort, 'entry_order_direction' => $order));
redirect($this->_Parent->getCurrentPageURL() . ($filter ? "?filter={$field_handle}:{$filter_value}" : ''));
}
} elseif (isset($_REQUEST['unsort'])) {
$sectionManager->edit($section->get('id'), array('entry_order' => NULL, 'entry_order_direction' => NULL));
redirect($this->_Parent->getCurrentPageURL());
}
$this->Form->setAttribute('action', $this->_Parent->getCurrentPageURL() . '?pg=' . $current_page . ($filter ? "&filter={$field_handle}:{$filter_value}" : ''));
## Remove the create button if there is a section link field, and no filtering set for it
$section_links = $section->fetchFields('sectionlink');
if (count($section_links) > 1 || !$filter && $section_links || is_object($section_links[0]) && $filter != $section_links[0]->get('id')) {
$this->appendSubheading($section->get('name'));
} else {
$this->appendSubheading($section->get('name'), Widget::Anchor(__('Create New'), $this->_Parent->getCurrentPageURL() . 'new/' . ($filter ? '?prepopulate[' . $filter . ']=' . $filter_value : ''), __('Create a new entry'), 'create button'));
}
if (is_null($entryManager->getFetchSorting()->field) && is_null($entryManager->getFetchSorting()->direction)) {
$entryManager->setFetchSortingDirection('DESC');
}
$entries = $entryManager->fetchByPage($current_page, $section_id, Symphony::Configuration()->get('pagination_maximum_rows', 'symphony'), $where, $joins);
$aTableHead = array();
$visible_columns = $section->fetchVisibleColumns();
if (is_array($visible_columns) && !empty($visible_columns)) {
foreach ($visible_columns as $column) {
$label = $column->get('label');
if ($column->isSortable()) {
if ($column->get('id') == $section->get('entry_order')) {
$link = $this->_Parent->getCurrentPageURL() . '?pg=' . $current_page . '&sort=' . $column->get('id') . '&order=' . ($section->get('entry_order_direction') == 'desc' ? 'asc' : 'desc') . ($filter ? "&filter={$field_handle}:{$filter_value}" : '');
$anchor = Widget::Anchor($label, $link, __('Sort by %1$s %2$s', array($section->get('entry_order_direction') == 'desc' ? __('ascending') : __('descending'), strtolower($column->get('label')))), 'active');
} else {
$link = $this->_Parent->getCurrentPageURL() . '?pg=' . $current_page . '&sort=' . $column->get('id') . '&order=asc' . ($filter ? "&filter={$field_handle}:{$filter_value}" : '');
$anchor = Widget::Anchor($label, $link, __('Sort by %1$s %2$s', array(__('ascending'), strtolower($column->get('label')))));
}
$aTableHead[] = array($anchor, 'col');
} else {
$aTableHead[] = array($label, 'col');
}
}
} else {
$aTableHead[] = array(__('ID'), 'col');
}
$child_sections = NULL;
$associated_sections = $section->fetchAssociatedSections();
if (is_array($associated_sections) && !empty($associated_sections)) {
$child_sections = array();
foreach ($associated_sections as $key => $as) {
$child_sections[$key] = $sectionManager->fetch($as['child_section_id']);
$aTableHead[] = array($child_sections[$key]->get('name'), 'col');
}
}
## Table Body
$aTableBody = array();
if (!is_array($entries['records']) || empty($entries['records'])) {
$aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', NULL, count($aTableHead))), 'odd'));
} else {
$bOdd = true;
$field_pool = array();
if (is_array($visible_columns) && !empty($visible_columns)) {
foreach ($visible_columns as $column) {
$field_pool[$column->get('id')] = $column;
}
}
foreach ($entries['records'] as $entry) {
//.........这里部分代码省略.........