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


PHP DataExtension::onBeforeWrite方法代码示例

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


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

示例1: onBeforeWrite

 /**
  *	Update the tagging to reflect the change, allowing searchable content.
  */
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // Determine whether consolidated tags are found in the existing relationships.
     $types = array();
     foreach (singleton('FusionService')->getFusionTagTypes() as $type => $field) {
         $types[$type] = $type;
     }
     $types = array_intersect($this->owner->many_many(), $types);
     if (empty($types)) {
         // There are no consolidated tags found, therefore update the tagging based on the fusion tags.
         $tagging = array();
         foreach ($this->owner->FusionTags() as $tag) {
             $tagging[] = $tag->Title;
         }
     } else {
         // Empty the fusion tags to begin.
         $this->owner->FusionTags()->removeAll();
         // There are consolidated tags found, therefore update the tagging based on these.
         $tagging = array();
         foreach ($types as $relationship => $type) {
             foreach ($this->owner->{$relationship}() as $tag) {
                 // Update both the fusion tags and tagging.
                 $fusion = $tag->FusionTag();
                 $this->owner->FusionTags()->add($fusion);
                 $tagging[] = $fusion->Title;
             }
         }
     }
     $this->owner->Tagging = implode(' ', $tagging);
 }
开发者ID:helpfulrobot,项目名称:nglasl-silverstripe-fusion,代码行数:34,代码来源:TaggingExtension.php

示例2: onBeforeWrite

 /**
  * Generate a URL Segement before the data object gets written
  */
 public function onBeforeWrite()
 {
     if ($this->owner->Title) {
         $this->owner->URLSegment = $this->generateURLSegment($this->owner->Title);
     }
     parent::onBeforeWrite();
 }
开发者ID:helpfulrobot,项目名称:linkdup-silverstripe-seofriendlydataobject,代码行数:10,代码来源:SeoFriendlyDataObject.php

