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


PHP Contact::deleteAll方法代码示例

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


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

示例1: beforeDelete

 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         Contact::deleteAll('member_id = :member_id', [':member_id' => $this->id]);
         foreach ($this->codes as $code) {
             if ($code->delete() === false) {
                 return false;
             }
         }
         return true;
     }
     return false;
 }
开发者ID:EuresTools,项目名称:eVote-web,代码行数:13,代码来源:MemberBase.php

示例2: deleteMemberData

 public function deleteMemberData()
 {
     // Delete all existing members.
     // get member ids to delete
     $memberIds = ArrayHelper::getColumn($this->members, 'id');
     if (sizeof($memberIds) > 0) {
         // without members there should be no contact etc.
         $transaction = Yii::$app->db->beginTransaction();
         try {
             // delete contacts by member_id
             Contact::deleteAll(['member_id' => $memberIds]);
             /*
             $codes = app\models\Code::find()
                 ->select('id')
                 //->where(['poll_id' => $this->id, 'member_id' => $memberIds]) // member_id not required because i will delete all anyhow?
                 ->where(['poll_id' => $this->id])
                 ->asArray()
                 ->all();
             $codeIds = ArrayHelper::getColumn($codes, 'id');
             */
             // alternative also over the codes relation depends on what is "faster"
             $codeIds = ArrayHelper::getColumn($this->codes, 'id');
             // delete the votes by the code_id
             Vote::deleteAll(['code_id' => $codeIds]);
             // delete the Codes by poll_id and member_id
             //Code::deleteAll(['poll_id'=> $this->id, 'member_id' => $memberIds]);
             Code::deleteAll(['poll_id' => $this->id]);
             // member_id not required because i will delete all anyhow?
             // also delete member entries by id
             Member::deleteAll(['id' => $memberIds]);
             $transaction->commit();
             return true;
         } catch (Exception $e) {
             $transaction->rollBack();
             return false;
         }
     }
     return true;
 }
开发者ID:EuresTools,项目名称:eVote-web,代码行数:39,代码来源:Poll.php

示例3: actionUpdate

 /**
  * Updates an existing Member model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelContacts = $model->contacts;
     if ($model->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelContacts, 'id', 'id');
         $modelContacts = Model::createMultiple(Contact::classname(), $modelContacts);
         Model::loadMultiple($modelContacts, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelContacts, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::ValidateMultiple($modelContacts), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelContacts) && $valid;
         if ($valid) {
             $transaction = Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         Contact::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelContacts as $modelContact) {
                         $modelContact->member_id = $model->id;
                         if (!($flag = $modelContact->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     //return $this->redirect(['view', 'id' => $model->id]);
                     return $this->redirect($this->getReturnUrl(['view', 'id' => $model->id]));
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['model' => $model, 'modelContacts' => empty($modelContacts) ? [new Contact()] : $modelContacts]);
 }
开发者ID:EuresTools,项目名称:eVote-web,代码行数:50,代码来源:MemberController.php


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