Beispiel #1
0
 public function bootstrap($app)
 {
     Event::on(RatingModule::className(), RatingModule::EVENT_RATING_ADD, function ($event) {
         $torrent = \Yii::$app->db->cache(function ($db) use($event) {
             return Torrent::findOne($event->recordId);
         });
         $torrent->rating_avg = ($torrent->rating_votes * $torrent->rating_avg + $event->rating) / ($torrent->rating_votes + 1);
         $torrent->rating_votes = $torrent->rating_votes + 1;
         $torrent->save(false);
     });
     Event::on(ComplainModule::className(), ComplainModule::EVENT_COMPLAINT_ADD, function ($event) {
         if ($event->total >= \Yii::$app->params['numberComplaintsToHide'] && ($event->type === Complaint::TYPE_FAKE || $event->type === Complaint::TYPE_VIRUS)) {
             $torrent = \Yii::$app->db->cache(function ($db) use($event) {
                 return Torrent::findOne($event->recordId);
             });
             $torrent->visible_status = Torrent::VISIBLE_STATUS_DIRECT;
             $torrent->save(false);
         }
     });
     Event::on(CommentModule::className(), CommentModule::EVENT_COMMENT_ADD, function ($event) {
         $torrent = \Yii::$app->db->cache(function ($db) use($event) {
             return Torrent::findOne($event->recordId);
         });
         $torrent->comments_count = $torrent->comments_count + 1;
         $torrent->save(false);
     });
 }
Beispiel #2
0
 /**
  * Finds the Torrent model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Torrent the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     $model = Yii::$app->db->cache(function ($db) use($id) {
         return Torrent::findOne($id);
     });
     if ($model !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function beforeAction($action)
 {
     $id = Yii::$app->request->getQueryParam('id');
     $this->torrent = Yii::$app->db->cache(function ($db) use($id) {
         return Torrent::findOne($id);
     });
     if (!$this->torrent) {
         $this->error404();
         return false;
     }
     if (!$this->checkAccess()) {
         $this->error404();
         return false;
     }
     $this->checkUrl();
     return true;
 }