Commit 96aeeb38 by Dirk Benkert

feierabend ..... ;)

parent fe056490
......@@ -32,7 +32,35 @@ abstract class AbstractPersistor implements PersistorInterface {
if (isset($this->options[self::CHILD_ENTITIES]) && is_array($this->options[self::CHILD_ENTITIES])) {
$controller = $this->getService()->getController();
foreach ($this->options[self::CHILD_ENTITIES] as $name => $entity) {
$data[$name] = $controller->getEntityManager()->find($entity, $data[$name]);
$setterParameter = 'entity';
if (is_array($entity)) {
$setterParameter = $entity['setterParameter'];
$entity = $entity['name'];
}
if ($setterParameter == 'array') {
// child entities have to be an array with one element to fit into ORM ArrayCollection;
// used for many to many-or-on the "many" side of one-to-many relations
if (is_array($data[$name])) {
$entities = array();
foreach ($data[$name] as $entityId) {
$entities[] = $controller->getEntityManager()->find($entity, $entityId);
}
$data[$name] = $entities;
} else {
$object = $controller->getEntityManager()->find($entity, $data[$name]);
$data[$name] = array($object);
}
}
if ($setterParameter == 'entity') {
// this is default behaviour
// used on the "one" side of a many-to-one or one-to-one relations
$object = $controller->getEntityManager()->find($entity, $data[$name]);
$data[$name] = $object;
}
}
}
}
......
......@@ -61,8 +61,6 @@ class RenderLink extends AbstractTableRenderHelper {
public function render() {
$column = $this->options['label'];
error_log($this->entity->id);
return sprintf('<a href="%s">%s</a>',
$this->getView()->url(
$this->options['route']['name'],
......
......@@ -10,12 +10,12 @@
}
?>
<div class="filter-element last">
<a class="btn pull-right remoteDialog" data-target="<?php
<a class="btn btn-primary pull-right remoteDialog" data-target="<?php
echo $this->url('admin/user', array(
'action' => 'edit',
'controller' => 'user',
));
?>" data-initializePlugin="AjaxForm"><span class="glyphicon glyphicon-user"></span> Neuer Benutzer</a>
?>" data-initializePlugin="AjaxForm"><span class="fa fa-user-plus fa-2x"></span></a>
</div>
</div>
<?php
......@@ -32,7 +32,7 @@
));
$helper->setActions(array(
'edit' => array(
'icon' => 'pencil',
'icon' => 'fa-pencil-square fa-2x',
'attribs' => array(
'class' => 'remoteDialog',
'data-target' => array(
......@@ -68,7 +68,7 @@
// 'controller' => 'user',
// ),
// ),
'icon' => 'trash',
'icon' => 'fa-user-times fa-2x',
'params' => array(
'id'
)
......
......@@ -25,12 +25,9 @@ return array(
'files/index',
'files/edit',
'files/save',
'dialog/newfile',
'dialog/newfolder',
'dialog/newuser',
'form/file',
'form/folder',
'form/user',
'json/searchuser',
'json/savefolderusers',
),
),
'admin' => array(
......
......@@ -13,6 +13,7 @@ use Application\Controller\ControllerAbstract;
use Zend\View\Model\ViewModel;
use Application\Form\FolderForm;
use Application\Form\ForgotPasswordForm;
use Application\Service\User;
class DialogController extends ControllerAbstract {
......@@ -25,25 +26,16 @@ class DialogController extends ControllerAbstract {
return $viewModel;
}
public function newfileAction() {
$viewModel = new ViewModel(array());
$viewModel->setTerminal(true);
return $viewModel;
}
public function newfolderAction() {
$form = new FolderForm();
public function newuserAction() {
$folderid = $this->getRequest()->getQuery('folder_id', false);
$service = new User($this->getServiceLocator());
$viewModel = new ViewModel(array(
'form' => $form,
'folderid' => $folderid,
'userlist' => $service->getFolderUsers($folderid),
'identity' => $this->getIdentity(),
));
$viewModel->setTerminal(true);
return $viewModel;
}
public function newuserAction() {
$viewModel = new ViewModel(array());
$viewModel->setTerminal(true);
return $viewModel;
}
}
......@@ -88,6 +88,25 @@ class FilesController extends ControllerAbstract {
return $plugin->saveEntity();
}
public function downloadAction() {
$file = $this->getEntityManager()->find('Application\Entity\File', $this->getRequest()->getQuery('id', false));
if ($file) {
$response = new \Zend\Http\Response\Stream();
$response->setStream(fopen($file->path, 'r'));
$response->setStatusCode(200);
$headers = new \Zend\Http\Headers();
$headers->addHeaderLine('Content-Type', $file->type)
->addHeaderLine('Content-Disposition', 'inline; filename="' . $file->name . '"')
->addHeaderLine('Content-Length', $file->size);
$response->setHeaders($headers);
return $response;
} else {
throw new FileNotFoundException(sprintf('"%s" not found', $filepath));
}
}
protected function getCrudOptions() {
$id = $this->getRequest()->getQuery('id', false);
......
......@@ -101,7 +101,10 @@ class FolderController extends ControllerAbstract {
return array(
Crud::ENTITY => 'Application\Entity\Folder',
Crud::CHILD_ENTITIES => array(
'users' => 'Application\Entity\User',
'users' => array(
'entity' => 'Application\Entity\User',
'setterParameter' => 'array',
),
),
Crud::ID_COLUMN => 'id',
Crud::FORM => new FolderForm($this->getServiceLocator(), $editMode, $this->getIdentity(), $this->getEntityManager()),
......
......@@ -14,6 +14,7 @@ namespace Application\Controller;
use Application\Controller\ControllerAbstract;
use Zend\Json\Json;
use Zend\View\Model\ViewModel;
use Application\Service\User;
class JsonController extends ControllerAbstract {
......@@ -106,54 +107,31 @@ class JsonController extends ControllerAbstract {
return $this->getResponse()->setContent(Json::encode($json));
}
public function foldersAction() {
$authService = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
$identity = $authService->getIdentity();
$user = $this->getEntityManager()->find('Application\Entity\User', $identity->id);
$data = array();
foreach ($user->folders as $folder) {
$data[] = array(
'id' => $folder->id,
'label' => $folder->label,
);
}
return $this->getResponse()->setContent(Json::encode($data));
}
public function filesAction() {
public function searchuserAction() {
$service = new User($this->getServiceLocator());
$json = array(
array(
'id' => '1',
'filename' => 'testfile.txt',
'filesize' => '123,58 kB',
'uploaded' => '12.12.2014 13:12',
),
array(
'id' => '2',
'filename' => 'testfile.txt',
'filesize' => '123,58 kB',
'uploaded' => '12.12.2014 13:13',
),
array(
'id' => '3',
'filename' => 'testfile.txt',
'filesize' => '123,58 kB',
'uploaded' => '12.12.2014 13:14',
),
array(
'id' => '4',
'filename' => 'testfile.txt',
'filesize' => '123,58 kB',
'uploaded' => '12.12.2014 13:15',
),
array(
'id' => '5',
'filename' => 'testfile.txt',
'filesize' => '123,58 kB',
'uploaded' => '12.12.2014 13:16',
),
'payload' => $this->getItems($service->getUsersByName($this->getRequest()->getPost('q', ''))),
'reqnr' => $this->getRequest()->getPost('reqnr', false),
);
return $this->getResponse()->setContent(Json::encode($json));
}
public function savefolderusersAction() {
$service = new User($this->getServiceLocator());
$service->saveFolderUsers($this->getRequest()->getPost('userlist', array()), $this->getRequest()->getPost('folderid', false));
return false;
}
protected function getItems($users) {
$html = '';
foreach ($users as $user) {
$html .= sprintf('<div class="item" data-userid="%s">%s</div>', $user->id, $user->email);
}
return $html;
}
}
......@@ -62,10 +62,6 @@ class File extends AbstractEntity {
**/
protected $folder;
public function setFolder(Folder $folder) {
$this->folder = $folder;
}
public function setCreated($timestamp) {
$this->created = new DateTime();
$this->created->setTimestamp($timestamp);
......
......@@ -62,16 +62,6 @@ class Folder extends AbstractEntity {
$this->expires->setTimestamp(strtotime($timestamp));
}
public function setUsers($users) {
if (!is_array($users)) {
$users = array($users);
}
foreach ($users as $user) {
$this->addUser($user);
}
}
public function addUser(\Application\Entity\User $user) {
$this->users[] = $user;
}
......
......@@ -62,6 +62,11 @@ class User extends AbstractEntity {
protected $created;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $createdviainvite = false;
/**
* @ORM\ManyToMany(targetEntity="Folder", mappedBy="users")
*/
protected $folders;
......@@ -91,42 +96,11 @@ class User extends AbstractEntity {
$this->created->setTimestamp($timestamp);
}
public function setData($data, $folders = array()) {
$data['folders'] = array();
// map folder checkboxes to storages many to many relationship
foreach ($folders as $folder) {
if ($data['folders'.$folder->id] == 1) {
$data['folders'][] = $folder->id;
}
}
parent::setData($data);
}
public function setFolders($folders) {
$this->addFolders($folders);
}
public function addFolders(array $folders) {
$em = $this->getService()->getEntityManager();
// remove all previously added storages
$this->folders = null;
$em->persist($this);
foreach ($folders as $folder) {
if (is_numeric($folder)) {
$entity = $em->find('Application\Entity\Folder', $folder);
$this->addFolder($entity);
} else {
$this->addFolder($folder);
}
}
public function setCreatedviainvite($bool) {
$this->createdviainvite = $bool;
}
public function addFolder(\Application\Entity\Folder $folder) {
$this->folders[] = $folder;
$folder->addUser($this);
}
}
<?php
namespace Application;
use RuntimeException;
class FileNotFoundException extends RuntimeException {
}
......@@ -29,12 +29,7 @@ class UserRepository extends PaginationFilterSortRepository
*/
public function getRepositoryPage()
{
$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();
$qb->select('u')
->from('\Application\Entity\User', 'u');
$qb = $this->getSelect();
$this->addFilter($qb, $this->params['filter']['email']);
$this->sort($qb, $this->params['sort']);
......@@ -47,6 +42,23 @@ class UserRepository extends PaginationFilterSortRepository
return $paginator;
}
public function findByEmail($email) {
$qb = $this->getSelect();
$this->addFilter($qb, $email);
$query = $qb->getQuery();
return $query->getResult();
}
protected function getSelect() {
$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();
$qb->select('u')
->from('\Application\Entity\User', 'u');
return $qb;
}
protected function addFilter($qb, $filter_email) {
if ($filter_email != false) {
$qb->andWhere('u.email LIKE :email')
......
<?php
namespace Application\Service;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
abstract class AbstractService {
protected $serviceLocator = null;
protected $entityManager = null;
/**
* The constructor
*
* @return void
*/
public function __construct(ServiceLocatorInterface $serviceLocator = null) {
if (null !== $serviceLocator) {
$this->setServiceLocator($serviceLocator);
}
}
public function getServiceLocator() {
return $this->serviceLocator;
}
public function setServiceLocator(ServiceLocatorInterface $serviceLocator) {
$this->serviceLocator = $serviceLocator;
}
public function getEntityManager() {
if (null === $this->entityManager) {
$this->entityManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
}
return $this->entityManager;
}
}
<?php
namespace Application\Service;
class Password {
protected $characters = 'abcdefghijklmnopqrstuvwxyz987654321!?/-_$(){}[]';
public function generate($length = 8) {
$password = '';
for ($i = 0; $i < $length; $i++) {
$rand = rand(0, strlen($this->characters));
$password .= substr($this->characters, $rand, 1);
}
return $password;
}
}
<?php
namespace Application\Service;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class Path {
protected $serviceLocator = null;
/**
* The constructor
*
* @return void
*/
public function __construct(ServiceLocatorInterface $serviceLocator = null) {
if (null !== $serviceLocator) {
$this->setServiceLocator($serviceLocator);
}
}
class Path extends AbstractService {
public function filePath($foldername = '', $filename = '') {
$serviceManager = $this->getServiceLocator();
......@@ -29,14 +14,4 @@ class Path {
return $path;
}
public function getServiceLocator() {
return $this->serviceLocator;
}
public function setServiceLocator(ServiceLocatorInterface $serviceLocator) {
$this->serviceLocator = $serviceLocator;
}
}
<?php
namespace Application\Service;
use Application\Entity\User as UserEntity;
class User extends AbstractService {
public function getFolderUsers($folderid) {
$folder = $this->getEntityManager()->find('Application\Entity\Folder', $folderid);
return $folder->users;
}
public function getUsersByName($searchTerm) {
return $this->getEntityManager()->getRepository('Application\Entity\User')->findByEmail($searchTerm);
}
public function saveFolderUsers($userlist, $folderId) {
$folder = $this->getEntityManager()->find('Application\Entity\Folder', $folderId);
// remove all previously added storages
$folder->users = null;
$this->getEntityManager()->persist($folder);
foreach ($userlist as $userid => $value) {
$user = $this->getEntityManager()->find('Application\Entity\User', $userid);
if (!is_numeric($userid)) {
$user = new UserEntity();
$service = new Password();
$user->setData(array(
'email' => $userid,
'password' => $service->generate(),
'isadmin' => false,
'caninvite' => false,
'cancreatefolders' => false,
'canuploadfiles' => false,
'created' => time(),
'createdviainvite' => true
));
$this->getEntityManager()->persist($user);
$userid = $user->id;
$value = $user->id;
}
if ($user && $userid == $value) {
$folder->addUser($user);
}
}
$this->getEntityManager()->persist($folder);
$this->getEntityManager()->flush();
}
}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel"><?php echo $this->translate('Upload file'); ?></h4>
</div>
<form method="post" action="<?php echo $this->url('application/default', array('controller' => 'form', 'action' => 'file')); ?>">
<div class="modal-body">
<input id="input-id" type="file" class="file" data-preview-file-type="text">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $this->translate('cancel'); ?></button>
<button type="submit" class="btn btn-primary" data-submitmode="ajax"><?php echo $this->translate('save'); ?></button>
</div>
</form>
\ No newline at end of file
......@@ -5,38 +5,44 @@
</div>
<div class="mod modUserNew" >
<div class="inner background-white">
<form method="post" action="<?php echo $this->url('application/default', array('controller' => 'form', 'action' => 'user')); ?>">
<div class="modal-body">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="email" class="form-control" placeholder="<?php echo $this->translate('Email'); ?>" id="targetEmail" aria-describedby="basic-addon1">
</div>
<div class="modal-footer" >
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $this->translate('cancel'); ?></button>
<button type="submit" class="btn btn-primary" data-submitmode="ajax"><?php echo $this->translate('save'); ?></button>
</div>
<div STYLE=" height: 300px; font-size: 12px; overflow: auto; text-align:left;">
<table class="table table-striped" >
<thead>
<tr><th>Email</th><th>Hinzugefügt am </th></tr>
</thead>
<tbody>
<tr><td>FolderName 1</td><td>12.12.2015 11:34</td>
<tr><td>2 1</td><td>12.12.2015 11:34</td><i class="fa fa-user-plus"></i>
<tr><td>3 1</td><td>12.12.2015 11:34</td><i class="fa fa-user-plus"></i>
<tr><td>5 1</td><td>12.12.2015 11:34</td>
<tr><td>6 1</td><td>12.12.2015 11:34</td>
<tr><td>643 1</td><td>12.12.2015 11:34</td>
<tr><td>3654 1</td><td>12.12.2015 11:34</td>
<tr><td>346546 1</td><td>12.12.2015 11:34</td>
</tbody>
<input type="text" class="form-control" placeholder="<?php echo $this->translate('Email'); ?>" id="targetEmail" aria-describedby="basic-addon1">
</div>
<div class="dropdown-flyout">
<div class="inner">
<div class="dropdown-content"></div>
</div>
</div>
<table class="table table-striped userlist" data-folderid="<?php echo $this->folderid; ?>">
<thead>
<tr><th>Email</th><th>&nbsp;</th><th>&nbsp;</th></tr>
</thead>
<tbody>
<?php
foreach ($this->userlist as $user) {
if ($user->id == $this->identity->id) {
echo sprintf('<tr><td data-userid="%s">%s</td><td>&nbsp;</td><td>&nbsp;</td></tr>',
$user->id,
$user->email
);
} else {
echo sprintf('<tr><td>%s</td><td>&nbsp;</td><td><a href="#" data-userid="%s" class="removeUser"><i class="fa fa-user-times"></i></a></td></tr>',
$user->email,
$user->id
);
}
}
?>
</tbody>
</table>
</div>
<div class="modal-footer" >
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $this->translate('cancel'); ?></button>
<button type="button" class="btn btn-primary submitButton"><?php echo $this->translate('save'); ?></button>
</div>
</form>
</div>
</div>
\ No newline at end of file
......@@ -17,7 +17,7 @@
'controller' => 'folder',
), array(
));
?>" title="back"><i class="glyphicon glyphicon-arrow-left"></i></a>
?>" title="back"><i class="fa fa-arrow-left fa-2x"></i></a>
<?php if ($this->identity->canuploadfiles) { ?>
<a class="btn btn-primary remoteDialog" data-target="<?php
......@@ -27,7 +27,9 @@
), array(
'query' => $this->params
));
?>" title="Neue Datei" data-initializemodule="File"><i class="glyphicon glyphicon-open-file"></i></a>
?>" title="Neue Datei" data-initializemodule="File">
<i class="fa fa-cloud-upload fa-2x"></i>
</a>
<?php }
if ($this->identity->caninvite) {
?>
......@@ -35,8 +37,10 @@
echo $this->url('application/default', array(
'action' => 'newuser',
'controller' => 'dialog',
), array(
'query' => $this->params
));
?>" title="New User" data-initializemodule="UserNew"><i class="fa fa-user-plus"></i></a>
?>" title="New User" data-initializemodule="UserNew"><i class="fa fa-user-plus fa-2x"></i></a>
<?php
}
?>
......@@ -71,7 +75,7 @@
'action' => 'download',
),
),
'icon' => 'fa-download',
'icon' => 'fa-cloud-download fa-2x',
//'label' => 'download',
'params' => array(
'id'
......@@ -99,7 +103,7 @@
// 'controller' => 'user',
// ),
// ),
'icon' => 'trash',
'icon' => 'fa-times-circle fa-2x',
'params' => array(
'id' => 'id',
'folder_id' => 'folder->id'
......
......@@ -19,10 +19,7 @@
));
?>" title="Neuer Ordner" data-initializemodule="FolderForm">
<!-- <i class="fa fa-plus-circle fa-2x"></i> -->
<span class="fa-stack fa-lg icon-add">
<i class="fa fa-folder-o fa-stack-2x"></i>
<i class="fa fa-plus-circle fa-stack-1x"></i>
</span>
<i class="fa fa-cloud fa-2x"></i>
</a>
</div>
<?php } ?>
......@@ -75,7 +72,7 @@
'action' => 'index',
),
),
'icon' => 'fa-folder-open',
'icon' => 'fa-folder-open fa-2x',
//'label' => 'open',
'params' => array(
'folder_id' => 'id'
......@@ -103,7 +100,7 @@
// 'controller' => 'user',
// ),
// ),
'icon' => 'trash',
'icon' => 'fa-times-circle fa-2x',
'params' => array(
'id'
));
......
......@@ -9868,6 +9868,9 @@ embed {
.modCrud .sortable {
cursor: pointer;
}