当前位置: 首页>>代码示例>>PHP>>正文


PHP SectionManager::add方法代码示例

本文整理汇总了PHP中SectionManager::add方法的典型用法代码示例。如果您正苦于以下问题:PHP SectionManager::add方法的具体用法?PHP SectionManager::add怎么用?PHP SectionManager::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SectionManager的用法示例。


在下文中一共展示了SectionManager::add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateSections

 public static function updateSections()
 {
     $files = General::listStructure(WORKSPACE . '/sections', array(), false);
     $engine =& Symphony::Engine();
     $sectionManager = new SectionManager($engine);
     $fieldManager = new FieldManager($engine);
     if (is_array($files['filelist']) && !empty($files['filelist'])) {
         foreach ($files['filelist'] as $filename) {
             $data = @file_get_contents(WORKSPACE . "/sections/{$filename}");
             // Create DOMDocument instance
             $xml = new DOMDocument();
             $xml->preserveWhiteSpace = false;
             $xml->formatOutput = true;
             $xml->loadXML($data);
             // XPath for querying nodes
             $xpath = new DOMXPath($xml);
             $editing = false;
             $section_guid = $xpath->query('/section/@guid')->item(0)->value;
             $sections = Symphony::Database()->fetchCol('guid', "SELECT * FROM `tbl_sections`");
             if (in_array($section_guid, $sections)) {
                 $editing = true;
             }
             // Meta data
             $meta = array();
             $meta_nodes = $xpath->query('/section/meta/*');
             foreach ($meta_nodes as $node) {
                 $meta[$node->tagName] = $node->textContent;
             }
             if ($editing) {
                 Symphony::Database()->update($meta, 'tbl_sections', "guid = {$section_guid}");
             } else {
                 $section_id = $sectionManager->add($meta);
             }
             // Fields
             $fields = array();
             $field_nodes = $xpath->query('/section/fields/entry');
             foreach ($field_nodes as $node) {
                 $field = array();
                 foreach ($node->childNodes as $childNode) {
                     $field[$childNode->tagName] = $childNode->textContent;
                 }
                 $fields[] = $field;
             }
             self::removeMissingFields($fields, $fieldManager);
             if (is_array($fields) && !empty($fields)) {
                 foreach ($fields as $data) {
                     $field = $fieldManager->create($data['type']);
                     $field->setFromPOST($data);
                     $field->commit();
                 }
             }
         }
     }
 }
开发者ID:rainerborene,项目名称:schema_migration,代码行数:54,代码来源:class.synchronizer.php

示例2: __actionNew

 public function __actionNew()
 {
     if (@array_key_exists('save', $_POST['action']) || @array_key_exists('done', $_POST['action'])) {
         $canProceed = true;
         $fields = $_POST['fields'];
         $meta = $_POST['meta'];
         $this->_errors = array();
         ## Check to ensure all the required section fields are filled
         if (!isset($meta['name']) || strlen(trim($meta['name'])) == 0) {
             $required = array('Name');
             $this->_errors['name'] = __('This is a required field.');
             $canProceed = false;
         } elseif (Symphony::Database()->fetchRow(0, "SELECT * FROM `tbl_sections` WHERE `name` = '" . Symphony::Database()->cleanValue($meta['name']) . "' 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;
         }
         ## Basic custom field checking
         if (is_array($fields) && !empty($fields)) {
             $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('element_name' => __('Two custom fields have the same element name. All element names must be unique.'));
                     $canProceed = false;
                     break;
                 }
                 $name_list[] = $data['element_name'];
             }
             $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) {
             $query = 'SELECT MAX(`sortorder`) + 1 AS `next` FROM tbl_sections LIMIT 1';
             $next = Symphony::Database()->fetchVar('next', 0, $query);
             $meta['sortorder'] = $next ? $next : '1';
             $meta['handle'] = Lang::createHandle($meta['name']);
             $sectionManager = new SectionManager($this->_Parent);
             if (!($section_id = $sectionManager->add($meta))) {
                 $this->pageAlert(__('An unknown database occurred while attempting to create the section.'), Alert::ERROR);
             } else {
                 ## 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', $position);
                         $field->set('parent_section', $section_id);
                         $field->commit();
                         $field_id = $field->get('id');
                         if ($field_id) {
                             ###
                             # Delegate: FieldPostCreate
                             # Description: After creation of an Field. New Field object is provided.
                             $this->_Parent->ExtensionManager->notifyMembers('FieldPostCreate', '/blueprints/sections/', array('field' => &$field, 'data' => &$data));
                         }
                     }
                 }
                 ## TODO: Fix me
                 ###
                 # Delegate: Create
                 # Description: Creation of a new Section. Section ID and Primary Field ID are provided.
                 #$ExtensionManager->notifyMembers('Create', getCurrentPage(), array('section_id' => $section_id));
                 redirect(URL . "/symphony/blueprints/sections/edit/{$section_id}/created/");
             }
         }
     }
 }
开发者ID:klaftertief,项目名称:sym-forum,代码行数:93,代码来源:content.blueprintssections.php

示例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();
         }
     }
 }
开发者ID:davjand,项目名称:codecept-symphonycms-db,代码行数:31,代码来源:class.section.php

示例4: __viewCreate

 /**
  * Render create Page Fields section admin page.  This creates the Page Fields section
  * for the specified page.
  *
  */
 public function __viewCreate()
 {
     // Retrieve title and handle of specified pages.
     //
     $pageId = $this->_context[1];
     $pageQuery = "SELECT handle, title FROM `tbl_pages` WHERE `id` = {$pageId} LIMIT 1";
     $pageRow = $this->_Parent->Database->fetchrow(0, $pageQuery);
     // Now get the Id for the next extry in the section table.  We need this to create
     // a new entry.
     //
     $nextSectionIdQuery = 'SELECT MAX(`sortorder`) + 1 AS `next` FROM tbl_sections LIMIT 1';
     $nextSectionId = $this->_Parent->Database->fetchVar('next', 0, $nextSectionIdQuery);
     // Initialise details of the new section.
     //
     $newSectionDetails['sortorder'] = $nextSectionId ? $nextSectionId : '1';
     $newSectionDetails['handle'] = Lang::createHandle(PF_SECTION_TITLE_PREFIX . $pageId);
     $newSectionDetails['navigation_group'] = 'Content';
     $newSectionDetails['name'] = PF_SECTION_TITLE_PREFIX . $pageId;
     $newSectionDetails['hidden'] = 'yes';
     // Create the section and then display the (now updated) index page.
     //
     $sectionManager = new SectionManager($this->_Parent);
     $sectionManager->add($newSectionDetails);
     // Reditect to the manage page fields page.  (We can't just call __viewIndex()
     // to render the page as we need to redraw the menu).
     //
     redirect(URL . PF_MANAGE_URL);
 }
开发者ID:skeary,项目名称:symphony-page-fields,代码行数:33,代码来源:content.manage.php

示例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
//.........这里部分代码省略.........
开发者ID:davjand,项目名称:codecept-symphonycms-db,代码行数:101,代码来源:content.blueprintssections.php


注:本文中的SectionManager::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。