/** * @param array $accreditationList * @param int $offset * * @return array Sorted and filtered list of certificates. */ public function manageResults( $accreditationList = null, $offset = 0 ) { $wsResults = CertificatesWebservice::getCertificatesList(); $facets = array( self::$noAccreditationKeyword => 0 ); foreach ( $wsResults as $k => $result ) { $fetchResult = self::fetchNodeAndAppFromCourseId( $result['CourseID'] ); if ( $result['CompletionDateTime'] != '' ) { $tempDate = DateTime::createFromFormat( $this->dateFormat, $result['CompletionDateTime'] ); if ( $tempDate instanceof DateTime ) { $wsResults[$k]['CompletionDateTime'] = $tempDate->getTimestamp(); } else { $wsResults[$k]['CompletionDateTime'] = ''; } } if ( $fetchResult === false || (isset($fetchResult['node']) && !ObjectVisibilityManager::isVisible($fetchResult['node']->ContentObjectID)) ) { $wsResults[$k]['SimpleView'] = true; $facets[self::$noAccreditationKeyword] += 1; if ( !self::isAccreditationSourceChosen( self::$noAccreditationKeyword, $accreditationList ) ) { unset( $wsResults[$k] ); } continue; } /* @type $node eZContentObjectTreeNode */ /* @type $dm eZContentObjectAttribute[] */ $node = $fetchResult['node']; $wsResults[$k] = array_merge($wsResults[$k], $fetchResult); $dm = $node->dataMap(); $tags = array(); if ( $dm['serialized_taxonomies'] instanceof eZContentObjectAttribute ) { $serializedTaxonomies = $dm['serialized_taxonomies']->content(); if ( isset( $serializedTaxonomies['accreditation_source'] ) ) { $tags = (array) $serializedTaxonomies['accreditation_source']; } } if ( count( $tags ) == 0 ) { $wsResults[$k]['SimpleView'] = true; $facets[self::$noAccreditationKeyword] += 1; if ( !self::isAccreditationSourceChosen( self::$noAccreditationKeyword, $accreditationList ) ) { unset( $wsResults[$k] ); } continue; } foreach ( $tags as $keyword ) { if ( !isset( $facets[$keyword] ) ) { $facets[$keyword] = 0; } $facets[$keyword] += 1; if ( !self::isAccreditationSourceChosen( $keyword, $accreditationList ) ) { unset( $wsResults[$k] ); } } } $articleTotal = count( $wsResults ); return array( "items" => self::sortAndPaginate( $wsResults, $articleTotal, $offset ), "facets" => array( "accreditation_source" => $facets ), "total" => $articleTotal, ); }