コード例 #1
0
ファイル: controller.php プロジェクト: baardev/lbtb
 public function getPages($query = null)
 {
     global $c;
     $db = Loader::db();
     $bID = $this->bID;
     if ($this->bID) {
         $q = "select num, cParentID, cThis, orderBy, ctID, displayAliases, rss from btRelatedPages where bID = '{$bID}'";
         $r = $db->query($q);
         if ($r) {
             $row = $r->fetchRow();
         }
     } else {
         $row['num'] = $this->num;
         $row['cParentID'] = $this->cParentID;
         $row['cThis'] = $this->cThis;
         $row['orderBy'] = $this->orderBy;
         $row['ctID'] = $this->ctID;
         $row['rss'] = $this->rss;
         $row['displayAliases'] = $this->displayAliases;
     }
     $pl = new ProblogList();
     $cArray = array();
     switch ($row['orderBy']) {
         case 'display_asc':
             $pl->sortByDisplayOrder();
             break;
         case 'display_desc':
             $pl->sortByDisplayOrderDescending();
             break;
         case 'chrono_asc':
             $pl->sortByPublicDate();
             break;
         case 'alpha_asc':
             $pl->sortByName();
             break;
         case 'alpha_desc':
             $pl->sortByNameDescending();
             break;
         default:
             $pl->sortByPublicDateDescending();
             break;
     }
     $num = (int) $row['num'];
     if ($num > 0) {
         $pl->setItemsPerPage($num);
     }
     $c = Page::getCurrentPage();
     if (is_object($c)) {
         $this->cID = $c->getCollectionID();
     }
     $cParentID = $row['cThis'] ? $this->cID : $row['cParentID'];
     //$pl->filter(false,"(CHAR_LENGTH(cv.cvName) > 4 OR cv.cvName NOT REGEXP '^[0-9]')");
     $pl->filter(false, "ak_is_canonical_page < 1");
     $pl->filter('cvName', '', '!=');
     if ($row['ctID']) {
         $ctID = $row['ctID'];
         $pl->filter(false, "p.ptID = {$ctID}");
     }
     $columns = $db->MetaColumns(CollectionAttributeKey::getIndexedSearchTable());
     if (isset($columns['AK_EXCLUDE_PAGE_LIST'])) {
         $pl->filter(false, '(ak_exclude_page_list = 0 or ak_exclude_page_list is null)');
     }
     if (intval($row['cParentID']) != 0 && intval($row['cParentID']) != 9999) {
         $path = Page::getByID($cParentID)->getCollectionPath();
         $pl->filterByPath($path);
     } else {
         if (is_object($c)) {
             $parent = $c->getCollectionParentID();
             $pl->filterByParentID($parent);
         }
     }
     if ($this->displayFeaturedOnly == 1) {
         $cak = CollectionAttributeKey::getByHandle('is_featured');
         if (is_object($cak)) {
             $pl->filterByIsFeatured(1);
         }
     }
     if ($this->getAttributeKeyID()) {
         if ($this->akID == 'same_tags') {
             if (!is_object($c)) {
                 $c = Page::getByID($this->ccID);
             }
             $ak_handle = 'tags';
             $tags = $c->getAttribute($ak_handle);
             //$fields_array = explode(',',$tags);
             if ($tags) {
                 $fields_array = $tags->getOptions();
             }
         } else {
             if (!is_object($c)) {
                 $c = Page::getByID($this->ccID);
             }
             $ak = CollectionAttributeKey::getByID($this->getAttributeKeyID());
             $ak_handle = $ak->getAttributeKeyHandle();
             $fields_array = explode(',', $this->fields);
         }
         //var_dump($fields_array);
         if ($fields_array) {
             foreach ($fields_array as $field) {
                 if ($fs) {
                     $filter .= ' OR ';
                 } else {
                     $filter .= '(';
                 }
                 $filter .= "ak_" . $ak_handle . " LIKE '%\n{$field}\n%'";
                 $fs++;
             }
             $filter .= ')';
         }
     }
     if (is_object($c)) {
         $pl->filter(false, 'p.cID != ' . $c->getCollectionID());
     }
     if ($filter) {
         $pl->Filter(false, $filter);
     }
     //$pl->debug();
     $pl->ignoreAliases();
     $pages = $pl->getResults();
     $this->set('pl', $pl);
     return $pages;
 }