title = 'Документы';
$this->params['breadcrumbs'][] = ['label' => 'Документы', 'url' => ['index'] ];
$ucat = Yii::$app->request->get('cat', '');
if( $ucat ){
$this->params['breadcrumbs'][] = ['label' => $ucat, 'url' => ['index', 'cat'=>$ucat]];
}
$croute = '/manager/docs';
$rootcat = $model->GetRootCat();
$curcat = $model->GetCat();
$cat = yii\helpers\FileHelper::findDirectories($curcat);
$files = yii\helpers\FileHelper::findFiles($curcat,['recursive'=>false]);
$ckey = 'dosc_cat_'.md5($ucat);
Yii::$app->cache->delete($ckey);
$docs = Yii::$app->cache->getOrSet( $ckey, function () use ($model, $ucat) {
return $model->find()->where(['cat'=>$ucat?$ucat:null])->all();
},2 );
//var_dump($docs);
$docsf = [];
foreach($docs as $key => $item){
$docsf[$item->uid] = $key;
}
//$docsf = array_flip( yii\helpers\ArrayHelper::getColumn($docs, "uid") );
?>
session->hasFlash('success')): ?>
info!
=Yii::$app->session->getFlash('success');?>
= Html::a('Создать Docs', ['create', 'cat' => $ucat], ['class' => 'btn btn-success']) ?>
= Html::a('Создать Папку', ['catcreate'], ['class' => 'btn btn-success']) ?>
= Html::a('Массовая загрузка', ['uploads', 'cat'=>$ucat ], ['class' => 'btn btn-success']) ?>
foreach($cat as $item ){
$file = str_replace( $rootcat.'/', '', $item );
?>
-
=$file?>
}
foreach($files as $item ){
$ext = pathinfo($item, PATHINFO_EXTENSION);
// $bsaename = str_replace( '.'.$ext, '', pathinfo($item, PATHINFO_BASENAME));
$bsaename = str_replace( '.', '_', pathinfo($item, PATHINFO_BASENAME));
if( $ext == 'webp' ) continue;
$file = str_replace( $rootcat.'/', '', $item );
$ext = pathinfo($item, PATHINFO_EXTENSION);
$webp = str_replace( '.'.$ext, '.webp', $item );
if( !file_exists($webp) && $ext != 'webp' && ( $ext == 'pdf' || $ext == 'jpg' || $ext == 'png' || $ext == 'jpeg' || $ext == 'svg' )){
exec('convert -thumbnail x200 -background white -alpha remove '.$item.'[0] '.$webp);
}
$url = $model::$story_dir. DIRECTORY_SEPARATOR .$file;
?>
-
if( file_exists($webp) ){
?>
}else{
?>
}
$key = pathinfo($item, PATHINFO_BASENAME);
// $p = $model->find()->where(['uid'=>$key])->one();
$p = isset($docsf[$key])?$docs[$docsf[$key]]:false;
if( $p ){
$title = $p->title;
$id = $p->id;
unset($docsf[$key]);
}else{
$title = $file;
$id = $key."&cat=$ucat";
}
?>
=$title?>
}
?>
foreach($docsf as $item ){
$p = $docs[$item];
$id = $p->id;
?>
-
=$p->title?>
}
?>
\Yii::$app->assetManager->bundles['yii\\bootstrap\\BootstrapAsset'] = [
'css' => [],
'js' => []
];
?>
= FileUpload::widget([
'model' => $model,
'attribute' => 'file',
'url' => ['docsupload', 'id' => 0, 'cat'=>$ucat],
'options' => ['accept' => '*'],
'clientOptions' => [
'limitConcurrentUploads' => 3,
'disableImageMetaDataLoad' => true,
'autoUpload' => true,
],
// ...
'clientEvents' => [
'fileuploaddone' => 'function(e, data) {
res = JSON.parse(data.result);
$("#filesbox").append(" "+res.files[0].name+"");
var obj = poper.get(res.files[0].oname);
setTimeout(() => {
obj.css("display", "none");
}, 2000);
e.preventDefault();
}',
'fileuploadfail' => 'function(e, data) {
// console.log(e);
console.log(data);
e.preventDefault();
}',
'fileuploadchange' => 'function(e, data) {
starting(e, data);
}',
'fileuploaddrop' => 'function(e, data) {
starting(e, data);
}',
'fileuploadprogress' =>'function(e,data) {
e.preventDefault();
progress = parseInt(data.loaded / data.total * 100, 10);
var obj = poper.get(data.files[0].name);
obj.find(".progress-bar").css("width", progress+"%");
}',
'fileuploadstop' => 'function(e) {
console.log("fin");
setTimeout(() => {
window.location.reload();
}, 3000);
}'
],
]); ?>
$this->registerJs(<<