Skip to content

Commit a7d5b8f

Browse files
committed
Clean meta for release
1 parent f2fb96f commit a7d5b8f

File tree

9 files changed

+118
-82
lines changed

9 files changed

+118
-82
lines changed

README.md

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ File uploads and management, for CodeIgniter 4
66
1. Install with Composer: `> composer require tatter/files`
77
2. Migrate the database: `> php spark migrate -all`
88
2. Seed the database: `> php spark db:seed "Tatter\Files\Database\Seeds\FileSeeder"`
9-
3. Start managing files: https://[yourdomain.com]/files
9+
3. Start managing files: https://example.com/files
1010

1111
## Features
1212

1313
The Files module is a self-contained set of routes and functions that adds uploading and
1414
CRUD controls to any project. It uses [DropzoneJS](https://www.dropzonejs.com) for
15-
drag-and-drop uploads, and supports a number of extensions for directing files to other
16-
locations (WIP).
15+
drag-and-drop uploads, and supports a number of extensions for generating file thumbnails
16+
and exporting files to various destinations.
1717

1818
## Installation
1919

@@ -41,14 +41,20 @@ writable/files/*
4141
## Configuration (optional)
4242

4343
The library's default behavior can be altered by extending its config file. Copy
44-
**bin/Files.php** to **app/Config/** and follow the instructions
44+
**examples/Files.php** to **app/Config/** and follow the instructions
4545
in the comments. If no config file is found in **app/Config** the library will use its own.
4646

4747
## Usage
4848

4949
Default routes:
5050
* **files/index** - If user is allowed `mayList()` then shows all files, otherwise tries to fall back to the current logged in user
51-
* **files/user** - Shows files for a single user; if no user ID is supplied it defaults to the current logged in user
51+
* **files/user/{userId}** - Shows files for a single user; if no user ID is supplied it defaults to the current logged in user
52+
* **files/thumbnail/{fileId}** - Displays the thumbnail for a file
53+
54+
CRUD:
55+
* **files/upload** - Accepts upload requests from Dropzone
56+
* **files/delete/{fileId}** - Removes a file
57+
* **files/rename/{fileId}** - Accepts POST data to rename a file
5258

5359
Available formats:
5460
* **?format=cards** - Default view with thumbnail on responsive layout
@@ -63,3 +69,51 @@ group for global file access.
6369

6470
By default the **files/** routes are available as soon as the module is installed. In most
6571
cases you will want to use Route Filters to restrict some or all of the routes.
72+
73+
## Extending
74+
75+
**Controllers/Files.php** is the heart of the module, using cascading options to choose
76+
which files to display when. This controller has a `setData()` method to allow you to
77+
intercept this process to provide your own settings at any point. Simply extend the
78+
controller to your own and then provide whatever changes you would like, followed
79+
by the `display()` method. E.g.:
80+
81+
```
82+
<?php namespace App\Controller;
83+
84+
class WidgetFiles
85+
{
86+
public function index($widgetId)
87+
{
88+
$this->setData([
89+
'format' => 'cards',
90+
'files' => model(WidgetModel::class)->getFiles($widgetId),
91+
'layout' => 'manage',
92+
]);
93+
94+
return $this->display();
95+
}
96+
}
97+
98+
```
99+
100+
These are the default options for `setData()`, but you may also supply anything else you
101+
need in your view:
102+
103+
* `source` - The name of the controller method making the call
104+
* `layout` - The view layout to use (see **Config/Files.php**)
105+
* `files` - An array of Files to display
106+
* `selected` - Files to pre-select (for the `select` format)
107+
* `userId` - ID of a user to filter for Files`
108+
* `username` - Display name of the user for the default layout title
109+
* `ajax` - Whether to process the request as an AJAX call (skips layout wrapping)
110+
* `search` - Search term to filter Files
111+
* `sort` - File sort field
112+
* `order` - File sort order
113+
* `format` - Display format for files (cards, list, select, or your own!)
114+
* `perPage` - Number of items to display per page
115+
* `page` - Page number (leave `null` for default Pager handling)
116+
* `pager` - `Pager` instance to handle pagination
117+
* `access` - Whether the files can be modified, "manage" or "display"
118+
* `exports` - Destinations a File may be sent to (see `Tatter\Exports`)
119+
* `bulks` - Bulk destinations for a group of Files (see `Tatter\Exports`)

bin/Files.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

examples/Files.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php namespace Config;
2+
3+
/***
4+
*
5+
* This file contains example values to alter default library behavior.
6+
* Recommended usage:
7+
* 1. Copy the file to app/Config/Files.php
8+
* 2. Change any values
9+
* 3. Remove any lines to fallback to defaults
10+
*
11+
***/
12+
13+
class Files extends \Tatter\Files\Config\Files
14+
{
15+
/**
16+
* Directory to store files (with trailing slash)
17+
*
18+
* @var string
19+
*/
20+
public $storagePath = WRITEPATH . 'files/';
21+
22+
/**
23+
* Layouts to use for general access and for administration
24+
*
25+
* @var array<string, string>
26+
*/
27+
public $layouts = [
28+
'public' => 'Tatter\Files\Views\layout',
29+
'manage' => 'Tatter\Files\Views\layout',
30+
];
31+
32+
/**
33+
* View file aliases
34+
*
35+
* @var string[]
36+
*/
37+
public $views = [
38+
'dropzone' => 'Tatter\Files\Views\Dropzone\config',
39+
];
40+
41+
/**
42+
* Default display format; built in are 'cards', 'list', 'select'
43+
*
44+
* @var string
45+
*/
46+
public $defaultFormat = 'cards';
47+
48+
/**
49+
* Path to the default thumbnail file
50+
*
51+
* @var string
52+
*/
53+
public $defaultThumbnail = 'Tatter\Files\Assets\Unavailable.jpg';
54+
}
File renamed without changes.

src/Commands/MaintainFiles.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Config/Files.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Files extends BaseConfig
1414
/**
1515
* Layouts to use for general access and for administration
1616
*
17-
* @var string[]
17+
* @var array<string, string>
1818
*/
1919
public $layouts = [
2020
'public' => 'Tatter\Files\Views\layout',

src/Config/Routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
$routes->group('files', ['namespace' => '\Tatter\Files\Controllers'], function ($routes)
55
{
66
$routes->get('/', 'Files::index');
7-
$routes->get('index/(:any)', 'Files::index/$1');
7+
$routes->get('user', 'Files::user');
88
$routes->get('user/(:any)', 'Files::user/$1');
9-
//$routes->get('delete/(:num)', 'Files::delete/$1');
9+
$routes->get('delete/(:num)', 'Files::delete/$1');
1010
$routes->get('thumbnail/(:num)', 'Files::thumbnail/$1');
1111

1212
$routes->post('upload', 'Files::upload');

src/Controllers/Files.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,6 @@ public function user($userId = null)
213213
return $this->display();
214214
}
215215

216-
/**
217-
* Lists selectable files for a form (AJAX).
218-
*
219-
* @param string|integer|null $userId Optional user to filter by
220-
*
221-
* @return RedirectResponse|string
222-
*/
223-
public function select($userId = null)
224-
{
225-
$this->setData(['format' => 'select']);
226-
227-
// If a list of File IDs was passed then pre-select them
228-
if ($ids = $this->request->getVar('selected'))
229-
{
230-
$this->setData(['selected' => explode(',', $ids)]);
231-
}
232-
233-
return $userId ? $this->user($userId) : $this->index();
234-
}
235-
236216
//--------------------------------------------------------------------
237217

238218
/**
@@ -611,6 +591,7 @@ protected function setDefaults(): self
611591
{
612592
return $this->setData([
613593
'source' => 'index',
594+
'layout' => 'public',
614595
'files' => null,
615596
'selected' => explode(',', $this->request->getVar('selected') ?? ''),
616597
'userId' => null,

src/Views/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?= $this->extend(config('Files')->layouts['public']) ?>
1+
<?= $this->extend(config('Files')->layouts[$layout ?? 'public']) ?>
22
<?= $this->section('main') ?>
33

44
<div class="row">

0 commit comments

Comments
 (0)