Skip to content

Commit bfc145f

Browse files
波波
authored andcommitted
sql
1 parent b79e8fa commit bfc145f

File tree

23 files changed

+804
-0
lines changed

23 files changed

+804
-0
lines changed

module/Party/LICENSE.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2005-2012, Zend Technologies USA, Inc.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
* Neither the name of Zend Technologies USA, Inc. nor the names of its
15+
contributors may be used to endorse or promote products derived from this
16+
software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

module/Party/Module.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/Party for the canonical source repository
6+
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace Party;
11+
12+
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
13+
use Zend\Mvc\ModuleRouteListener;
14+
use Zend\Mvc\MvcEvent;
15+
use Party\Model\Party;
16+
use Party\Model\PartyTable;
17+
use Zend\Db\ResultSet\ResultSet;
18+
use Zend\Db\TableGateway\TableGateway;
19+
20+
class Module implements AutoloaderProviderInterface
21+
{
22+
public function getAutoloaderConfig()
23+
{
24+
return array(
25+
'Zend\Loader\ClassMapAutoloader' => array(
26+
__DIR__ . '/autoload_classmap.php',
27+
),
28+
'Zend\Loader\StandardAutoloader' => array(
29+
'namespaces' => array(
30+
// if we're in a namespace deeper than one level we need to fix the \ in the path
31+
__NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
32+
),
33+
),
34+
);
35+
}
36+
37+
public function getConfig()
38+
{
39+
return include __DIR__ . '/config/module.config.php';
40+
}
41+
42+
public function onBootstrap(MvcEvent $e)
43+
{
44+
// You may not need to do this if you're doing it elsewhere in your
45+
// application
46+
$eventManager = $e->getApplication()->getEventManager();
47+
$moduleRouteListener = new ModuleRouteListener();
48+
$moduleRouteListener->attach($eventManager);
49+
}
50+
51+
public function getServiceConfig()
52+
{
53+
return array(
54+
'factories' => array(
55+
'Party\Model\Party' => function($sm){
56+
$tableGateway = $sm->get('PartyTableGateway');
57+
$table = new Party($tableGateway);
58+
return $table;
59+
},
60+
'PartyTableGateway' => function ($sm) {
61+
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
62+
$resultSetPrototype = new ResultSet();
63+
$resultSetPrototype->setArrayObjectPrototype(new PartyTable());
64+
return new TableGateway('Collect_info', $dbAdapter, null, $resultSetPrototype);
65+
},
66+
),
67+
);
68+
}
69+
}

module/Party/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sample, skeleton module for use with the ZF2 MVC layer.

module/Party/autoload_classmap.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
// Generated by ZF2's ./bin/classmap_generator.php
3+
return array(
4+
'Party\Module' => __DIR__ . '/Module.php',
5+
'Party\Controller\PartyController' => __DIR__ . '/src/Party/Controller/PartyController.php',
6+
'PartyTest\Framework\TestCase' => __DIR__ . '/tests/Party/Framework/TestCase.php',
7+
'PartyTest\SampleTest' => __DIR__ . '/tests/Party/SampleTest.php',
8+
);

module/Party/autoload_function.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
return function ($class) {
3+
static $map;
4+
if (!$map) {
5+
$map = include __DIR__ . '/autoload_classmap.php';
6+
}
7+
8+
if (!isset($map[$class])) {
9+
return false;
10+
}
11+
return include $map[$class];
12+
};

