forked from wingman007/fmi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc57c5f
commit c43fdff
Showing
7 changed files
with
302 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
200 changes: 200 additions & 0 deletions
200
module/Fmi/src/Fmi/Controller/VladislavAntovController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> </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> |