Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 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();
     }
 }
Ejemplo n.º 3
0
 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();
 }