Paperyard
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Paperyard\Controllers\Archive\Archive Class Reference
Inheritance diagram for Paperyard\Controllers\Archive\Archive:
Paperyard\Controllers\BasicController

Public Member Functions

 __construct (Twig $view, LoggerInterface $logger, Messages $flash)
 
 __invoke (Request $request, Response $response, $args)
 
 render ()
 
- Public Member Functions inherited from Paperyard\Controllers\BasicController
 getPlugins ()
 
 registerPlugin ($name, $type=PluginType::NORMAL)
 
 getLanguageFlag ()
 

Private Member Functions

 getArchives ()
 
 getFiles ()
 
 getNewestFiles ()
 

Private Attributes

 $rootPath = '/data/sort'
 
 $archiveRelPath
 
 $archiveFullPath
 

Additional Inherited Members

- Protected Attributes inherited from Paperyard\Controllers\BasicController
 $view
 
 $logger
 
 $flash
 

Detailed Description

Definition at line 17 of file Archive.php.

Constructor & Destructor Documentation

Paperyard\Controllers\Archive\Archive::__construct ( Twig  $view,
LoggerInterface  $logger,
Messages  $flash 
)
Parameters
Twig$view
LoggerInterface$logger
Messages$flash

Definition at line 33 of file Archive.php.

34  {
35  $this->view = $view;
36  $this->logger = $logger;
37  $this->flash = $flash;
38 
39  $this->registerPlugin('clickable-row');
40  $this->registerPlugin('searchable-table');
41  $this->registerPlugin('datatables.min');
42  $this->registerPlugin('bootstrap-notify.min');
43  }
registerPlugin($name, $type=PluginType::NORMAL)

Member Function Documentation

Paperyard\Controllers\Archive\Archive::__invoke ( Request  $request,
Response  $response,
  $args 
)
Parameters
Request$request
Response$response
$args
Returns
Response

Definition at line 51 of file Archive.php.

52  {
53  $this->archiveRelPath = $request->getAttribute('path');
54  $this->archiveFullPath = $this->rootPath . $this->archiveRelPath;
55 
56  if (!is_dir($this->archiveFullPath)) {
57  $this->flash->addMessage('error', _('Archive not found.'));
58  return $response->withRedirect('/archive');
59  }
60 
61  $this->view->render($response, 'archive/archive.twig', $this->render());
62  return $response;
63  }
Paperyard\Controllers\Archive\Archive::getArchives ( )
private

Finds all archives deeper than the current.

Returns
array all deeper archives

Definition at line 84 of file Archive.php.

85  {
86  // combine to current path
87  $archive_path = $this->rootPath . $this->archiveRelPath;
88 
89  // iterate over current folder and get every deeper folder
90  $archives = [];
91  $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($archive_path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
92  foreach ($iterator as $file) {
93  if ($file->isDir()) {
94  $archives[] = str_replace($this->rootPath, "", $file);
95  }
96  }
97  return $archives;
98  }
Paperyard\Controllers\Archive\Archive::getFiles ( )
private

Finds all archives deeper than the current.

Returns
array all deeper archives

Definition at line 105 of file Archive.php.

106  {
107  // searchpattern for current archive
108  $archive_search_pattern = $this->archiveFullPath . "/*.pdf";
109 
110  // get files as strings from filesystem
111  $pdfs = glob($archive_search_pattern, GLOB_NOSORT);
112 
113  // convert string elements into ArchiveDocuments objects
114  array_walk($pdfs, function (&$pdf) {
115  $pdf = (new Document($pdf))->toArray();
116  });
117  return $pdfs;
118  }
$pdfs
Paperyard\Controllers\Archive\Archive::getNewestFiles ( )
private

Sort all archives by date.

Returns
array sorted archives

Definition at line 125 of file Archive.php.

126  {
127  // get archive list
128  $pdfs = $this -> getFiles();
129 
130  // sort archives by date
131  usort($pdfs, function($a, $b){
132  return $a['date'] < $b['date'];
133  });
134  return $pdfs;
135  }
$pdfs
Paperyard\Controllers\Archive\Archive::render ( )
Returns
array data to render the view

Definition at line 68 of file Archive.php.

69  {
70  return array(
71  'plugins' => parent::getPlugins(),
72  'languageFlag' => parent::getLanguageFlag(),
73  'archives' => $this->getArchives(),
74  'newestFiles' => $this -> getNewestFiles(),
75  'files' => $this->getFiles()
76  );
77  }

Member Data Documentation

Paperyard\Controllers\Archive\Archive::$archiveFullPath
private

Definition at line 26 of file Archive.php.

Paperyard\Controllers\Archive\Archive::$archiveRelPath
private

Definition at line 23 of file Archive.php.

Paperyard\Controllers\Archive\Archive::$rootPath = '/data/sort'
private

Definition at line 20 of file Archive.php.


The documentation for this class was generated from the following file: