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


PHP Entity::isNew方法代码示例

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


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

示例1: beforeSave

 public function beforeSave(Event $event, Entity $entity)
 {
     $get_user_id_function = $this->config('get_user_id_function');
     if (!empty($get_user_id_function)) {
         $user_id = call_user_func($get_user_id_function);
         if ($entity->isNew() && $entity->accessible('created_by')) {
             $entity->created_by = $user_id;
         }
         if (!$entity->isNew() && $entity->accessible('modified_by')) {
             $entity->modified_by = $user_id;
         }
     }
 }
开发者ID:alaxos,项目名称:cakephp3-libs,代码行数:13,代码来源:UserLinkBehavior.php

示例2: basepath

 /**
  * Returns the basepath for the current field/data combination.
  * If a `path` is specified in settings, then that will be used as
  * the replacement pattern
  *
  * @return string
  * @throws LogicException if a replacement is not valid for the current dataset
  */
 public function basepath()
 {
     $defaultPath = 'webroot{DS}files{DS}{model}{DS}{field}{DS}';
     $path = Hash::get($this->settings, 'path', $defaultPath);
     if (strpos($path, '{primaryKey}') !== false) {
         if ($this->entity->isNew()) {
             throw new LogicException('{primaryKey} substitution not allowed for new entities');
         }
         if (is_array($this->table->primaryKey())) {
             throw new LogicException('{primaryKey} substitution not valid for composite primary keys');
         }
     }
     $replacements = ['{primaryKey}' => $this->entity->get($this->table->primaryKey()), '{model}' => $this->table->alias(), '{relatedModel}' => $this->entity->model, '{table}' => $this->table->table(), '{field}' => $this->field, '{time}' => time(), '{microtime}' => microtime(), '{DS}' => DIRECTORY_SEPARATOR];
     return str_replace(array_keys($replacements), array_values($replacements), $path);
 }
开发者ID:gintonicweb,项目名称:images,代码行数:23,代码来源:PolymorphicProcessor.php

示例3: beforeSave

 /**
  * Before save listener.
  * Transparently manages setting the lft and rght fields if the parent field is
  * included in the parameters to be saved.
  *
  * @param \Cake\Event\Event the beforeSave event that was fired
  * @param \Cake\ORM\Entity the entity that is going to be saved
  * @return void
  * @throws \RuntimeException if the parent to set for the node is invalid
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $isNew = $entity->isNew();
     $config = $this->config();
     $parent = $entity->get($config['parent']);
     $primaryKey = (array) $this->_table->primaryKey();
     $dirty = $entity->dirty($config['parent']);
     if ($isNew && $parent) {
         if ($entity->get($primaryKey[0]) == $parent) {
             throw new \RuntimeException("Cannot set a node's parent as itself");
         }
         $parentNode = $this->_getNode($parent);
         $edge = $parentNode->get($config['right']);
         $entity->set($config['left'], $edge);
         $entity->set($config['right'], $edge + 1);
         $this->_sync(2, '+', ">= {$edge}");
     }
     if ($isNew && !$parent) {
         $edge = $this->_getMax();
         $entity->set($config['left'], $edge + 1);
         $entity->set($config['right'], $edge + 2);
     }
     if (!$isNew && $dirty && $parent) {
         $this->_setParent($entity, $parent);
     }
     if (!$isNew && $dirty && !$parent) {
         $this->_setAsRoot($entity);
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:39,代码来源:TreeBehavior.php

示例4: beforeSave

 /**
  * Run before a model is saved, used to set up slug for model.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Cake\ORM\Entity $entity The entity being saved
  * @param array $options Array of options for the save operation
  * @return bool True if save should proceed, false otherwise
  * @throws \Cake\Error\FatalErrorException When some of the specified columns
  *  in config's "label" is not present in the entity being saved
  */
 public function beforeSave(Event $event, $entity, $options = [])
 {
     if (!$this->_enabled) {
         return true;
     }
     $config = $this->config();
     $isNew = $entity->isNew();
     if ($isNew && in_array($config['on'], ['create', 'both']) || !$isNew && in_array($config['on'], ['update', 'both'])) {
         if (!is_array($config['label'])) {
             $config['label'] = [$config['label']];
         }
         foreach ($config['label'] as $field) {
             if (!$entity->has($field)) {
                 throw new FatalErrorException(__d('cms', 'SluggableBehavior was not able to generate a slug reason: entity\'s property "{0}" not found', $field));
             }
         }
         $label = '';
         foreach ($config['label'] as $field) {
             $val = $entity->get($field);
             $label .= !empty($val) ? " {$val}" : '';
         }
         if (!empty($label)) {
             $slug = $this->_slug($label, $entity);
             $entity->set($config['slug'], $slug);
         }
     }
     return true;
 }
开发者ID:quickapps-plugins,项目名称:cms,代码行数:38,代码来源:SluggableBehavior.php