示例3: onBeforeWrite

 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // Load the significant_fields and check to see if they have changed if they have record the current DateTime
     $significant = Config::inst()->get($this->owner->Classname, 'significant_fields');
     $isSignicantChange = $this->owner->isSignificantChange;
     if (isset($significant) && !$isSignicantChange) {
         $significant = array_combine($significant, $significant);
         //If the owner object or an extension of it implements getSignificantChange call it instead of testing here
         if ($this->owner->hasMethod('getSignificantChange') && $this->owner->getSignificantChange()) {
             //Set LastSignificantChange to now
             $this->owner->LastSignificantChange = date(DateTime::ATOM);
         } else {
             $changes = $this->owner->getChangedFields(true, 2);
             //A simple interesect of the keys gives us whether a change has occurred
             if (count($changes) && count(array_intersect_key($changes, $significant))) {
                 //Set LastSignificantChange to now
                 $this->owner->LastSignificantChange = date(DateTime::ATOM);
             }
         }
         //If we don't have any significant changes leave the field alone as a previous edit may have been
         //significant.
     } else {
         if ($this->owner->isInDB()) {
             $this->owner->LastSignificantChange = NULL;
         }
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-australia-datachange-tracker,代码行数:28,代码来源:SignificantChangeRecordable.php

示例4: onBeforeWrite

 /**
  *	Update the corresponding vanity mapping.
  */
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // Retrieve the vanity mapping URL, where this is only possible using the POST variable.
     $vanityURL = is_null($URL = Controller::curr()->getRequest()->postVar('VanityURL')) ? $this->owner->VanityMapping()->MappedLink : $URL;
     $mappingExists = $this->owner->VanityMapping()->exists();
     // Determine whether the vanity mapping URL has been updated.
     if ($vanityURL && $mappingExists) {
         if ($this->owner->VanityMapping()->MappedLink !== $vanityURL) {
             // Update the corresponding vanity mapping.
             $this->owner->VanityMapping()->MappedLink = $vanityURL;
             $this->owner->VanityMapping()->write();
         }
     } else {
         if ($vanityURL) {
             // Instantiate the vanity mapping.
             $mapping = singleton('MisdirectionService')->createPageMapping($vanityURL, $this->owner->ID, 2);
             $this->owner->VanityMappingID = $mapping->ID;
         } else {
             if ($mappingExists) {
                 // Remove the corresponding vanity mapping.
                 $this->owner->VanityMapping()->delete();
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:nglasl-silverstripe-misdirection,代码行数:29,代码来源:SiteTreeMisdirectionExtension.php

示例5: onBeforeWrite

 function onBeforeWrite()
 {
     if ($this->owner->Status == 'Paid' && $this->owner->StockHasBeenCalculated == 0) {
         $this->owner->StockHasBeenCalculated = 1;
         if ($orderItems = $this->owner->Items()) {
             foreach ($orderItems as $orderItem) {
                 if ($buyable = $orderItem->Buyable()) {
                     if ($buyable->UnlimitedStock == 0) {
                         $oldNum = $buyable->Stock;
                         $newNum = $oldNum - $orderItem->Quantity;
                         $buyable->Stock = $newNum;
                         $buyable->write();
                     }
                 }
             }
         }
     }
     if ($this->owner->Status == 'AdminCancelled' && $this->owner->StockHasBeenCalculated == 1 || $this->owner->Status == 'MemberCancelled' && $this->owner->StockHasBeenCalculated == 1) {
         if ($orderItems = $this->owner->Items()) {
             foreach ($orderItems as $orderItem) {
                 if ($buyable = $orderItem->Buyable()) {
                     $oldNum = $buyable->Stock;
                     $newNum = $oldNum + $orderItem->Quantity;
                     $buyable->Stock = $newNum;
                     $buyable->write();
                 }
             }
         }
     }
     parent::onBeforeWrite();
 }
开发者ID:nimeso,项目名称:shop-stock-control,代码行数:31,代码来源:OrderStockDecoator.php

示例6: onBeforeWrite

 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->owner->SiteID) {
         $this->owner->SiteID = Multisites::inst()->getActiveSite()->ID;
     }
 }
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-multisites,代码行数:7,代码来源:MultisitesAware.php

示例7: onBeforeWrite

 /**
  * Set up defaults for fields
  */
 public function onBeforeWrite()
 {
     /** =========================================
          * @var TwitterSiteConfigExtension $siteConfig
         ===========================================*/
     parent::onBeforeWrite();
     $siteConfig = SiteConfig::current_site_config();
     if ($this->owner->exists()) {
         if ($this->owner->isChanged('Content') && !$this->owner->TwitterDescription) {
             $this->owner->setField('TwitterDescription', $this->owner->dbObject('Content')->Summary(50));
         }
         if ($this->owner->isChanged('Title') && !$this->owner->TwitterTitle) {
             $this->owner->setField('TwitterTitle', $this->owner->Title);
         }
         if (!$this->owner->TwitterSite) {
             $this->owner->setField('TwitterSite', $siteConfig->DefaultTwitterHandle);
         }
         if (!$this->owner->TwitterCreator) {
             $this->owner->setField('TwitterCreator', $siteConfig->DefaultTwitterHandle);
         }
         if (!$this->owner->TwitterImageID) {
             $this->owner->setField('TwitterImageID', $siteConfig->DefaultTwitterImageID);
         }
     }
     if (!$this->owner->TwitterTitle) {
         $this->owner->setField('TwitterTitle', $this->owner->Title);
     }
     if (!$this->owner->TwitterDescription) {
         $this->owner->setField('TwitterDescription', $this->owner->dbObject('Content')->Summary(50));
     }
 }
开发者ID:toastnz,项目名称:twitter-card-meta,代码行数:34,代码来源:TwitterCardMeta.php

示例8: onBeforeWrite

 /**
  * Set URLSegment to be unique on write
  */
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $defaults = $this->owner->config()->defaults;
     $URLSegment = $this->owner->URLSegment;
     // If there is no URLSegment set, generate one from Title
     if ((!$URLSegment || $URLSegment == $defaults['URLSegment']) && $this->owner->Title != $defaults['Title']) {
         $URLSegment = $this->generateURLSegment($this->owner->Title);
     } else {
         if ($this->owner->isChanged('URLSegment')) {
             // Make sure the URLSegment is valid for use in a URL
             $segment = preg_replace('/[^A-Za-z0-9]+/', '-', $this->owner->URLSegment);
             $segment = preg_replace('/-+/', '-', $segment);
             // If after sanitising there is no URLSegment, give it a reasonable default
             if (!$segment) {
                 $segment = $this->fallbackUrl();
             }
             $URLSegment = $segment;
         }
     }
     // Ensure that this object has a non-conflicting URLSegment value.
     $count = 2;
     $ID = $this->owner->ID;
     while ($this->lookForExistingURLSegment($URLSegment, $ID)) {
         $URLSegment = preg_replace('/-[0-9]+$/', null, $URLSegment) . '-' . $count;
         $count++;
     }
     $this->owner->URLSegment = $URLSegment;
 }
开发者ID:helpfulrobot,项目名称:ntb-silverstripe-rest-api,代码行数:32,代码来源:SlugableExtension.php

示例9: onBeforeWrite

 public function onBeforeWrite()
 {
     if (Config::inst()->get(__CLASS__, 'flush_on_change') && ($this->owner->isChanged('FocusX') || $this->owner->isChanged('FocusY'))) {
         $this->owner->deleteFormattedImages();
     }
     parent::onBeforeWrite();
 }
开发者ID:kashifmsidd,项目名称:silverstripe-focuspoint,代码行数:7,代码来源:FocusPointImage.php

示例10: onBeforeWrite

 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->owner->ID && !$this->owner->PublicationDate) {
         $this->owner->PublicationDate = date("Y-m-d H:i:s");
     }
 }
