Last active
          October 15, 2019 05:31 
        
      - 
      
 - 
        
Save YuzuruSano/d60fe9844d003ecec352 to your computer and use it in GitHub Desktop.  
    PgaeListオブジェクト利用例チートシート
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| // http://concrete5-japan.org/help/5-7/developer/working-with-pages/searching-and-sorting-with-the-pagelist-object/ | |
| $list = new \Concrete\Core\Page\PageList(); | |
| //ページタイプでフィルター | |
| $list->filterByPageTypeHandle('blog_entry'); | |
| //複数のタイプでフィルター | |
| $list->filterByPageTypeHandle(array('blog_entry', 'press_release')); | |
| //キーワードでフィルター(シンプル) | |
| $list->filterByKeywords('foobar'); | |
| //キーワードでのフィルターは、ページの名前、説明、テキストコンテンツ、「検索インデックスに含む」にマークされている検索可能なページ属性を対象に検索します。 | |
| //キーワードでフィルター(フルテキスト) | |
| $list->filterByKeywords('foobar'); | |
| //現在のページを除く | |
| $list->filter('p.cID', $c->getCollectionID(), '!='); | |
| //親ページでフィルター | |
| $list->filter('p.cParentID', $parentID); | |
| //選択属性に含まれているかどうかでフィルター | |
| $list->filter(false, '(ak_select IN (1,2,3))'); | |
| //日付属性でフィルター 今日より日付があと | |
| $pageListPlus->filter('ak_data_event_finish', date('Y-m-d'), ">="); | |
| //表示日時でソート | |
| $list->sortByPublicDate(); | |
| //または降順 | |
| $list->sortByPublicDateDescending(); | |
| //名前でソート | |
| $list->sortByName(); | |
| //サイトマップ順でソート | |
| $list->sortByDisplayOrder(); | |
| //権限を無視 | |
| $list->ignorePermissions(); | |
| //特殊なページを含める | |
| $list->includeInactivePages(); // 非アクティブページ | |
| $list->includeAliases(); // エイリアス | |
| $list->includeSystemPages(); // システムページ | |
| // 下記の場合、各行はANDで連結される | |
| // $myList->filterByAttribute('name',$val1); | |
| // $myList->filterByAttribute('addr',$val2); | |
| //選択属性でOR検索 | |
| foreach ($forsearch as $v) { | |
| $criteria[] = "(ak_xxx LIKE '%\n{$v}\n%')"; | |
| } | |
| $where = '(' . implode(' OR ', $criteria) . ')'; | |
| $list->filter(false, $where); | |
| // あまり無いと思うけど | |
| // OR連結とAND連結を混ぜるような場合にはfilterメソッドからSQLを書く | |
| // 下記は属性でのOR検索の例。SQL書くときは「ak_属性ハンドル」で指定する。 | |
| // find_in_setなどのmysqlで持っているメソッドも利用できる | |
| // $myList->filter(false, '(ak_age = 10 OR ak_age IN (13,17,25) OR ak_age > 23)'); | |
| //filterを使って複合ORキーワードサーチ はキーワード | |
| $list->filter(false, '(psi.cName LIKE "%'.$query.'%" OR psi.content LIKE "%'.$query.'%" OR ak_data_events_president LIKE "%'.$query.'%")'); | |
| //Paginationオブジェクトで表示件数の制限 | |
| //カスタマイズ例 | |
| //http://concrete5-japan.org/help/5-7/recipes/customize-pagination/ | |
| $pagination = $list->getPagination(); | |
| $pagination->setMaxPerPage($num);//件数指定してREQUESTされたページを表示 | |
| //$pagination->setMaxPerPage($num)->setCurrentPage(1);//表示させるページを指定したい場合 | |
| $pages = $pagination->getCurrentPageResults(); | |
| //ページネーションを表示 | |
| echo $pagination->renderDefaultView(); | |
| //一通り条件を投げたらこちらで結果を取得 | |
| $pages = $list->getResults();//ループ用にオブジェクトを取得 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment