intro
Zend_Gdata_Spreadsheetsを用いてGoogleスプレッドシートをデータストアとして利用する追加/更新/削除/閲覧コントローラを作成します。
1.コントローラの作成
以下のように
library/My/Controller/GSheets.php
ファイルを作成します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'My/Controller/Simple.php'</span>; <span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Controller/Action.php'</span>; <span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Gdata.php'</span>; <span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Gdata/AuthSub.php'</span>; <span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Gdata/Spreadsheets.php'</span>; <span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Gdata/Spreadsheets/DocumentQuery.php'</span>; <span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Gdata/Spreadsheets/ListQuery.php'</span>; <span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Session/Namespace.php'</span>; <span style="color: #000000; font-weight: bold;">class</span> My_Controller_Gsheets <span style="color: #000000; font-weight: bold;">extends</span> My_Controller_Simple <span style="color: #66cc66;">{</span> protected <span style="color: #0000ff;">$_table_class</span> = <span style="color: #000000; font-weight: bold;">null</span>; protected <span style="color: #0000ff;">$_spreadsheet_name</span> = <span style="color: #000000; font-weight: bold;">null</span>; protected <span style="color: #0000ff;">$_worksheet_name</span> = <span style="color: #000000; font-weight: bold;">null</span>; protected <span style="color: #0000ff;">$_service</span> = <span style="color: #000000; font-weight: bold;">null</span>; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getTable<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getService<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$session</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getSession</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_service<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>->_service; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$session</span>-><span style="color: #006600;">sheet_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$client</span> = Zend_Gdata_AuthSub::<span style="color: #006600;">getHttpClient</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$session</span>-><span style="color: #006600;">sheet_token</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$this</span>->_service = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Spreadsheets<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$client</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>->_service; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getSpreadsheetName<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>->_spreadsheet_name; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getWorksheetName<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>->_worksheet_name; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> logonAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$session</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getSession</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!<a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$session</span>-><span style="color: #006600;">sheet_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'token'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #808080; font-style: italic;">// You can convert the single-use token to a session token.</span> <span style="color: #0000ff;">$token</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'token'</span><span style="color: #66cc66;">]</span>; <span style="color: #0000ff;">$session_token</span> = Zend_Gdata_AuthSub::<span style="color: #006600;">getAuthSubSessionToken</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$token</span><span style="color: #66cc66;">)</span>; <span style="color: #808080; font-style: italic;">// Store the session token in our session.</span> <span style="color: #0000ff;">$session</span>-><span style="color: #006600;">sheet_token</span> = <span style="color: #0000ff;">$session_token</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span> <span style="color: #808080; font-style: italic;">// Display link to generate single-use token</span> <span style="color: #0000ff;">$url</span> = <span style="color: #ff0000;">'http://'</span>. <span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'SERVER_NAME'</span><span style="color: #66cc66;">]</span> . <span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'REQUEST_URI'</span><span style="color: #66cc66;">]</span>; <span style="color: #0000ff;">$g_scope</span> = <span style="color: #ff0000;">'http://spreadsheets.google.com/feeds'</span>; <span style="color: #0000ff;">$g_secure</span> = <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #0000ff;">$g_session</span> = <span style="color: #000000; font-weight: bold;">true</span>; <span style="color: #0000ff;">$googleUri</span> = Zend_Gdata_AuthSub::<span style="color: #006600;">getAuthSubTokenUri</span><span style="color: #66cc66;">(</span> <span style="color: #0000ff;">$url</span>, <span style="color: #0000ff;">$g_scope</span>, <span style="color: #0000ff;">$g_secure</span>, <span style="color: #0000ff;">$g_session</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">view</span>-><span style="color: #006600;">googleUri</span> = <span style="color: #0000ff;">$googleUri</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> logoutAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$session</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getSession</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$session</span>-><span style="color: #006600;">sheet_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> Zend_Gdata_AuthSub::<span style="color: #006600;">AuthSubRevokeToken</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$session</span>-><span style="color: #006600;">sheet_token</span><span style="color: #66cc66;">)</span>; <a href="http://www.php.net/unset"><span style="color: #000066;">unset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$session</span>-><span style="color: #006600;">sheet_token</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #0000ff;">$this</span>->_helper-><span style="color: #006600;">redirector</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'index'</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> protected <span style="color: #000000; font-weight: bold;">function</span> _getSpreadsheetId<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$session</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getSession</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$service</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getService</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$session</span>-><span style="color: #006600;">spreadsheet_id</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$session</span>-><span style="color: #006600;">spreadsheet_id</span>; <span style="color: #66cc66;">}</span> <span style="color: #0000ff;">$title</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getSpreadsheetName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$feed</span> = <span style="color: #0000ff;">$service</span>-><span style="color: #006600;">getSpreadsheetFeed</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$feed</span>-><span style="color: #006600;">entries</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$entry</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$entry</span>-><span style="color: #006600;">title</span>-><span style="color: #006600;">text</span> == <span style="color: #0000ff;">$title</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$splits</span> = <a href="http://www.php.net/split"><span style="color: #000066;">split</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'/'</span>, <span style="color: #0000ff;">$entry</span>-><span style="color: #006600;">id</span>-><span style="color: #006600;">text</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$session</span>-><span style="color: #006600;">spreadsheet_id</span> = <span style="color: #0000ff;">$splits</span><span style="color: #66cc66;">[</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">]</span>; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$session</span>-><span style="color: #006600;">spreadsheet_id</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>; <span style="color: #66cc66;">}</span> protected <span style="color: #000000; font-weight: bold;">function</span> _getWorksheetId<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$doc_id</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$service</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getService</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$session</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getSession</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$session</span>-><span style="color: #006600;">worksheet_id</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$session</span>-><span style="color: #006600;">worksheet_id</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$doc_id</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$title</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getWorksheetName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$query</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Spreadsheets_DocumentQuery<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$query</span>-><span style="color: #006600;">setSpreadsheetKey</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$doc_id</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$feed</span> = <span style="color: #0000ff;">$service</span>-><span style="color: #006600;">getWorksheetFeed</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!<span style="color: #0000ff;">$title</span> && <span style="color: #0000ff;">$feed</span>-><span style="color: #006600;">count</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> > <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$splits</span> = <a href="http://www.php.net/split"><span style="color: #000066;">split</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'/'</span>, <span style="color: #0000ff;">$feed</span>-><span style="color: #006600;">entries</span><span style="color: #66cc66;">[</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">]</span>-><span style="color: #006600;">id</span>-><span style="color: #006600;">text</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$session</span>-><span style="color: #006600;">worksheet_id</span> = <span style="color: #0000ff;">$splits</span><span style="color: #66cc66;">[</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">]</span>; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$session</span>-><span style="color: #006600;">worksheet_id</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$feed</span>-><span style="color: #006600;">entries</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$entry</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$entry</span>-><span style="color: #006600;">title</span>-><span style="color: #006600;">text</span> == <span style="color: #0000ff;">$title</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$splits</span> = <a href="http://www.php.net/split"><span style="color: #000066;">split</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'/'</span>, <span style="color: #0000ff;">$entry</span>-><span style="color: #006600;">id</span>-><span style="color: #006600;">text</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$session</span>-><span style="color: #006600;">worksheet_id</span> = <span style="color: #0000ff;">$splits</span><span style="color: #66cc66;">[</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">]</span>; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$session</span>-><span style="color: #006600;">worksheet_id</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>; <span style="color: #66cc66;">}</span> protected <span style="color: #000000; font-weight: bold;">function</span> _executeList<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$table</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$service</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getService</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$doc_id</span> = <span style="color: #0000ff;">$this</span>->_getSpreadsheetId<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$sheet_id</span> = <span style="color: #0000ff;">$this</span>->_getWorksheetId<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$doc_id</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$doc_id</span> && <span style="color: #0000ff;">$sheet_id</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$query</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Spreadsheets_ListQuery<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$query</span>-><span style="color: #006600;">setSpreadsheetKey</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$doc_id</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$query</span>-><span style="color: #006600;">setWorksheetId</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$sheet_id</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$service</span>-><span style="color: #006600;">getListFeed</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>; <span style="color: #66cc66;">}</span> protected <span style="color: #000000; font-weight: bold;">function</span> _executeInsert<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$table</span>, <span style="color: #0000ff;">$values</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$service</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getService</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$doc_id</span> = <span style="color: #0000ff;">$this</span>->_getSpreadsheetId<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$sheet_id</span> = <span style="color: #0000ff;">$this</span>->_getWorksheetId<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$doc_id</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$doc_id</span> && <span style="color: #0000ff;">$sheet_id</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$service</span>-><span style="color: #006600;">insertRow</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$values</span>, <span style="color: #0000ff;">$doc_id</span>, <span style="color: #0000ff;">$sheet_id</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> protected <span style="color: #000000; font-weight: bold;">function</span> _executeUpdate<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$table</span>, <span style="color: #0000ff;">$id</span>, <span style="color: #0000ff;">$values</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$service</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getService</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$feed</span> = <span style="color: #0000ff;">$this</span>->_executeList<span style="color: #66cc66;">(</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$feed</span> && <span style="color: #0000ff;">$feed</span>-><span style="color: #006600;">count</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> >= <span style="color: #0000ff;">$id</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$entry</span> = <span style="color: #0000ff;">$feed</span>-><span style="color: #006600;">entries</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$id</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">]</span>; <span style="color: #0000ff;">$service</span>-><span style="color: #006600;">updateRow</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$entry</span>, <span style="color: #0000ff;">$values</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> protected <span style="color: #000000; font-weight: bold;">function</span> _executeDelete<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$table</span>, <span style="color: #0000ff;">$id</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$service</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getService</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$feed</span> = <span style="color: #0000ff;">$this</span>->_executeList<span style="color: #66cc66;">(</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$feed</span> && <span style="color: #0000ff;">$feed</span>-><span style="color: #006600;">count</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> >= <span style="color: #0000ff;">$id</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$entry</span> = <span style="color: #0000ff;">$feed</span>-><span style="color: #006600;">entries</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$id</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">]</span>; <span style="color: #0000ff;">$service</span>-><span style="color: #006600;">deleteRow</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$entry</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> protected <span style="color: #000000; font-weight: bold;">function</span> _executeFind<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$table</span>, <span style="color: #0000ff;">$id</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$feed</span> = <span style="color: #0000ff;">$this</span>->_executeList<span style="color: #66cc66;">(</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$feed</span> && <span style="color: #0000ff;">$feed</span>-><span style="color: #006600;">count</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> >= <span style="color: #0000ff;">$id</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$entry</span> = <span style="color: #0000ff;">$feed</span>-><span style="color: #006600;">entries</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$id</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">]</span>; <span style="color: #0000ff;">$rowData</span> = <span style="color: #0000ff;">$entry</span>-><span style="color: #006600;">getCustom</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$values</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$rowData</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$customEntry</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$values</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$customEntry</span>-><span style="color: #006600;">getColumnName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$customEntry</span>-><span style="color: #006600;">getText</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$values</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> |
次回
作成したコントローラを使います。
履歴
日付 | 内容 |
---|---|
2008/5/7 | 公開 |