示例5: afterSave

 /**
  * After Save Callback
  *
  * @param Cake/Event/Event $event The afterSave event that was fired.
  * @param Cake/ORM/Entity $entity The entity
  * @param ArrayObject $options Options
  * @return void
  */
 public function afterSave(Event $event, Entity $entity, ArrayObject $options)
 {
     if ($entity->isNew()) {
         $this->saveDefaultUri($entity);
     } else {
         // Change route.
         if ($entity->dirty()) {
             $SeoUris = TableRegistry::get('Seo.SeoUris');
             $SeoCanonicals = TableRegistry::get('Seo.SeoCanonicals');
             $urlsConfig = $this->config('urls');
             foreach ($urlsConfig as $key => $url) {
                 $uri = $this->_getUri($entity, $url);
                 $seoUri = $SeoUris->find()->contain(['SeoCanonicals'])->where(['model' => $this->_table->alias(), 'foreign_key' => $entity->id, 'locale' => isset($url['locale']) ? $url['locale'] : null])->first();
                 if ($seoUri) {
                     $seoUri = $SeoUris->patchEntity($seoUri, ['uri' => $uri], ['associated' => ['SeoCanonicals']]);
                     $SeoUris->save($seoUri);
                     $seoUriCanonical = Router::fullBaseUrl() . $uri;
                     $seoUri->seo_canonical->set('canonical', $seoUriCanonical);
                     $SeoCanonicals->save($seoUri->seo_canonical);
                 }
             }
         }
     }
     \Cake\Cache\Cache::clear(false, 'seo');
 }
开发者ID:orgasmicnightmare,项目名称:cakephp-seo,代码行数:33,代码来源:SeoBehavior.php

示例6: afterSave

 /**
  * Called after an entity is saved
  * @param \Cake\Event\Event $event Event object
  * @param \Cake\ORM\Entity $entity Entity object
  * @param \ArrayObject $options Options
  * @return void
  * @uses MeCms\Model\Table\AppTable::afterSave()
  */
 public function afterSave(\Cake\Event\Event $event, \Cake\ORM\Entity $entity, \ArrayObject $options)
 {
     //Creates the folder
     if ($entity->isNew()) {
         (new Folder())->create(PHOTOS . DS . $entity->id, 0777);
     }
     parent::afterSave($event, $entity, $options);
 }
开发者ID:mirko-pagliai,项目名称:me-cms,代码行数:16,代码来源:PhotosAlbumsTable.php

示例7: beforeSave

 /**
  * Before save callback.
  *
  * @param Event $event
  * @param Entity $entity
  * @param \ArrayObject $options
  * @return bool
  */
 public function beforeSave(Event $event, Entity $entity, \ArrayObject $options)
 {
     if ($entity->isNew() || $this->_config['update']) {
         $uniqueSlug = $this->_generateUniqueSlug($entity);
         $entity->set($this->_config['slug'], $uniqueSlug);
     }
     return true;
 }
开发者ID:Cheren,项目名称:union,代码行数:16,代码来源:SlugBehavior.php

示例8: beforeSave

 public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
 {
     if ($entity->isNew() && empty($entity->user_id)) {
         $entity->errors('user_id', ['not_found', 'User not found']);
         $entity->errors('net_id', ['not_found', 'User not found']);
         return false;
     }
 }
开发者ID:byu-oit-appdev,项目名称:byusa-clubs,代码行数:8,代码来源:MatchUserBehavior.php

示例9: afterSave

 /**
  * AfterSave callback.
  *
  * @param \Cake\Event\Event $event   The afterSave event that was fired.
  * @param \Cake\ORM\Entity $entity  The entity that was saved.
  * @param \ArrayObject $options The options passed to the callback.
  *
  * @return bool
  */
 public function afterSave(Event $event, Entity $entity, ArrayObject $options)
 {
     if ($entity->isNew()) {
         $comment = new Event('Model.BlogArticlesComments.add', $this, ['comment' => $entity]);
         $this->eventManager()->dispatch($comment);
     }
     return true;
 }
开发者ID:edukondaluetg,项目名称:Xeta,代码行数:17,代码来源:BlogArticlesCommentsTable.php

示例10: beforeSave

 public function beforeSave(Event $event, Entity $entity, \ArrayObject $options)
 {
     if ($entity->isNew()) {
         if (!$this->matchUser($entity)) {
             $entity->errors('net_id', ['not_found', 'User not found']);
             return false;
         }
     }
 }
开发者ID:byu-oit-appdev,项目名称:eam,代码行数:9,代码来源:MatchUserBehavior.php

示例11: testBeforeSaveEditEntity

 /**
  * test beforeSave() method when updating an existing entity.
  *
  * @return void
  */
 public function testBeforeSaveEditEntity()
 {
     $event = new Event('Model.beforeSave');
     $entity = new Entity(['id' => 100, 'title' => 'Random String Title', 'slug' => '']);
     $entity->isNew(false);
     $this->Behavior->beforeSave($event, $entity);
     $this->assertTrue(!$entity->has('created_by'));
     $this->assertEquals(1, $entity->get('modified_by'));
 }
