Skip to content

Commit

Permalink
Adicionada capa do livro e melhorado detalhes na lista e vizualização…
Browse files Browse the repository at this point in the history
… única.
  • Loading branch information
andrebian committed Dec 20, 2015
1 parent 37b8fa1 commit b89426c
Show file tree
Hide file tree
Showing 224 changed files with 135 additions and 101,467 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/build
/dist
/tags
/app/webroot/files/*
!/app/webroot/files/empty

# OS generated files #
######################
Expand Down
41 changes: 41 additions & 0 deletions app/File/FileManipulator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* Class FileManipulator
*/
class FileManipulator
{

private $path;

/**
* @param null $path
*/
public function __construct($path = null)
{
$this->path = dirname(__DIR__) . '/webroot/files';
if (!empty($path)) {
$this->path = $path;
}
}

/**
* @param string $key
* @todo: Validate image
*/
public function doTheUpload(array $file)
{
$destinationFile = $this->path . '/' . $file['name'];
move_uploaded_file($file['tmp_name'], $destinationFile);
}

/**
* @param $fileName
* @param null $path
*/
public function removeFile($fileName)
{
$fileToRemove = $this->path . '/' . $fileName;
unlink($fileToRemove);
}
}
26 changes: 23 additions & 3 deletions app/Model/Book.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
App::uses('AppModel', 'Model');
App::uses('FileManipulator', 'File');

