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+ }
0 commit comments