From 351a119a5904d836f1bf468d65b4bb1a7a5abc30 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 24 Aug 2016 19:02:03 +0900 Subject: [PATCH] =?UTF-8?q?https://github.com/NetCommons3/Topics/commit/d1?= =?UTF-8?q?a47328c69f53320bee5949ff089d5ecccc5b18=20=E3=81=A7=E3=80=81afte?= =?UTF-8?q?rSave()=E3=81=AB=E3=81=82=E3=82=8B=E5=87=A6=E7=90=86=E3=82=92sa?= =?UTF-8?q?veTopics()=E3=81=AB=E7=A7=BB=E3=81=97=E3=81=A6=E3=80=81afterSav?= =?UTF-8?q?e=E3=81=8B=E3=82=89saveTopics=E3=81=AB=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E3=80=82=E5=90=8C=E3=81=98=E3=81=8F=E3=80=81beforeDelete?= =?UTF-8?q?=E3=80=81afterDelete=E3=82=82=E5=90=8C=E6=A7=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Behavior/TopicsBehavior.php | 104 +++++++++++++++--------------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/Model/Behavior/TopicsBehavior.php b/Model/Behavior/TopicsBehavior.php index feaeb42..2831a4b 100644 --- a/Model/Behavior/TopicsBehavior.php +++ b/Model/Behavior/TopicsBehavior.php @@ -94,47 +94,9 @@ public function setup(Model $model, $config = array()) { * saveTopics * * @param Model $model 呼び出し元のモデル - * @return void - */ - public function saveTopics(Model $model) { - $this->afterSave($model, false, array('fieldList' => false)); - } - -/** - * beforeDeleteTopics - * - * @param Model $model 呼び出し元のモデル - * @return void - */ - public function beforeDeleteTopics(Model $model) { - $this->beforeDelete($model, true); - } - -/** - * afterDeleteTopics - * - * @param Model $model 呼び出し元のモデル - * @return void - */ - public function afterDeleteTopics(Model $model) { - $this->afterDelete($model); - } - -/** - * afterSave is called after a model is saved. - * - * @param Model $model 呼び出し元のモデル - * @param bool $created True if this save created a new record - * @param array $options Options passed from Model::save(). * @return bool - * @see Model::save() */ - public function afterSave(Model $model, $created, $options = array()) { - //$options['fieldList']がセットされているときは、saveFieldから実行されたとして判断し、処理しない - if ($options['fieldList']) { - return true; - } - + public function saveTopics(Model $model) { $model->loadModels([ 'Topic' => 'Topics.Topic', 'TopicUserStatus' => 'Topics.TopicUserStatus', @@ -153,20 +115,16 @@ public function afterSave(Model $model, $created, $options = array()) { $this->_saveTopicReadable($model, $topicId); } - return parent::afterSave($model, $created, $options); + return true; } /** - * Before delete is called before any delete occurs on the attached model, but after the model's - * beforeDelete is called. Returning false from a beforeDelete will abort the delete. + * beforeDeleteTopics * - * @param Model $model Model using this behavior - * @param bool $cascade If true records that depend on this record will also be deleted - * @return mixed False if the operation should abort. Any other result will continue. - * @throws InternalErrorException - * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + * @param Model $model 呼び出し元のモデル + * @return bool */ - public function beforeDelete(Model $model, $cascade = true) { + public function beforeDeleteTopics(Model $model) { $model->loadModels([ 'Block' => 'Blocks.Block', 'Topic' => 'Topics.Topic', @@ -219,13 +177,13 @@ public function beforeDelete(Model $model, $cascade = true) { } /** - * After delete is called after any delete occurs on the attached model. + * afterDeleteTopics * - * @param Model $model Model using this behavior + * @param Model $model 呼び出し元のモデル * @return void * @throws InternalErrorException */ - public function afterDelete(Model $model) { + public function afterDeleteTopics(Model $model) { $model->loadModels([ 'Topic' => 'Topics.Topic', 'TopicReadable' => 'Topics.TopicReadable', @@ -256,6 +214,50 @@ public function afterDelete(Model $model) { } } +/** + * afterSave is called after a model is saved. + * + * @param Model $model 呼び出し元のモデル + * @param bool $created True if this save created a new record + * @param array $options Options passed from Model::save(). + * @return bool + * @see Model::save() + */ + public function afterSave(Model $model, $created, $options = array()) { + //$options['fieldList']がセットされているときは、saveFieldから実行されたとして判断し、処理しない + if ($options['fieldList']) { + return true; + } + + $this->saveTopics($model); + + return parent::afterSave($model, $created, $options); + } + +/** + * Before delete is called before any delete occurs on the attached model, but after the model's + * beforeDelete is called. Returning false from a beforeDelete will abort the delete. + * + * @param Model $model Model using this behavior + * @param bool $cascade If true records that depend on this record will also be deleted + * @return mixed False if the operation should abort. Any other result will continue. + * @throws InternalErrorException + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + */ + public function beforeDelete(Model $model, $cascade = true) { + return $this->beforeDeleteTopics($model); + } + +/** + * After delete is called after any delete occurs on the attached model. + * + * @param Model $model Model using this behavior + * @return void + */ + public function afterDelete(Model $model) { + $this->afterDeleteTopics($model); + } + /** * 既読データの登録 *