Skip to content

Commit

Permalink
Vladislav Antov
Browse files Browse the repository at this point in the history
  • Loading branch information
wingman007 committed Jun 12, 2013
1 parent dc57c5f commit c43fdff
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 1 deletion.
8 changes: 8 additions & 0 deletions module/Application/view/application/index/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,12 @@ $this->headLink(array(
</p>
</div>

<div class="hero-unit fmi">
<h2>Vladislav Antov</h2>
<p>
<a class="btn btn-success" href="<?php echo $this->url('fmi/default', array('controller'=> 'vladislav-antov', 'action' => 'index'), true); ?>" target="_blank"><?php echo $this->translate('Vladislav Antov') ?> &raquo;</a>
</p>
</div>


<hr style="clear: both;"/>
3 changes: 2 additions & 1 deletion module/Fmi/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
'Fmi\Controller\DenisGeorgiev' => 'Fmi\Controller\DenisGeorgievController',
'Fmi\Controller\CvetomirStoqnov' => 'Fmi\Controller\CvetomirStoqnovController',
'Fmi\Controller\CankoGrozev' => 'Fmi\Controller\CankoGrozevController',
'Fmi\Controller\StoyanRevov' => 'Fmi\Controller\StoyanRevovController',
'Fmi\Controller\StoyanRevov' => 'Fmi\Controller\StoyanRevovController',
'Fmi\Controller\VladislavAntov' => 'Fmi\Controller\VladislavAntovController',
),
),
// !!! SUPER important use fmi/default grace-drops/<segment>in url helper
Expand Down
200 changes: 200 additions & 0 deletions module/Fmi/src/Fmi/Controller/VladislavAntovController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Fmi\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

use Zend\Form\Annotation\AnnotationBuilder;

use Zend\Form\Element;

// hydration tests
use Zend\Stdlib\Hydrator;

// for Doctrine annotation
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use DoctrineORMModule\Stdlib\Hydrator\DoctrineEntity;
use DoctrineORMModule\Form\Annotation\AnnotationBuilder as DoctrineAnnotationBuilder;

use Fmi\Entity\User;

class VladislavAntovController extends AbstractActionController
{
public function indexAction()
{
$entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
// $dql = "SELECT b, e, r FROM Bug b JOIN b.engineer e JOIN b.reporter r ORDER BY b.created DESC";
$dql = "SELECT u FROM Fmi\Entity\User u";

$query = $entityManager->createQuery($dql);
$query->setMaxResults(30);
$users = $query->getResult();

return new ViewModel(array('users' => $users));
}

public function addAction()
{
// 1) Crete the form
// $form = new AlbumForm();
// $form->get('submit')->setValue('Add');
// 1.2) with annotations

$entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
$user = new User;
$builder = new DoctrineAnnotationBuilder($entityManager);
$form = $builder->createForm( $user );
$form->setHydrator(new DoctrineHydrator($entityManager,'Fmi\Entity\User'));
// it works both ways. With the above line. and the line bellow
//- $form->setHydrator(new DoctrineEntity($entityManager, 'Fmi\Entity\User'));
$send = new Element('send');
$send->setValue('Add'); // submit
$send->setAttributes(array(
'type' => 'submit'
));
$form->add($send);

// 2) bind the entity
$form->bind($user);

// do the logic
$request = $this->getRequest();
if ($request->isPost()) {
// $album = new Album();
// $form->setInputFilter($album->getInputFilter());
$form->setData($request->getPost());

if ($form->isValid()) { // if it is valid hets populated
// $album->exchangeArray($form->getData());
// $this->getAlbumTable()->saveAlbum($album);

// NOW I will need the em

$entityManager->persist($user);
$entityManager->flush();

// Redirect to list of albums
return $this->redirect()->toRoute('fmi');
}
}
return array('form' => $form);
}

public function editAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('fmi', array(
'action' => 'add'
));
}

// Get the Album with the specified id. An exception is thrown
// if it cannot be found, in which case go to the index page.
$entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
try {
// $album = $this->getAlbumTable()->getAlbum($id);
$repository = $entityManager->getRepository('Fmi\Entity\User');
// $id = (int)$this->params()->fromQuery('id', 1);
$user = $repository->find($id);
}
catch (\Exception $ex) {
return $this->redirect()->toRoute('fmi', array(
'action' => 'index'
));
}

// Create the form
// 2.2)
// $form = new AlbumForm();
// $form->get('submit')->setAttribute('value', 'Edit');
// 2.2)
$builder = new DoctrineAnnotationBuilder($entityManager);
$form = $builder->createForm( $user );
$form->setHydrator(new DoctrineHydrator($entityManager,'Fmi\Entity\User'));
// it works both ways. With the above line. and the line bellow
//- $form->setHydrator(new DoctrineEntity($entityManager, 'Fmi\Entity\User'));
$send = new Element('send');
$send->setValue('Edit'); // submit
$send->setAttributes(array(
'type' => 'submit'
));
$form->add($send);

// 3) bind
$form->bind($user);