开发者ID:KINKCreative,项目名称:actors,代码行数:7,代码来源:Publishable.php

示例11: onBeforeWrite

 /**
  * Set VerificationString if not set
  * If not verified log out user and display message.
  */
 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->owner->VerificationString) {
         $this->owner->VerificationString = MD5(rand());
     }
     if (!$this->owner->Verified) {
         if (!$this->owner->VerificationEmailSent) {
             if (!self::$hasOnBeforeWrite) {
                 self::$hasOnBeforeWrite = true;
                 $this->owner->sendemail($this->owner, false);
             }
         }
         if (Member::currentUserID() && $this->owner->Email == Member::currentUser()->Email) {
             Security::logout(false);
             if (!is_null(Controller::redirectedTo())) {
                 $messageSet = array('default' => _t('EmailVerifiedMember.EMAILVERIFY', 'Please verify your email address by clicking on the link in the email before logging in.'));
             }
             Session::set("Security.Message.type", 'bad');
             Security::permissionFailure(Controller::curr(), $messageSet);
         } else {
             return;
         }
     } else {
         return;
     }
 }
开发者ID:helpfulrobot,项目名称:exadium-emailverifiedmember,代码行数:31,代码来源:EmailVerifiedMember.php

示例12: onBeforeWrite

 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->owner->ID && $this->owner->ClassName == 'ErrorPage') {
         $this->owner->ShowInSiteMap = 0;
     }
 }
开发者ID:christopherbolt,项目名称:silverstripe-bolttools,代码行数:7,代码来源:BoltSiteTree.php

示例13: onBeforeWrite

 function onBeforeWrite()
 {
     if (!$this->owner->ID && !$this->owner->SubsiteID && Subsite::currentSubsiteID()) {
         $this->owner->SubsiteID = Subsite::currentSubsiteID();
     }
     parent::onBeforeWrite();
 }
开发者ID:mikenz,项目名称:silverstripe-simplesubsites,代码行数:7,代码来源:SiteTreeSubsites.php

示例14: onBeforeWrite

 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // Create the base folder
     if (!$this->owner->BaseFolder && $this->owner->Title) {
         $filter = new FileNameFilter();
         $this->owner->BaseFolder = $filter->filter($this->owner->getTitle());
         $this->owner->BaseFolder = str_replace(' ', '', ucwords(str_replace('-', ' ', $this->owner->BaseFolder)));
     }
     // If name has changed, rename existing groups
     $changes = $this->owner->getChangedFields();
     if (isset($changes['Title']) && !empty($changes['Title']['before'])) {
         $filter = new URLSegmentFilter();
         $groupName = $this->getAdministratorGroupName($changes['Title']['before']);
         $group = self::getGroupByName($groupName);
         if ($group) {
             $group->Title = $this->getAdministratorGroupName($changes['Title']['after']);
             $group->Code = $filter->filter($group->Title);
             $group->write();
         }
         $membersGroupName = $this->getMembersGroupName($changes['Title']['before']);
         $membersGroup = self::getGroupByName($membersGroupName);
         if ($membersGroup) {
             $membersGroup->Title = $this->getMembersGroupName($changes['Title']['after']);
             $membersGroup->Code = $filter->filter($membersGroup->Title);
             $membersGroup->write();
         }
     }
 }
开发者ID:lekoala,项目名称:silverstripe-subsites-extras,代码行数:29,代码来源:SubsiteExtension.php

示例15: onBeforeWrite

 /**
  * Write the Color field to get the dominant color if not set
  */
 public function onBeforeWrite()
 {
     if ($this->owner->getField('Color') === null) {
         $this->owner->Color = $this->dominantColor();
     }
     parent::onBeforeWrite();
 }
开发者ID:jacobbuck,项目名称:silverstripe-colorfulimage,代码行数:10,代码来源:ColorfulImageExtension.php


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