public static function fetchMapMarkers($parentNodeId, $childrenClassIdentifiers)
 {
     foreach ($childrenClassIdentifiers as $key => $value) {
         if (empty($value)) {
             unset($childrenClassIdentifiers[$key]);
         }
     }
     $sortBy = array('name' => 'asc');
     $result = array();
     if ($parentNode = self::getNode($parentNodeId)) {
         if (!empty($childrenClassIdentifiers)) {
             $childrenClassTypes = (array) eZContentClass::fetchList(0, true, false, null, null, $childrenClassIdentifiers);
         } else {
             $childrenClassTypes = self::getChildrenClasses($parentNodeId);
         }
         // ricavo gli attributi delle classi
         $geoAttributes = array();
         foreach ($childrenClassTypes as $classType) {
             if ($classType instanceof eZContentClass) {
                 $geoAttributes = array_merge($geoAttributes, eZContentClassAttribute::fetchFilteredList(array('contentclass_id' => $classType->attribute('id'), 'version' => $classType->attribute('version'), 'data_type_string' => 'ezgmaplocation')));
             }
         }
         if (count($geoAttributes)) {
             // imposto i filtri di ricerca
             $geoFields = $geoFieldsNames = array();
             foreach ($geoAttributes as $geoAttribute) {
                 if ($geoAttribute instanceof eZContentClassAttribute) {
                     $geoFields[$geoAttribute->attribute('identifier')] = $geoAttribute->attribute('name');
                     $geoFieldsNames[] = "subattr_{$geoAttribute->attribute('identifier')}___coordinates____gpt";
                 }
             }
             $childrenParameters = array('SearchSubTreeArray' => array($parentNode->attribute('node_id')), 'Filter' => array('-meta_id_si:' . $parentNode->attribute('contentobject_id')), 'SearchLimit' => 1000, 'AsObjects' => false, 'SortBy' => $sortBy, 'FieldsToReturn' => $geoFieldsNames);
             // cerco i figli
             $solr = new OCSolr();
             $children = $solr->search('', $childrenParameters);
             if ($children['SearchCount'] > 0) {
                 foreach ($children['SearchResult'] as $item) {
                     foreach ($geoFieldsNames as $geoFieldsName) {
                         @(list($longitude, $latitude) = explode(',', $item['fields'][$geoFieldsName][0]));
                         if (intval($latitude) > 0 && intval($longitude) > 0) {
                             $href = isset($item['main_url_alias']) ? $item['main_url_alias'] : $item['main_url_alias_ms'];
                             eZURI::transformURI($href, false, 'full');
                             $popup = isset($item['name']) ? $item['name'] : $item['name_t'];
                             $id = isset($item['id_si']) ? $item['id_si'] : $item['id'];
                             $result[] = array('id' => $id, 'type' => null, 'lat' => floatval($latitude), 'lon' => floatval($longitude), 'lng' => floatval($longitude), 'popupMsg' => $popup, 'title' => $popup, 'description' => "<h3><a href='{$href}'>{$popup}</a></h3>", 'urlAlias' => $href, 'objectID' => $id);
                         }
                     }
                 }
             }
         }
     }
     return array('result' => $result);
 }
 public static function generateCache($file, $args)
 {
     extract($args);
     $result = false;
     if (isset($parameters)) {
         $solrSearch = new OCSolr();
         $result = $solrSearch->search($parameters['queryText'], $parameters['queryParameters']);
         $extras = $result['SearchExtras'];
         if ($extras instanceof ezfSearchResultInfo) {
             $result['FacetFields'] = $extras->attribute('facet_fields');
         }
         unset($result['SearchExtras']);
     }
     return array('content' => $result, 'scope' => self::CACHE_IDENTIFIER);
 }
 public function fetch()
 {
     $startDateArray = array('hour' => '00', 'minute' => '00', 'second' => '00', 'month' => $this->parameters['month'], 'day' => $this->parameters['day'], 'year' => $this->parameters['year']);
     $originalStartDateTime = DateTime::createFromFormat('H i s n j Y', implode(' ', $startDateArray), self::timezone());
     $this->parameters['picker_date'] = date(self::PICKER_DATE_FORMAT, $originalStartDateTime->getTimestamp());
     if ($this->parameters['interval'] == self::INTERVAL_MONTH) {
         $startDateArray['day'] = 1;
     }
     $startDateTime = DateTime::createFromFormat('H i s n j Y', implode(' ', $startDateArray), self::timezone());
     if (!$startDateTime instanceof DateTime) {
         throw new Exception("Data non valida");
     }
     $interval = new DateInterval($this->parameters['interval']);
     if (!$interval instanceof DateInterval) {
         throw new Exception("Intervallo non valido");
     }
     // start day
     $this->parameters['timestamp'] = $startDateTime->getTimestamp();
     $this->parameters['days_of_month'] = date('t', $startDateTime->getTimestamp());
     $this->parameters['start_weekday'] = date('w', $startDateTime->getTimestamp());
     $endOfMonthArray = array_merge($startDateArray, array('day' => $this->parameters['days_of_month']));
     $endOfMonthDateTime = DateTime::createFromFormat('H i s n j Y', implode(' ', $endOfMonthArray), self::timezone());
     $this->parameters['end_weekday'] = date('w', $endOfMonthDateTime->getTimestamp());
     $fromTimeStamp = $startDateTime->format('U');
     $this->parameters['search_from_solr'] = ezfSolrDocumentFieldBase::preProcessValue($startDateTime->getTimestamp(), 'date');
     $this->parameters['search_from_timestamp'] = $startDateTime->getTimestamp();
     // end day
     $endDateTime = clone $startDateTime;
     $endDateTime->add($interval);
     $endTimeStamp = $endDateTime->format('U');
     $this->parameters['search_to_solr'] = ezfSolrDocumentFieldBase::preProcessValue($endDateTime->getTimestamp() - 1, 'date');
     $this->parameters['search_to_timestamp'] = $endDateTime->getTimestamp();
     $this->parameters['search_to_picker_date'] = date(self::PICKER_DATE_FORMAT, $endDateTime->getTimestamp());
     // filter
     $this->filters[] = array('or', 'attr_from_time_dt:[' . $this->parameters['search_from_solr'] . ' TO ' . $this->parameters['search_to_solr'] . ']', 'attr_to_time_dt:[' . $this->parameters['search_from_solr'] . ' TO ' . $this->parameters['search_to_solr'] . ']', array('and', 'attr_from_time_dt:[* TO ' . $this->parameters['search_from_solr'] . ']', 'attr_to_time_dt:[' . $this->parameters['search_to_solr'] . ' TO *]'));
     $facets = array();
     //esempio: $this->parameters['Materia'] = '"Economia e diritto"';
     foreach (self::relatedParameters() as $fieldIdentifier => $fieldName) {
         if (isset($this->parameters[$fieldName]) && $this->parameters[$fieldName] !== false) {
             if (is_array($this->parameters[$fieldName])) {
                 $orFilter = array('or');
                 foreach ($this->parameters[$fieldName] as $value) {
                     $filterValue = addcslashes($value, '"');
                     $orFilter[] = "subattr_{$fieldIdentifier}___name____s:\"{$filterValue}\"";
                 }
                 $this->filters[] = $orFilter;
             } else {
                 $filterValue = addcslashes($this->parameters[$fieldName], '"');
                 $this->filters[] = "subattr_{$fieldIdentifier}___name____s:\"{$filterValue}\"";
             }
         }
         $facets[] = array('field' => "subattr_{$fieldIdentifier}___name____s", 'name' => $fieldName, 'limit' => 100, 'sort' => 'alpha');
     }
     if (is_array($this->parameters['filter'])) {
         $this->filters = array_merge($this->filters, $this->parameters['filter']);
     }
     $sortBy = array('attr_priority_si' => 'desc', 'attr_special_b' => 'desc');
     if (class_exists('ezfIndexEventDuration')) {
         $sortBy['extra_event_duration_s'] = 'asc';
     }
     $sortBy['attr_from_time_dt'] = 'asc';
     $solrFetchParams = array('SearchOffset' => 0, 'SearchLimit' => 1000, 'Facet' => $facets, 'SortBy' => $sortBy, 'Filter' => $this->filters, 'SearchContentClassID' => null, 'SearchSectionID' => null, 'SearchSubTreeArray' => $this->parameters['subtree'], 'AsObjects' => false, 'SpellCheck' => null, 'IgnoreVisibility' => null, 'Limitation' => null, 'BoostFunctions' => null, 'QueryHandler' => 'ezpublish', 'EnableElevation' => true, 'ForceElevation' => true, 'SearchDate' => null, 'DistributedSearch' => null, 'FieldsToReturn' => self::fieldsToReturn(), 'SearchResultClustering' => null, 'ExtendedAttributeFilter' => array());
     $solrSearch = new OCSolr();
     $solrResult = $solrSearch->search($this->parameters['query'], $solrFetchParams);
     //eZDebug::writeNotice( $this->filters, __METHOD__ );
     //eZDebug::writeNotice( $solrResult, __METHOD__ );
     $this->data['parameters'] = $this->parameters;
     $this->data['fetch_parameters'] = $solrFetchParams;
     $facetFields = $solrResult['SearchExtras']->attribute('facet_fields');
     //eZDebug::writeNotice( $solrResult['SearchExtras'], __METHOD__ );
     $resultFacets = array();
     foreach ($facets as $index => $facet) {
         if (isset($facetFields[$index]['queryLimit']) && !empty($facetFields[$index]['queryLimit'])) {
             if (isset($facetFields[$index]['fieldList'])) {
                 foreach ($facetFields[$index]['fieldList'] as $key => $value) {
                     $resultFacets[$facet['name']][] = $key;
                 }
             } else {
                 foreach ($facetFields[$index]['nameList'] as $key => $value) {
                     $resultFacets[$facet['name']][] = $key;
                 }
             }
         }
     }
     $this->data['search_facets'] = $this->sortFacets($resultFacets);
     $events = array();
     foreach ($solrResult['SearchResult'] as $item) {
         $event = OCCalendarItem::fromEzfindResultArray($item);
         if ($event->isValid()) {
             $events[] = $event;
         }
     }
     $timeTableEvents = $this->fetchTimeTableEvents();
     if (count($timeTableEvents)) {
         $events = self::reorderEvents(array_merge($events, $timeTableEvents));
     }
     //eZDebug::writeNotice( $events, __METHOD__ );
     $this->data['search_count'] = count($events);
     $eventsByDay = array();
     $byDayInterval = new DateInterval('P1D');
     $byDayPeriod = new DatePeriod($startDateTime, $byDayInterval, $endDateTime);
     foreach ($byDayPeriod as $date) {
         $identifier = $date->format(self::FULLDAY_IDENTIFIER_FORMAT);
         $calendarDay = new OCCalendarDay($identifier);
         $calendarDay->addEvents($events);
         $eventsByDay[$identifier] = $calendarDay;
     }
     $this->data['events'] = $events;
     $this->data['day_by_day'] = $eventsByDay;
     //eZDebug::writeNotice( $eventsByDay, __METHOD__ );
     //eZDebug::writeNotice( $this->data['search_facets'], __METHOD__ );
 }