메뉴 건너뛰기

infra

[Gdata] php로 Zend_Gdata_Spreadsheets_ListQuery 사용

lispro062015.06.15 01:31조회 수 1026댓글 1

    • 글자 크기

1. PHP ZEND 설치

2. ZEND library full down - gdata가 xml도 사용하므로 full로 다운받아야 이용 가능(zend framework 1.12.13)

http://framework.zend.com/downloads/latest

3. ZendFramework-1.12.13/demos/Zend/Gdata/Spreadsheet-ClientLogin.php 파일 수정

//생성자에 시트키와 워크시트 키를 고정한다.

    public function __construct($email, $password, $keyword)

    {

        try {

          $client = Zend_Gdata_ClientLogin::getHttpClient($email, $password,

                    Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME);

        } catch (Zend_Gdata_App_AuthException $ae) {

          exit("Error: ". $ae->getMessage() ."nCredentials provided were email: [$email] and password [$password].n");

        }

$this->gdClient = new Zend_Gdata_Spreadsheets($client);

        $this->currKey = '시트키';

        $this->currWkshtId = '워크시트키';

        $this->listFeed = '';

        $this->rowCount = 0;

        $this->columnCount = 0;

$this->keyword = '검색어';//셀상단값=검색어

    }

//스프레드시트 선택 인풋 루틴 제거

    /**

     * promptForSpreadsheet

     *

     * @return void

     */

    public function promptForSpreadsheet()

    {

        $feed = $this->gdClient->getSpreadsheetFeed();

    }

//워크시트 선택 인풋 루틴 제거

    /**

     * promptForWorksheet

     *

     * @return void

     */

    public function promptForWorksheet()

    {

        $query = new Zend_Gdata_Spreadsheets_DocumentQuery();

        $query->setSpreadsheetKey($this->currKey);

        $feed = $this->gdClient->getWorksheetFeed($query);

    }

// 리스트 방식으로 고정하고 첫번째 명령을 dump로 고정
    /**
     * promptForListAction
     *
     * @return void
     */
    public function promptForListAction()
    {
        $command[0] = "dump";
        if ($command[0] == 'dump') {
            $this->listGetAction();
        } else if ($command[0] == 'insert') {
            $this->listInsertAction(array_slice($command, 1));
        } else if ($command[0] == 'update') {
            $this->listUpdateAction($command[1], array_slice($command, 2));
        } else if ($command[0] == 'delete') {
            $this->listDeleteAction($command[1]);
        } else {
            $this->invalidCommandError($input);
        }
    }
//리스트 출력 함수 부분에 setSpreadsheetQuery("검색어"); 추가
    /**
     * listGetAction
     *
     * @return void
     */
    public function listGetAction()
    {
        $query = new Zend_Gdata_Spreadsheets_ListQuery();
        $query->setSpreadsheetKey($this->currKey);
        $query->setWorksheetId($this->currWkshtId);
$keyword="전문의=".$this->keyword;
$query->setSpreadsheetQuery($keyword);
        $this->listFeed = $this->gdClient->getListFeed($query);
print "<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>"; 
        $this->printFeed($this->listFeed);
        print "</body></html>n";
exit();//무한 루프를 없애기 위해 종료
    }

    /**
     * run
     *
     * @return void
     */
    public function run()
    {
        $this->promptForSpreadsheet();
        $this->promptForWorksheet();
        $this->promptForListAction();//리스트 액션을 호출해 주면 된다.
    }

쿼리 사용은 http://framework.zend.com/manual/1.12/en/zend.gdata.spreadsheets.html 참고


        $query = new Zend_Gdata_Spreadsheets_ListQuery();

        $query->setSpreadsheetKey($this->currKey);

        $query->setWorksheetId($this->currWkshtId);

$keyword="셀이름=검색어";

$query->setSpreadsheetQuery($keyword);

        $this->listFeed = $this->gdClient->getListFeed($query);


봐줄만한 속도로 스프레드시트의 검색된 결과 행을 출력한다.



    /**

     * printFeed

     *

     * @param  Zend_Gdata_Gbase_Feed $feed

     * @return void

     */

    public function printFeed($feed)

    {

        $i = 0;

        foreach($feed->entries as $entry) {

           // if ($entry instanceof Zend_Gdata_Spreadsheets_CellEntry) {

           //     print $entry->title->text .' '. $entry->content->text . "n";

           // } else if ($entry instanceof Zend_Gdata_Spreadsheets_ListEntry) {

           //     print $i .' '. $entry->title->text .' | '. $entry->content->text . "n";

           // } else {

           //     print $i .' '. $entry->title->text . "n";

           // }

  print $entry->content->text;

            $i++;

        }

    }

위 함수를 수정하면 출력 결과 형태를 커스터마이징할 수 있다.
lispro06 (비회원)
    • 글자 크기
[OAuth] 구글 OAuth2 사용 (by lispro06) [Tonardo] Python 웹서버 (by lispro06)

댓글 달기

댓글 1
첨부 (0)
위로