$request = $this->getRequest();
if ($request->isPost()) {
// $form->setInputFilter($album->getInputFilter());
$form->setData($request->getPost());

if ($form->isValid()) {
// $this->getAlbumTable()->saveAlbum($form->getData());

$entityManager->persist($user);
$entityManager->flush();

// Redirect to list of albums
return $this->redirect()->toRoute('fmi');
}
}

return array(
'id' => $id,
'form' => $form,
);
}

public function deleteAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('fmi');
}

$entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
try {
// $album = $this->getAlbumTable()->getAlbum($id);
$repository = $entityManager->getRepository('Fmi\Entity\User');
// $product = $entityManager->getRepository('Product')->findOneBy(array('name' => $productName));
// $id = (int)$this->params()->fromQuery('id', 1);
$user = $repository->find($id);
// or $user = $entityManager->find("Fmi\Entity\User", (int)$id);
}
catch (\Exception $ex) {
return $this->redirect()->toRoute('fmi', array(
'action' => 'index'
));
}

$request = $this->getRequest();
if ($request->isPost()) {
$del = $request->getPost('del', 'No');

if ($del == 'Yes') {
$id = (int) $request->getPost('id');
// $this->getAlbumTable()->deleteAlbum($id);
$user = $repository->find($id);
$entityManager->remove($user);
$entityManager->flush();
}

// Redirect to list of albums
return $this->redirect()->toRoute('fmi');
}

return array(
'id' => $id,
'user' => $user, // $this->getAlbumTable()->getAlbum($id)
);
}
}
12 changes: 12 additions & 0 deletions module/Fmi/view/fmi/vladislav-antov/add.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
echo '<h1>I am in add.phtml GraceDrops Controller</h1>';
$form = $this->form;
$form->prepare();
// Assuming the "contact/process" route exists...
$form->setAttribute('action', $this->url('fmi/default', array('controller' => 'Index', 'action' => 'add'))); //'contact/process'));
// Set the method attribute for the form
$form->setAttribute('method', 'post');

echo $this->form()->openTag($form);
echo $this->formCollection($form);
echo $this->form()->closeTag();
27 changes: 27 additions & 0 deletions module/Fmi/view/fmi/vladislav-antov/delete.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
echo '<h1>I am in delete.phtml GraceDrops Controller</h1>';

// module/Album/view/album/album/delete.phtml:

$title = 'Delete user';
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title); ?></h1>

<p>Are you sure that you want to delete
'<?php echo $this->escapeHtml($user->getUsrName()); ?>' by
'<?php echo $this->escapeHtml($user->getUsrPassword()); ?>'?
</p>
<?php
$url = $this->url('fmi/default', array(
'action' => 'delete',
'id' => $this->id,
));
?>
<form action="<?php echo $url; ?>" method="post">
<div>
<input type="hidden" name="id" value="<?php echo (int) $user->getUsrId(); ?>" />
<input type="submit" name="del" value="Yes" />
<input type="submit" name="del" value="No" />
</div>
</form>
13 changes: 13 additions & 0 deletions module/Fmi/view/fmi/vladislav-antov/edit.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
echo '<h1>I am in edit.phtml GraceDrops Controller</h1>';

$form = $this->form;
$form->prepare();
// Assuming the "contact/process" route exists...
$form->setAttribute('action', $this->url('fmi/default', array('controller' => 'Index', 'action' => 'edit', 'id' => $this->id))); //'contact/process'));
// Set the method attribute for the form
$form->setAttribute('method', 'post');

echo $this->form()->openTag($form);
echo $this->formCollection($form);
echo $this->form()->closeTag();
40 changes: 40 additions & 0 deletions module/Fmi/view/fmi/vladislav-antov/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
echo '<h1>I am in index.phtml GraceDrops Controller</h1>';
/*
foreach($users AS $user) {
echo $user->getDescription()." - ".$user->getCreated()->format('d.m.Y')."\n";
echo " Reported by: ".$user->getReporter()->name."\n";
echo " Assigned to: ".$user->getEngineer()->name."\n";
foreach($user->getProducts() AS $product) {
echo " Platform: ".$product->name."\n";
}
echo "\n";
}
*/
$title = 'My users';
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title); ?></h1>
<p>
<a href="<?php echo $this->url('fmi/default', array('controller' => 'index', 'action'=>'add'));?>">Add new user</a>
</p>

<table class="table">
<tr>
<th>Name</th>
<th>Password</th>
<th>&nbsp;</th>
</tr>
<?php foreach ($users as $user) : ?>
<tr>
<td><?php echo $this->escapeHtml($user->getUsrName());?></td>
<td><?php echo $this->escapeHtml($user->getUsrPassword());?></td>
<td>
<a href="<?php echo $this->url('fmi/default', // SUPER IMPORTANT use grace-drops/<segment> NOT ONLY grace-drops
array('controller' => 'index', 'action'=>'edit', 'id' => $user->getUsrId()));?>">Edit</a>
<a href="<?php echo $this->url('fmi/default', // SUPER IMPORTANT use grace-drops/<segment>
array('controller' => 'index', 'action'=>'delete', 'id' => $user->getUsrId()));?>">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>

0 comments on commit c43fdff

Please sign in to comment.