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


PHP SiteTree::onBeforeWrite方法代码示例

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


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

示例1: onBeforeWrite

 function onBeforeWrite()
 {
     if ($this->EmailBodyTemplate) {
         $this->EmailBodyTemplate = self::stripSSFromFilename($this->EmailBodyTemplate);
     }
     return parent::onBeforeWrite();
 }
开发者ID:pstaender,项目名称:Newsletter,代码行数:7,代码来源:NewsletterHolder.php

示例2: onBeforeWrite

	function onBeforeWrite() {
		if($this->LegacyURL) {
			$SQL_legacyURL = Convert::raw2sql($this->LegacyURL);
			$existingPages = DataObject::get_one(
				'Page',
				"URLSegment = '{$SQL_legacyURL}'"
			);
			if($existingPages) {
				$this->LegacyURL = null;
			}
		}
		
		parent::onBeforeWrite();
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:14,代码来源:Page.php

示例3: onBeforeWrite

 /**
  *	Apply the parent holder media type and update any respective media type attributes.
  */
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // Set the default media page date to the current time.
     if (is_null($this->Date)) {
         $this->Date = SS_Datetime::now()->Format('Y-m-d H:i:s');
     }
     // Confirm that the external link exists.
     if ($this->ExternalLink) {
         if (stripos($this->ExternalLink, 'http') === false) {
             $this->ExternalLink = 'http://' . $this->ExternalLink;
         }
         $file_headers = @get_headers($this->ExternalLink);
         if (!$file_headers || strripos($file_headers[0], '404 Not Found')) {
             $this->ExternalLink = null;
         }
     }
     // Apply the changes from each media type attribute.
     foreach ($this->record as $name => $value) {
         if (strrpos($name, 'MediaAttribute')) {
             $ID = substr($name, 0, strpos($name, '_'));
             $attribute = MediaAttribute::get_by_id('MediaAttribute', $ID);
             $attribute->Content = $value;
             $attribute->write();
         }
     }
     // Apply the parent holder media type.
     $parent = $this->getParent();
     if ($parent) {
         $type = $parent->MediaType();
         if ($type->exists()) {
             $this->MediaTypeID = $type->ID;
             $type = $type->Title;
         } else {
             $existing = MediaType::get_one('MediaType');
             $parent->MediaTypeID = $existing->ID;
             $parent->write();
             $this->MediaTypeID = $existing->ID;
             $type = $existing->Title;
         }
         // Merge the default and custom default media types and their respective attributes.
         $temporary = array();
         foreach (self::$custom_defaults as $default => $attributes) {
             if (isset(self::$page_defaults[$default])) {
                 self::$page_defaults[$default] = array_unique(array_merge(self::$page_defaults[$default], $attributes));
             } else {
                 $temporary[$default] = $attributes;
             }
         }
         $defaults = array_merge(self::$page_defaults, $temporary);
         // Apply existing attributes to a new media page.
         if (!$this->MediaAttributes()->exists()) {
             // Retrieve existing attributes for the respective media type.
             $attributes = MediaAttribute::get()->innerJoin('MediaPage', 'MediaAttribute.MediaPageID = MediaPage.ID')->innerJoin('MediaType', 'MediaPage.MediaTypeID = MediaType.ID')->where("MediaType.Title = '" . Convert::raw2sql($type) . "' AND MediaAttribute.LinkID = -1");
             if ($attributes->exists()) {
                 foreach ($attributes as $attribute) {
                     // Create a new attribute for each one found.
                     $new = MediaAttribute::create();
                     $new->Title = $attribute->Title;
                     $new->LinkID = $attribute->ID;
                     $new->MediaPageID = $this->ID;
                     $this->MediaAttributes()->add($new);
                     $new->write();
                 }
             } else {
                 if (isset($defaults[$type])) {
                     foreach ($defaults[$type] as $attribute) {
                         $new = MediaAttribute::create();
                         $new->Title = $attribute;
                         $new->LinkID = -1;
                         $new->MediaPageID = $this->ID;
                         $this->MediaAttributes()->add($new);
                         $new->write();
                     }
                 }
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:nglasl-silverstripe-mediawesome,代码行数:82,代码来源:MediaPage.php

示例4: onBeforeWrite

 /**
  * Handles the UseAsRootForMainNavigation property on before write.
  * 
  * @return void
  *
  * @author Sebastian Diel <sdiel@pixeltricks.de>
  * @since 07.10.2014
  */
 protected function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $request = Controller::curr()->getRequest();
     /* @var $request SS_HTTPRequest */
     if ($request->postVar('ID') == $this->ID && $request->postVar('UseAsRootForMainNavigation') == '1') {
         $this->UseAsRootForMainNavigation = true;
     }
     if ($this->isChanged('UseAsRootForMainNavigation')) {
         $changed = $this->getChangedFields(false, 1);
         $ch = $changed['UseAsRootForMainNavigation'];
         if ($this->UseAsRootForMainNavigation) {
             DB::query('UPDATE SilvercartPage SET UseAsRootForMainNavigation = 0 WHERE ID != ' . $this->ID);
         } elseif ($ch['before'] != $ch['after']) {
             $this->UseAsRootForMainNavigation = true;
         }
     }
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:26,代码来源:SilvercartPage.php


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