當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AbstractModel::setCreatedAt方法代碼示例

本文整理匯總了PHP中Magento\Framework\Model\AbstractModel::setCreatedAt方法的典型用法代碼示例。如果您正苦於以下問題:PHP AbstractModel::setCreatedAt方法的具體用法?PHP AbstractModel::setCreatedAt怎麽用?PHP AbstractModel::setCreatedAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Framework\Model\AbstractModel的用法示例。


在下文中一共展示了AbstractModel::setCreatedAt方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _beforeSave

 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if (!$object->getId()) {
         $object->setCreatedAt($this->_date->gmtDate());
     }
     $object->setUpdatedAt($this->_date->gmtDate());
     return $this;
 }
開發者ID:pradeeprcs,項目名稱:TestModule,代碼行數:8,代碼來源:Test.php

示例2: _beforeSave

 /**
  * Prepare data to be saved to database
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\Object $object
  *
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->isObjectNew()) {
         $object->setCreatedAt($this->dateTime->formatDate(true));
     }
     $object->setUpdatedAt($this->dateTime->formatDate(true));
     return $this;
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:14,代碼來源:Bookmark.php

示例3: _beforeSave

 /**
  * @param \Magento\Framework\Model\AbstractModel $object
  *
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->isObjectNew() && !$object->hasCreatedAt()) {
         $object->setCreatedAt($this->_date->gmtDate());
     }
     $object->setUpdatedAt($this->_date->gmtDate());
     return parent::_beforeSave($object);
 }
開發者ID:pyvil,項目名稱:magento2-blog-module,代碼行數:14,代碼來源:Comment.php

示例4: _prepareDataForSave

 /**
  * Prepare data for save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return array
  */
 protected function _prepareDataForSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $currentTime = $this->dateTime->now();
     if ((!$object->getId() || $object->isObjectNew()) && !$object->getCreatedAt()) {
         $object->setCreatedAt($currentTime);
     }
     $object->setUpdatedAt($currentTime);
     $data = parent::_prepareDataForSave($object);
     return $data;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:16,代碼來源:AbstractResource.php

示例5: _beforeSave

 /**
  * Set date of last update
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  */
 protected function _beforeSave(AbstractModel $object)
 {
     /* @var $object \ClassyLlama\AvaTax\Model\Queue */
     $date = $this->dateTime->gmtDate();
     if ($object->isObjectNew() && !$object->getCreatedAt()) {
         $object->setCreatedAt($date);
     } else {
         $object->setUpdatedAt($date);
     }
     return parent::_beforeSave($object);
 }
開發者ID:classyllama,項目名稱:ClassyLlama_AvaTax,代碼行數:17,代碼來源:Queue.php

示例6: _beforeSave

 /**
  * before save callback
  *
  * @param \Magento\Framework\Model\AbstractModel|\Mageplaza\Blog\Model\Topic $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $object->setUpdatedAt($this->date->date());
     if ($object->isObjectNew()) {
         $object->setCreatedAt($this->date->date());
     }
     //Check Url Key
     if ($object->isObjectNew()) {
         $count = 0;
         $objName = $object->getName();
         if ($object->getUrlKey()) {
             $urlKey = $object->getUrlKey();
         } else {
             $urlKey = $this->generateUrlKey($objName, $count);
         }
         while ($this->checkUrlKey($urlKey)) {
             $count++;
             $urlKey = $this->generateUrlKey($urlKey, $count);
         }
         $object->setUrlKey($urlKey);
     } else {
         $objectId = $object->getId();
         $count = 0;
         $objName = $object->getName();
         if ($object->getUrlKey()) {
             $urlKey = $object->getUrlKey();
         } else {
             $urlKey = $this->generateUrlKey($objName, $count);
         }
         while ($this->checkUrlKey($urlKey, $objectId)) {
             $count++;
             $urlKey = $this->generateUrlKey($urlKey, $count);
         }
         $object->setUrlKey($urlKey);
     }
     return parent::_beforeSave($object);
 }
開發者ID:mageplaza,項目名稱:magento-2-blog-extension,代碼行數:43,代碼來源:Topic.php

示例7: _beforeSave

 /**
  * Perform actions before object save
  *
  * @param AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(AbstractModel $object)
 {
     if (!$object->getId()) {
         $object->setCreatedAt($this->_date->gmtDate());
     }
     if ($object->hasData('stores') && is_array($object->getStores())) {
         $stores = $object->getStores();
         $stores[] = 0;
         $object->setStores($stores);
     } elseif ($object->hasData('stores')) {
         $object->setStores([$object->getStores(), 0]);
     }
     return $this;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:20,代碼來源:Review.php

示例8: _afterSave

 /**
  * Perform actions after object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $connection = $this->getConnection();
     $columns = $connection->describeTable($this->getMainTable());
     if (isset($columns['created_at'], $columns['updated_at'])) {
         $select = $connection->select()->from($this->getMainTable(), ['created_at', 'updated_at'])->where($this->getIdFieldName() . ' = :entity_id');
         $row = $connection->fetchRow($select, [':entity_id' => $object->getId()]);
         if (is_array($row) && isset($row['created_at'], $row['updated_at'])) {
             $object->setCreatedAt($row['created_at']);
             $object->setUpdatedAt($row['updated_at']);
         }
     }
     parent::_afterSave($object);
     return $this;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:21,代碼來源:EntityAbstract.php

示例9: _beforeSave

 /**
  * Set template type, added at and modified at time
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(AbstractModel $object)
 {
     if ($object->isObjectNew()) {
         $object->setCreatedAt($this->dateTime->formatDate(true));
     }
     $object->setModifiedAt($this->dateTime->formatDate(true));
     $object->setTemplateType((int) $object->getTemplateType());
     return parent::_beforeSave($object);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:15,代碼來源:Template.php

示例10: _beforeSave

 /**
  * before save callback
  *
  * @param AbstractModel|\Sample\News\Model\Author $object
  * @return $this
  */
 protected function _beforeSave(AbstractModel $object)
 {
     foreach (['dob'] as $field) {
         $value = !$object->getData($field) ? null : $object->getData($field);
         $object->setData($field, $this->dateTime->formatDate($value));
     }
     $object->setUpdatedAt($this->date->gmtDate());
     if ($object->isObjectNew()) {
         $object->setCreatedAt($this->date->gmtDate());
     }
     $urlKey = $object->getData('url_key');
     if ($urlKey == '') {
         $urlKey = $object->getName();
     }
     $urlKey = $object->formatUrlKey($urlKey);
     $object->setUrlKey($urlKey);
     $validKey = false;
     while (!$validKey) {
         if ($this->getIsUniqueAuthorToStores($object)) {
             $validKey = true;
         } else {
             $parts = explode('-', $urlKey);
             $last = $parts[count($parts) - 1];
             if (!is_numeric($last)) {
                 $urlKey = $urlKey . '-1';
             } else {
                 $suffix = '-' . ($last + 1);
                 unset($parts[count($parts) - 1]);
                 $urlKey = implode('-', $parts) . $suffix;
             }
             $object->setData('url_key', $urlKey);
         }
     }
     return parent::_beforeSave($object);
 }
