コード例 #1
0
ファイル: SD_Utils.php プロジェクト: yusufchang/app
 /**
  * Gets all the filters specified for a category.
  */
 static function loadFiltersForCategory($category)
 {
     $filters = array();
     $title = Title::newFromText($category, NS_CATEGORY);
     $pageId = $title->getArticleID();
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('page_props', array('pp_value'), array('pp_page' => $pageId, 'pp_propname' => 'SDFilters'));
     while ($row = $dbr->fetchRow($res)) {
         // There should only be one row.
         $filtersStr = $row['pp_value'];
         $filtersInfo = unserialize($filtersStr);
         foreach ($filtersInfo as $filterName => $filterValues) {
             $curFilter = new SDFilter();
             $curFilter->setName($filterName);
             foreach ($filterValues as $key => $value) {
                 if ($key == 'property') {
                     $curFilter->setProperty($value);
                     $curFilter->loadPropertyTypeFromProperty();
                 } elseif ($key == 'category') {
                     $curFilter->setCategory($value);
                 } elseif ($key == 'requires') {
                     $curFilter->addRequiredFilter($value);
                 }
             }
             $filters[] = $curFilter;
         }
     }
     // Get "legacy" filters defined via the SMW special property
     // "Has filter" and the Filter: namespace.
     $filter_names = SDUtils::getValuesForProperty(str_replace(' ', '_', $category), NS_CATEGORY, '_SD_F');
     foreach ($filter_names as $filter_name) {
         $filter = SDFilter::load($filter_name);
         $filter->required_filters = SDUtils::getValuesForProperty($filter_name, SD_NS_FILTER, '_SD_RF', SD_SP_REQUIRES_FILTER, SD_NS_FILTER);
         $filters[] = $filter;
     }
     // Read from the Page Schemas schema for this category, if
     // it exists, and add any filters defined there.
     if (class_exists('PSSchema')) {
         $pageSchemaObj = new PSSchema($category);
         if ($pageSchemaObj->isPSDefined()) {
             $filters_ps = SDFilter::loadAllFromPageSchema($pageSchemaObj);
             $result_filters = array_merge($filters, $filters_ps);
             return $result_filters;
         }
     }
     return $filters;
 }
コード例 #2
0
	/**
	 * Gets all the filters specified for a category.
	 */
	static function loadFiltersForCategory( $category ) {
		$filters = array();
		$filters_ps = array();
		$filter_names = SDUtils::getValuesForProperty( str_replace( ' ', '_', $category ), NS_CATEGORY, '_SD_F' );
		foreach ( $filter_names as $filter_name ) {
			$filters[] = SDFilter::load( $filter_name );
		}
		// Read from the Page Schemas schema for this category, if
		// it exists, and add any filters defined there.
		if ( class_exists( 'PSSchema' ) ) {
			$pageSchemaObj = new PSSchema( $category );
			if ( $pageSchemaObj->isPSDefined() ) {
				$filters_ps = SDFilter::loadAllFromPageSchema( $pageSchemaObj );
				$result_filters = array_merge( $filters, $filters_ps );
				return $result_filters;
			}
		}
		return $filters;
	}