/**
* Class Book
Expand Down Expand Up @@ -53,15 +54,34 @@ public function beforeSave($options = array())
}

if (isset($this->data[$this->alias]['attachment'])) {
$attach = $this->data[$this->alias]['attachment']['name'];
$file = $this->data[$this->alias]['attachment'];

if (!empty($file['name'])) {
$this->data[$this->alias]['attachment'] = $file['name'];

$uploader = new FileManipulator();
$uploader->doTheUpload($file);

if (!empty($attach)) {
$this->data[$this->alias]['attachment'] = $attach;
} else {
unset($this->data[$this->alias]['attachment']);
}
}

parent::beforeSave($options);
}

public function beforeDelete($cascade = true)
{
$book = $this->read(null, $this->id);
$attachment = $book['Book']['attachment'];

if (!empty($attachment)) {
$uploader = new FileManipulator();
$uploader->removeFile($attachment);
}

return parent::beforeDelete($cascade);
}


}
69 changes: 46 additions & 23 deletions app/View/Books/index.ctp
Original file line number Diff line number Diff line change
@@ -1,41 +1,64 @@
<h2><?php echo __('Meus livros'); ?></h2>

<?php
$imageExtensions = array(
'jpg', 'jpeg', 'bmp', 'png', 'gif'
);
?>

<?php echo $this->Html->link('Adicionar livro', array('action' => 'add'), array('class' => 'btn btn-primary')); ?>
<br />
<br />
<br/>
<br/>
<table class="table table-hover">
<thead class="th">
<tr>
<th><?php echo $this->Paginator->sort('name', 'Nome'); ?></th>
<th><?php echo $this->Paginator->sort('isbn', 'ISBN'); ?></th>
<th><?php echo $this->Paginator->sort('acquired_form', 'Meio'); ?></th>
<th><?php echo $this->Paginator->sort('buyer', 'Comprador'); ?></th>
<th><?php echo $this->Paginator->sort('purchase_point', 'Local'); ?></th>
<th class="tenpercent"><?php echo $this->Paginator->sort('price', 'Valor'); ?></th>
<th><?php echo $this->Paginator->sort('date_buy', 'Data'); ?></th>
<th class="actions"><?php echo __('Opções'); ?></th>
</tr>
<tr>
<th><?php echo $this->Paginator->sort('name', 'Capa'); ?></th>
<th><?php echo $this->Paginator->sort('name', 'Detalhes'); ?></th>
<th><?php echo $this->Paginator->sort('date_buy', 'Registrado em'); ?></th>
<th class="actions"><?php echo __('Opções'); ?></th>
</tr>
</thead>
<tfoot class="th">
<tr>
<th><?php echo $this->Paginator->sort('name', 'Capa'); ?></th>
<th><?php echo $this->Paginator->sort('name', 'Detalhes'); ?></th>
<th><?php echo $this->Paginator->sort('date_buy', 'Registrado em'); ?></th>
<th class="actions"><?php echo __('Opções'); ?></th>
</tr>
</tfoot>
<?php foreach ($books as $book): ?>
<tr>
<td>

<?php if (!empty($book['Book']['attachment'])) : ?>

<?php
$attachment = $book['Book']['attachment'];
$attachmentExploded = explode('.', $attachment);
$currentImageExtension = end($attachmentExploded);
?>

<?php if (in_array($currentImageExtension, $imageExtensions)) : ?>
<?php echo '<br />' . $this->Html->image('/files/' . $book['Book']['attachment'], array('width' => 128, 'url' => array('action' => 'view', $book['Book']['id']))); ?>
<?php endif; ?>
<?php endif; ?>
&nbsp;
</td>
<td>
<?php
echo $this->Html->link($book['Book']['name'], 'javascript:;', array('title' => 'Autor: ' . $book['Book']['author'] . "\nEditora: " .
echo $this->Html->link($book['Book']['name'], array('action' => 'view', $book['Book']['id']), array('title' => 'Autor: ' . $book['Book']['author'] . "\nEditora: " .
$book['Book']['publishing_house'] . "\n\nSinopse:\n" . $book['Book']['resume'], 'class' => 'ttip_t'));
?>
&nbsp;
?><br/>
<?php echo $book['Book']['author']; ?>
</td>
<td>
<?php if (!empty($book['Book']['date_buy'])) : ?>
<?php echo date('d/m/Y', strtotime($book['Book']['date_buy'])); ?>&nbsp;
<?php endif; ?>
</td>
<td><?php echo h($book['Book']['isbn']); ?>&nbsp;</td>
<td><?php echo h($book['Book']['acquired_form']); ?>&nbsp;</td>
<td><?php echo h($book['Book']['buyer']); ?>&nbsp;</td>
<td><?php echo h($book['Book']['purchase_point']); ?>&nbsp;</td>
<td>R$ <?php echo number_format($book['Book']['price'], 2, ',', '.'); ?>&nbsp;</td>
<td><?php echo date('d/m/Y', strtotime($book['Book']['date_buy'])); ?>&nbsp;</td>
<td class="actions">
<?php echo $this->Html->link('Log', array('controller' => 'books_logs', 'action' => 'index', $book['Book']['id']), array('class' => 'btn btn-mini btn-primary')); ?>
&nbsp;
<?php echo $this->Html->link('Detalhes', array('action' => 'view', $book['Book']['id']), array('class' => 'btn btn-mini btn-success')); ?>
&nbsp;
<?php echo $this->Form->postLink('Remover', array('action' => 'delete', $book['Book']['id']), array('class' => 'btn btn-mini btn-danger'), __('Deseja realmente remover o livro %s?', $book['Book']['name'])); ?>

</td>
Expand Down
23 changes: 23 additions & 0 deletions app/View/Books/view.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<li class="active">Detalhes</li>
</ul>

<?php
$imageExtensions = array(
'jpg', 'jpeg', 'bmp', 'png', 'gif'
);
?>

<div class="books view">
<h2><?php echo 'Informações de "' . $book['Book']['name'] . '"'; ?></h2>
<dl>
Expand All @@ -14,6 +20,23 @@
<dd><?php echo h($book['Book']['resume']); ?>&nbsp;</dd>
<br />

<dt>Capa</dt>
<dd>
<?php if (!empty($book['Book']['attachment'])) : ?>

<?php
$attachment = $book['Book']['attachment'];
$attachmentExploded = explode('.', $attachment);
$currentImageExtension = end($attachmentExploded);
?>

<?php if (in_array($currentImageExtension, $imageExtensions)) : ?>
<?php echo '<br />' . $this->Html->image('/files/' . $book['Book']['attachment'], array('width' => 350)); ?>
<?php endif; ?>
<?php endif; ?>
</dd>
<br />

<dt>ISBN</dt>
<dd><?php echo h($book['Book']['isbn']); ?>&nbsp;</dd>
<br />
Expand Down
140 changes: 0 additions & 140 deletions app/webroot/coverage/app.dashboard.html

This file was deleted.

Loading

0 comments on commit b89426c

Please sign in to comment.