开发者ID:quickapps-plugins,项目名称:user,代码行数:14,代码来源:WhoDidItBehaviorTest.php

示例12: beforeSave

 /**
  * Every save event triggers a new personal_key. If the entity is new then
  * check the config if there needs to be an email verification.
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $entity->set('personal_key');
     if ($entity->isNew()) {
         if (Configure::read('Users.send_email_verification')) {
             $entity->emailVerification();
         }
     }
 }
开发者ID:propellerstudios,项目名称:users-plugin,代码行数:13,代码来源:UsersTable.php

示例13: beforeSave

 /**
  * {@inheritDoc}
  */
 public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
 {
     if (empty($options['loggedInUser'])) {
         return;
     }
     if ($entity->isNew()) {
         $entity->set('created_by', $options['loggedInUser']);
     }
     $entity->set('modified_by', $options['loggedInUser']);
 }
开发者ID:steinkel,项目名称:blame,代码行数:13,代码来源:BlameBehavior.php

示例14: afterSave

 public function afterSave(Event $event, Entity $entity)
 {
     $job_id = $entity->job_id;
     $event_id = isset($entity->event_id) ? $entity->event_id : 1;
     // default to event type 1 (new file upload)
     // format file list, if applicable
     $files = '';
     if ($this->files) {
         foreach ($this->files as $file) {
             $files .= basename($file) . '<br/>';
         }
     }
     // NEW FILE IS UPLOADED
     if ($entity->isNew()) {
         $Activity = TableRegistry::get('Activity');
         $activity = $Activity->find('all')->where(['Activity.id' => $entity->id])->contain(['Files', 'Users', 'Creatives', 'Jobs'])->first()->toArray();
         //die(print_r($activity));
         $Notifications = TableRegistry::get('Notifications');
         // set conditions for notification query
         $conditions = ['OR' => [['Notifications.event_id' => "4"], ['Notifications.job_id' => $job_id, 'OR' => [['Notifications.event_id' => $event_id], ['Notifications.event_id' => "3"]]]]];
         if ($notify_users = $Notifications->find('all', ['conditions' => $conditions, 'group' => ['Notifications.user_id'], 'contain' => ['Users']])) {
             $notify_users = $notify_users->toArray();
             $Events = TableRegistry::get('Events');
             $event = $Events->get($event_id)->toArray();
             $text = $event['email_text'];
             $text = str_replace("%username%", $activity['user']['first_name'], $text);
             $text = str_replace("%fileversion%", $activity['file']['version'], $text);
             $text = str_replace("%filename%", $activity['file']['name'], $text);
             $text = str_replace("%dimensions%", $activity['file']['width'] && $activity['file']['height'] ? $activity['file']['width'] . 'X' . $activity['file']['height'] : 'N/A', $text);
             $text = str_replace("%size%", $activity['file']['size'], $text);
             $text = str_replace("%jobname%", $activity['job']['name'], $text);
             $text = str_replace("%joblink%", $activity['job']['short_link'] . '#' . $activity['creative']['slug'], $text);
             $text = str_replace("%creativename%", $activity['creative']['name'], $text);
             $text = str_replace("%files%", $files, $text);
             $subject = $event['email_subject'];
             $subject = str_replace("%filename%", $activity['file']['name'], $subject);
             $subject = str_replace("%jobname%", $activity['job']['name'], $subject);
             $subject = str_replace("%username%", $activity['user']['first_name'], $subject);
             foreach ($notify_users as $user) {
                 $name = $user['user']['first_name'];
                 $email = $user['user']['email'];
                 $body = file_get_contents(WWW_ROOT . DS . 'email/notify.html');
                 $body = str_replace("%name%", $name, $body);
                 $body = str_replace("%username%", $name, $body);
                 $body = str_replace("%email%", $email, $body);
                 $body = str_replace("%text%", $text, $body);
                 if (AppController::sendEmail(['subject' => $subject, 'body' => $body, 'to' => $email])) {
                     $Notifications->save($Notifications->newEntity(['id' => $user['id']]));
                 } else {
                     // epic fail
                 }
             }
         }
     }
 }
开发者ID:dlowetz,项目名称:asset-preview,代码行数:55,代码来源:ActivityTable.php

示例15: beforeSave

 /**
  * save
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $config = $this->config();
     $fields = $config['fields'];
     foreach ($fields as $key => $value) {
         $historic[$value] = $entity->get($value);
     }
     if (!$entity->isNew() && ($historicOld = $this->_table->Historics->find()->where([$this->foreignKey => $entity->id])->toArray())) {
         $this->_table->Historics->patchEntity($historicOld[0], ['is_active' => 0]);
         $entity->set('historics', [$this->_table->Historics->newEntity($historic), $historicOld[0]]);
     } else {
         $entity->set('historics', [$this->_table->Historics->newEntity($historic)]);
     }
     $entity->dirty('historics', true);
 }
开发者ID:oxenti,项目名称:historic,代码行数:18,代码来源:HistoricBehavior.php


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