/** * @return int * @throws \Exception */ public function getFileCount() { $count = File::find()->where(['itemId' => $this->owner->getAttribute('id'), 'model' => $this->getModule()->getShortClass($this->owner)])->count(); return (int) $count; }
public function actionSetOrder() { $order = array_reverse(Yii::$app->request->post('order', [])); foreach ($order as $sort => $fileId) { $file = File::findOne($fileId); /** @var File $file */ $file->sort = $sort + 1; $file->save(); } }
public function detachFile($id) { /** @var File $file */ $file = File::findOne(['id' => $id]); $filePath = $this->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type; unlink($filePath); $file->delete(); }