/** * @param mixed $event */ public function afterInsert($event) { /* @var $row AlbumFileInformation */ $row = $event->sender; /* @var $album Album */ $album = $row->getAlbum()->one(); $fileInformationList = AlbumFileInformation::find()->where(['album_id' => $album->getId()])->all(); if (!is_array($fileInformationList)) { return; } $album->setPhotoCount(count($fileInformationList))->save(); }
/** * @param integer $albumId * @param integer $fileInformationId * @return \ImageMS\models\Album\FileInformation\AlbumFileInformation */ public function add($albumId, $fileInformationId) : AlbumFileInformation { $row = new AlbumFileInformation(); $row->setAlbumId($albumId)->setFileInformationId($fileInformationId)->save(); return $row; }
/** * @return \yii\db\ActiveQuery */ public function getImageInAlbum() { return $this->hasMany(AlbumFileInformation::className(), ['album_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getImageAlbum2fileInformations() { return $this->hasMany(AlbumFileInformation::className(), ['file_information_id' => 'id']); }