開發者ID:sz-bill,項目名稱:Magento2.x,代碼行數:41,代碼來源:Author.php

示例11: _beforeSave

 /**
  * before save callback
  *
  * @param \Magento\Framework\Model\AbstractModel|\Mageplaza\Blog\Model\Category $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $object->setUpdatedAt($this->date->date());
     if ($object->isObjectNew()) {
         $object->setCreatedAt($this->date->date());
     }
     /** @var \Mageplaza\Blog\Model\Category $object */
     parent::_beforeSave($object);
     if (!$object->getChildrenCount()) {
         $object->setChildrenCount(0);
     }
     if ($object->isObjectNew()) {
         if ($object->getPosition() === null) {
             $object->setPosition($this->getMaxPosition($object->getPath()) + 1);
         }
         $path = explode('/', $object->getPath());
         $level = count($path) - ($object->getId() ? 1 : 0);
         $toUpdateChild = array_diff($path, [$object->getId()]);
         if (!$object->hasPosition()) {
             $object->setPosition($this->getMaxPosition(implode('/', $toUpdateChild)) + 1);
         }
         if (!$object->hasLevel()) {
             $object->setLevel($level);
         }
         if (!$object->hasParentId() && $level && !$object->getInitialSetupFlag()) {
             $object->setParentId($path[$level - 1]);
         }
         if (!$object->getId() && !$object->getInitialSetupFlag()) {
             $object->setPath($object->getPath() . '/');
         }
         if (!$object->getInitialSetupFlag()) {
             $this->getConnection()->update($this->getMainTable(), ['children_count' => new \Zend_Db_Expr('children_count+1')], ['category_id IN(?)' => $toUpdateChild]);
         }
     }
     //Check Url Key
     if ($object->isObjectNew()) {
         $count = 0;
         $objName = $object->getName();
         if ($object->getUrlKey()) {
             $urlKey = $object->getUrlKey();
         } else {
             $urlKey = $this->generateUrlKey($objName, $count);
         }
         while ($this->checkUrlKey($urlKey)) {
             $count++;
             $urlKey = $this->generateUrlKey($urlKey, $count);
         }
         $object->setUrlKey($urlKey);
     } else {
         $objectId = $object->getId();
         $count = 0;
         $objName = $object->getName();
         if ($object->getUrlKey()) {
             $urlKey = $object->getUrlKey();
         } else {
             $urlKey = $this->generateUrlKey($objName, $count);
         }
         while ($this->checkUrlKey($urlKey, $objectId)) {
             $count++;
             $urlKey = $this->generateUrlKey($urlKey, $count);
         }
         $object->setUrlKey($urlKey);
     }
     return $this;
 }
開發者ID:mageplaza,項目名稱:magento-2-blog-extension,代碼行數:71,代碼來源:Category.php


注:本文中的Magento\Framework\Model\AbstractModel::setCreatedAt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。