/** * Generate links to files to use them as messages. * @param string $type Message type, ok or error. * @return array */ private function linksToFiles($type = 'ok') { $array = $type == 'ok' ? $this->_oks : $this->_errors; $files = File::find()->where(['guid' => array_keys($array)])->all(); foreach ($files as $file) { $array[$file->guid] = Url::to(['file/' . $file->guid]); } return $array; }
public function actionIndex() { $this->title = Yii::t('vps-uploader', 'File list'); $query = File::find(); $provider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['dt' => SORT_DESC]], 'pagination' => ['pageSize' => 50, 'forcePageParam' => false, 'pageSizeParam' => false, 'urlManager' => new \yii\web\UrlManager(['enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => ['uploader/file/<page>' => 'uploader/file/index']])]]); // Last uploaded files. $last = Yii::$app->request->get('last', ''); $this->data('last', StringHelper::explode($last)); // Common files list. $this->data('files', $provider->models); $this->data('pagination', $provider->pagination); }
/** * Copy file name to GUIDs. * @param string[] $guids * @return BatchResult */ public static function guidFromName($guids) { $result = new BatchResult(); $files = File::find()->where(['guid' => $guids])->all(); foreach ($files as $file) { $guid = $file->guid; $file->guid = $file->name; if ($file->save()) { $file->rename($file->guid); $result->ok($file->guid); } else { $result->error($guid); } } return $result; }
public function actionIndex() { $this->title = Yii::t('vps-uploader', 'VPS uploader'); $this->data('last', File::find()->orderBy(['dt' => SORT_DESC])->limit(20)->all()); }