Skip to content

Commit

Permalink
1. Meeting
Browse files Browse the repository at this point in the history
2. School
  • Loading branch information
nazargulov committed May 14, 2014
1 parent 557addd commit 8558a10
Show file tree
Hide file tree
Showing 45 changed files with 2,027 additions and 222 deletions.
579 changes: 368 additions & 211 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions config/application.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'User',
'Secret',
'Meeting',
'School',
),

// These are various options for the listeners attached to the ModuleManager
Expand Down
2 changes: 2 additions & 0 deletions module/Application/view/layout/layout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<ul class="nav navbar-nav">
<li class="active"><a href="<?php echo $this->url('home') ?>"><?php echo $this->translate('Home') ?></a></li>
<li><a href="<?= $this->url('zfcuser'); ?>"><?= $this->translate('Log in'); ?></a></li>
<li><a href="<?= $this->url('meeting'); ?>"><?= $this->translate('Meeting'); ?></a></li>
<li><a href="<?= $this->url('school'); ?>"><?= $this->translate('School'); ?></a></li>
<li><a href="<?= $this->url('secret'); ?>"><?= $this->translate('Secret'); ?></a></li>
</ul>
</div><!--/.nav-collapse -->
Expand Down
5 changes: 5 additions & 0 deletions module/Meeting/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.buildpath
.project
.settings/
.DS_Store
vendor
27 changes: 27 additions & 0 deletions module/Meeting/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2005-2014, Zend Technologies USA, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of Zend Technologies USA, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 changes: 46 additions & 0 deletions module/Meeting/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/Meeting for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Meeting;

use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;

class Module implements AutoloaderProviderInterface
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
// if we're in a namespace deeper than one level we need to fix the \ in the path
__NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
),
),
);
}

public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}

public function onBootstrap(MvcEvent $e)
{
// You may not need to do this if you're doing it elsewhere in your
// application
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
}
1 change: 1 addition & 0 deletions module/Meeting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample, meeting module for use with the ZF2 MVC layer.
8 changes: 8 additions & 0 deletions module/Meeting/autoload_classmap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'Meeting\Module' => __DIR__ . '/Module.php',
'Meeting\Controller\Main' => __DIR__ . '/src/Meeting/Controller/Main.php',
'MeetingTest\Framework\TestCase' => __DIR__ . '/tests/Meeting/Framework/TestCase.php',
'MeetingTest\SampleTest' => __DIR__ . '/tests/Meeting/SampleTest.php',
);
12 changes: 12 additions & 0 deletions module/Meeting/autoload_function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
return function ($class) {
static $map;
if (!$map) {
$map = include __DIR__ . '/autoload_classmap.php';
}

if (!isset($map[$class])) {
return false;
}
return include $map[$class];
};
2 changes: 2 additions & 0 deletions module/Meeting/autoload_register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
spl_autoload_register(include __DIR__ . '/autoload_function.php');
64 changes: 64 additions & 0 deletions module/Meeting/config/module.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
return array(
'controllers' => array(
'invokables' => array(
'Meeting\Controller\Main' => 'Meeting\Controller\Main',
),
),
'router' => array(
'routes' => array(
'meeting' => array(
'type' => 'Literal',
'options' => array(
// Change this to something specific to your module
'route' => '/meeting',
'defaults' => array(
// Change this value to reflect the namespace in which
// the controllers for your module are found
'__NAMESPACE__' => 'Meeting\Controller',
'controller' => 'Main',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// This route is a sane default when developing a module;
// as you solidify the routes for your module, however,
// you may want to remove it and replace it with more
// specific routes.
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action][/:id]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'Meeting' => __DIR__ . '/../view',
),
),
'doctrine' => array(
'driver' => array(
'meeting_entity' => array(
'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Meeting/Entity')
),

'orm_default' => array(
'drivers' => array(
'Meeting\Entity' => 'meeting_entity'
)
))),
);
123 changes: 123 additions & 0 deletions module/Meeting/src/Meeting/Controller/Main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/Meeting for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Meeting\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Meeting\Entity\Meeting;
use User\Entity\Student;
use School\Entity\School;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Doctrine\ORM;
use Meeting\Form\MeetingForm;

class Main extends AbstractActionController
{
/**
* @var Doctrine\ORM\EntityManager
*/
protected $em;

/**
* @var ZfcUserAuthService
*/
protected $_auth;

public function indexAction()
{
$userId = 0;
$auth = $this->getAuth();
if (!empty($auth) && $auth->hasIdentity()) {
$userId = $auth->getIdentity()->getId();
}

$meetingId = (int) $this->params()->fromRoute("id", 0);
$mode = "edit";
$leading = null;
$organizer = null;
$meeting = $this->getEntityManager()->find('Meeting\Entity\Meeting', $meetingId);
if (!$meeting instanceof Meeting) {
$meeting = new Meeting();
$leading = new Student();
$organizer = new School();
$mode = "add";
} else {
$leading = $this->getEntityManager()->find('User\Entity\Student', $meeting->getLeadingId());
$organizer = $this->getEntityManager()->find('School\Entity\School', $meeting->getSchoolId());
}

$readonly = ($userId == $organizer->getUserId());
$form = new MeetingForm($this->getEntityManager(), $readonly);
$hydrator = new DoctrineHydrator($this->getEntityManager(), get_class($meeting));
$form->setHydrator($hydrator);

//bind object to form
$form->bind($meeting);
$form->get('id')->setValue($meetingId);
if ($mode == "add") {
$form->get('submit')->setValue('Add');
} else {
if (!empty($leading))
$form->get('leading')->setValue($leading->getName());
if (!empty($organizer))
$form->get('school')->setValue($organizer->getName());
$form->get('timeStart')->setValue($meeting->getTimeStart()->format('d.m.y h:m'));
$form->get('timeStop')->setValue($meeting->getTimeStop()->format('d.m.y h:m'));
$form->get('submit')->setAttribute('value', 'Save');
}

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

if ($form->isValid()) {
if ($mode == "add") {
$this->getEntityManager()->persist($meeting);
$msg = 'Add new meeting';
} else {
$msg = 'Edit meeting';
}
$this->getEntityManager()->flush();
$this->FlashMessenger()->setNamespace(\Zend\Mvc\Controller\Plugin\FlashMessenger::NAMESPACE_INFO);
// Redirect to list of albums
return $this->redirect()->toRoute('meeting/default', array('controller' => 'main', 'action' => 'index', 'id' => $meetingId));
}
}
return array('form' => $form);
}

public function fooAction()
{
// This shows the :controller and :action parameters in default route
// are working when you browse to /module-specific-root/main/foo
return array();
}

/**
* @return array|object|Doctrine\ORM\EntityManager
*/
public function getEntityManager()
{
if (null == $this->em) {
$this->em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
}
return $this->em;
}

/**
* @return array|object|ZfcUserAuthService
*/
public function getAuth() {
if (!$this->_auth) {
$this->_auth = $this->zfcUserAuthentication();
}
return $this->_auth;
}

}
Loading

0 comments on commit 8558a10

Please sign in to comment.