module/Party/autoload_register.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
spl_autoload_register(include __DIR__ . '/autoload_function.php');
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
return array(
3+
'controllers' => array(
4+
'invokables' => array(
5+
'Party\Controller\Party' => 'Party\Controller\PartyController',
6+
),
7+
),
8+
'router' => array(
9+
'routes' => array(
10+
'Party' => array(
11+
'type' => 'Segment',
12+
'options' => array(
13+
// Change this to something specific to your module
14+
'route' => '/Party[/:action][/:id]',
15+
'constraints' => array(
16+
//'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
17+
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
18+
'id' =>'[0-9]+', ),
19+
'defaults' => array(
20+
// Change this value to reflect the namespace in which
21+
// the controllers for your module are found
22+
'__NAMESPACE__' => 'Party\Controller',
23+
'controller' => 'Party',
24+
'action' => 'index',
25+
),
26+
),
27+
'may_terminate' => true,
28+
/** 'child_routes' => array(
29+
// This route is a sane default when developing a module;
30+
// as you solidify the routes for your module, however,
31+
// you may want to remove it and replace it with more
32+
// specific routes.
33+
'default' => array(
34+
'type' => 'Segment',
35+
'options' => array(
36+
'route' => '[/:action][/:id]',
37+
'constraints' => array(
38+
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
39+
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
40+
'id' =>'[0-9]+',
41+
),
42+
'defaults' => array(
43+
),
44+
),
45+
),
46+
),**/
47+
),
48+
),
49+
),
50+
'view_manager' => array(
51+
'template_path_stack' => array(
52+
'Party' => __DIR__ . '/../view',
53+
),
54+
),
55+
);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/Party for the canonical source repository
6+
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace Party\Controller;
11+
12+
use Zend\Mvc\Controller\AbstractActionController;
13+
use Zend\View\Model\ViewModel ;
14+
15+
class PartyController extends AbstractActionController
16+
{
17+
protected $Party;
18+
19+
public function indexAction()
20+
{
21+
return new ViewModel(array('Party' => $this->getPartyTable()->fetchAll(),
22+
));
23+
}
24+
25+
public function addAction()
26+
{
27+
return array();
28+
}
29+
30+
31+
public function fooAction()
32+
{
33+
// This shows the :controller and :action parameters in default route
34+
// are working when you browse to /party/party/foo
35+
return array();
36+
}
37+
38+
public function getPartyTable()
39+
{
40+
if (!$this->Party) {
41+
$sm = $this->getServiceLocator();
42+
$this->Party = $sm->get('Party\Model\Party');
43+
}
44+
return $this->Party;
45+
46+
}
47+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
namespace Party\Model;
3+
4+
use Zend\Db\TableGateway\TableGateway;
5+
6+
class Party
7+
{
8+
protected $tableGateway;
9+
10+
public function __construct(TableGateway $tableGateway)
11+
{
12+
$this->tableGateway = $tableGateway;
13+
14+
}
15+
16+
public function fetchAll()
17+
{
18+
$resultSet = $this->tableGateway->select();
19+
return $resultSet;
20+
}
21+
22+
public function getParty($id)
23+
{
24+
$id = (int) $id;
25+
$rowset = $this->tableGateway->select(array('id' => $id));
26+
$row = $rowset->current();
27+
if (!$row) {
28+
throw new \Exception("Could not find row $id");
29+
}
30+
}
31+
32+
public function saveParty(PartyTable $PartyTable)
33+
{
34+
$data = array(
35+
user_name =>$PartyTable->user_name,
36+
user_phone =>$PartyTable->user_phone,
37+
user_qq =>$PartyTable->user_qq,
38+
user_call =>$PartyTable->user_call,
39+
user_email =>$PartyTable->user_email,
40+
user_province =>$PartyTable->user_province,
41+
user_city =>$PartyTable->user_city,
42+
user_group =>$PartyTable->user_group,
43+
freetime_begin =>$PartyTable->freetime_begin,
44+
freetime_end =>$PartyTable->freetime_end,
45+
content =>$PartyTable->content,
46+
submit_time =>$PartyTable->submit_ip,
47+
submit_ip =>$PartyTable->submit_time,
48+
);
49+
$id = (int)$PartyTable->id;
50+
if ($id == 0) {
51+
$this->tableGateway->insert($data);
52+
}else {
53+
if ($this->getParty($id)) {
54+
$this->tableGateway->update($data, array('id' => $id));
55+
} else {
56+
throw new \Exception('Form id does not exist');
57+
}
58+
}
59+
}
60+
61+
public function deleteParty($id)
62+
{
63+
$this->tableGateway->delete(array('id' => $id));
64+
}
65+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
namespace Party\Model;
3+
4+
class PartyTable
5+
{
6+
public $id ;
7+
public $user_name ;
8+
public $user_phone ;
9+
public $user_qq ;
10+
public $user_call ;
11+
public $user_email ;
12+
public $user_province ;
13+
public $user_city ;
14+
public $user_group ;
15+
public $freetime_begin ;
16+
public $freetime_end ;
17+
public $content ;
18+
public $submit_time ;
19+
public $submit_ip ;
20+
protected $inputFilter;
21+
22+
public function exchangeArray($data)
23+
{
24+
$this->id = (!empty($data['id'])) ? $data['id'] : null;
25+
$this->user_name = (!empty($data['user_name'])) ? $data['user_name'] : null;
26+
$this->user_phone = (!empty($data['user_phone'])) ? $data['user_phone'] : null;
27+
$this->user_call = (!empty($data['user_call'])) ? $data['user_call'] : null;
28+
$this->user_email = (!empty($data['user_email'])) ? $data['user_email'] : null;
29+
$this->user_province = (!empty($data['user_province'])) ? $data['user_province'] : null;
30+
$this->user_city = (!empty($data['user_city'])) ? $data['user_city'] : null;
31+
$this->user_group = (!empty($data['user_group'])) ? $data['user_group'] : null;
32+
$this->freetime_begin = (!empty($data['freetime_begin'])) ? $data['freetime_begin'] : null;
33+
$this->freetime_end = (!empty($data['freetime_end'])) ? $data['freetime_end'] : null;
34+
$this->content = (!empty($data['content'])) ? $data['content'] : null;
35+
$this->submit_time = (!empty($data['submit_time'])) ? $data['submit_time'] : null;
36+
$this->submit_ip = (!empty($data['submit_ip'])) ? $data['submit_ip'] : null;
37+
38+
}
39+
}

0 commit comments

Comments
 (0)