Example #1
0
 /**
  * @deprecated as of SD 2.0 - will be removed when the "Filter:"
  * namespace goes away.
  */
 static function load($filter_name)
 {
     $f = new SDFilter();
     $f->setName($filter_name);
     $properties_used = SDUtils::getValuesForProperty($filter_name, SD_NS_FILTER, '_SD_CP', SD_SP_COVERS_PROPERTY, SMW_NS_PROPERTY);
     if (count($properties_used) > 0) {
         $f->setProperty($properties_used[0]);
         // This may not be necessary, or useful.
         $f->property_type = 'page';
     }
     $proptitle = Title::newFromText($f->property, SMW_NS_PROPERTY);
     if ($proptitle != null) {
         $f->loadPropertyTypeFromProperty();
     }
     $categories = SDUtils::getValuesForProperty($filter_name, SD_NS_FILTER, '_SD_VC', SD_SP_GETS_VALUES_FROM_CATEGORY, NS_CATEGORY);
     if (count($categories) > 0) {
         $f->setCategory($categories[0]);
     } elseif ($f->property_type === 'boolean') {
         $f->allowed_values = array('0', '1');
     } else {
         $f->allowed_values = array();
     }
     // Set list of possible applied filters if allowed values
     // array was set.
     foreach ($f->allowed_values as $allowed_value) {
         $f->possible_applied_filters[] = SDAppliedFilter::create($f, $allowed_value);
     }
     return $f;
 }
Example #2
0
 /**
  * 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;
 }
	/**
	 * 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;
	}