当前位置: 首页>>代码示例>>PHP>>正文


PHP TimeExpressionParser::normalizeDateRange方法代码示例

本文整理汇总了PHP中TimeExpressionParser::normalizeDateRange方法的典型用法代码示例。如果您正苦于以下问题:PHP TimeExpressionParser::normalizeDateRange方法的具体用法?PHP TimeExpressionParser::normalizeDateRange怎么用?PHP TimeExpressionParser::normalizeDateRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeExpressionParser的用法示例。


在下文中一共展示了TimeExpressionParser::normalizeDateRange方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: caNormalizeDateRange

/**
 * Normalize arbitrarily precise date expression to century, decade, year, month or day
 *
 * @param string $ps_expression A valid date expression parseable by the TimeExpressionParser class
 * @param string $ps_normalization Level to normalize to. Valid values are centuries, decades, years, months, days
 * @param array $pa_options
 *			delimiter = A string to join multiple values with when returning normalized date range as a string. Default is semicolon followed by space ("; ")
 *			returnAsArray = If set an array of normalized values will be returned rather than a string. Default is false.
 * @return mixes The normalized expression. If the expression normalizes to multiple values (eg. a range of years being normalized to months) then the values will be joined with a delimiter and returned as a string unless the "returnAsArray" option is set.
 */
function caNormalizeDateRange($ps_expression, $ps_normalization, $pa_options = null)
{
    $o_tep = new TimeExpressionParser();
    if ($o_tep->parse($ps_expression)) {
        $va_dates = $o_tep->getHistoricTimestamps();
        $va_vals = $o_tep->normalizeDateRange($va_dates['start'], $va_dates['end'], $ps_normalization);
        if (isset($pa_options['returnAsArray']) && $pa_options['returnAsArray']) {
            return $va_vals;
        } else {
            $vs_delimiter = isset($pa_options['returnAsArray']) ? $pa_options['returnAsArray'] : "; ";
            return join($vs_delimiter, $va_vals);
        }
    }
    return null;
}
开发者ID:kai-iak,项目名称:providence,代码行数:25,代码来源:displayHelpers.php

示例2: switch

         if (isset($va_types[$vs_g]['name_plural'])) {
             $va_groups[] = $va_types[$vs_g]['name_plural'];
         } else {
             $va_groups[] = _t('Type ') . $vs_g;
         }
     }
     break;
 default:
     if ($vn_grouping_attribute_id) {
         switch ($vn_element_datatype) {
             case 2:
                 //date
                 $va_tmp = explode(':', $vs_grouping_field);
                 if (isset($va_item['ca_attribute_' . $vn_grouping_attribute_id]) && is_array($va_item['ca_attribute_' . $vn_grouping_attribute_id])) {
                     foreach ($va_item['ca_attribute_' . $vn_grouping_attribute_id] as $vn_i => $va_v) {
                         $va_v = $o_tep->normalizeDateRange($va_v['value_decimal1'], $va_v['value_decimal2'], isset($va_tmp[1]) && in_array($va_tmp[1], array('years', 'decades', 'centuries')) ? $va_tmp[1] : 'decades');
                         foreach ($va_v as $vn_i => $vn_v) {
                             $va_groups[] = $vn_v;
                         }
                     }
                 }
                 break;
             default:
                 if (isset($va_item['ca_attribute_' . $vn_grouping_attribute_id]) && is_array($va_item['ca_attribute_' . $vn_grouping_attribute_id])) {
                     foreach ($va_item['ca_attribute_' . $vn_grouping_attribute_id] as $vn_i => $va_v) {
                         $va_groups[] = $va_v['value_longtext1'];
                     }
                 }
                 break;
         }
     } else {
开发者ID:guaykuru,项目名称:pawtucket,代码行数:31,代码来源:ajax_browse_facet_html.php

示例3: getFacetContent


//.........这里部分代码省略.........
                 if (isset($va_facet_info['maximum_date'])) {
                     if ($o_tep->parse($va_facet_info['maximum_date'])) {
                         $va_tmp = $o_tep->getHistoricTimestamps();
                         $vn_max_date = (double) $va_tmp['end'];
                         $vs_max_sql = " AND (ca_attribute_values.value_decimal2 <= {$vn_max_date})";
                     }
                 }
                 if ($vb_check_availability_only) {
                     $vs_sql = "\n\t\t\t\t\t\t\t\tSELECT 1\n\t\t\t\t\t\t\t\tFROM ca_attributes\n\t\t\t\t\t\t\t\t{$vs_join_sql}\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tca_attribute_values.element_id = ? \n\t\t\t\t\t\t\t\t\t{$vs_min_sql}\n\t\t\t\t\t\t\t\t\t{$vs_max_sql}\n\t\t\t\t\t\t\t\t\t{$vs_where_sql}\n\t\t\t\t\t\t\t\t\tLIMIT 1";
                     //print $vs_sql;
                     $qr_res = $this->opo_db->query($vs_sql, $vn_element_id);
                     return (int) $qr_res->numRows() > 0 ? true : false;
                 } else {
                     $vs_sql = "\n\t\t\t\t\t\t\t\tSELECT DISTINCT ca_attribute_values.value_decimal1, ca_attribute_values.value_decimal2\n\t\t\t\t\t\t\t\tFROM ca_attributes\n\t\t\t\t\t\t\t\t{$vs_join_sql}\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tca_attribute_values.element_id = ? \n\t\t\t\t\t\t\t\t\t{$vs_min_sql}\n\t\t\t\t\t\t\t\t\t{$vs_max_sql}\n\t\t\t\t\t\t\t\t\t{$vs_where_sql}\n\t\t\t\t\t\t\t";
                     //print $vs_sql;
                     $qr_res = $this->opo_db->query($vs_sql, $vn_element_id);
                     $vn_current_year = (int) date("Y");
                     $va_values = array();
                     $vb_include_unknown = (bool) caGetOption('include_unknown', $va_facet_info, false);
                     $vb_unknown_is_set = false;
                     while ($qr_res->nextRow()) {
                         $vn_start = $qr_res->get('value_decimal1');
                         $vn_end = $qr_res->get('value_decimal2');
                         if (!($vn_start && $vn_end)) {
                             if ($vb_include_unknown) {
                                 $vb_unknown_is_set = true;
                             }
                             continue;
                         }
                         if ($vn_end > $vn_current_year + 50) {
                             continue;
                         }
                         // bad years can make for large facets that cause timeouts so cut it off 50 years into the future
                         $va_normalized_values = $o_tep->normalizeDateRange($vn_start, $vn_end, $vs_normalization);
                         foreach ($va_normalized_values as $vn_sort_value => $vs_normalized_value) {
                             if ($va_criteria[$vs_normalized_value]) {
                                 continue;
                             }
                             // skip items that are used as browse critera - don't want to browse on something you're already browsing on
                             if (is_numeric($vs_normalized_value) && (int) $vs_normalized_value === 0) {
                                 continue;
                             }
                             // don't include year=0
                             $va_values[$vn_sort_value][$vs_normalized_value] = array('id' => $vs_normalized_value, 'label' => $vs_normalized_value);
                             if (!is_null($vs_single_value) && $vs_normalized_value == $vs_single_value) {
                                 $vb_single_value_is_present = true;
                             }
                         }
                     }
                     if ($vb_include_unknown && !$vb_unknown_is_set) {
                         // Check for rows where no data is set at all as opposed to null dates
                         $vs_sql = "\n\t\t\t\t\t\t\t\t\tSELECT DISTINCT ca_attributes.row_id\n\t\t\t\t\t\t\t\t\tFROM ca_attributes\n\t\t\t\t\t\t\t\t\t{$vs_join_sql}\n\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\tca_attribute_values.element_id = ? \n\t\t\t\t\t\t\t\t\t\t{$vs_min_sql}\n\t\t\t\t\t\t\t\t\t\t{$vs_max_sql}\n\t\t\t\t\t\t\t\t\t\t{$vs_where_sql}\n\t\t\t\t\t\t\t\t";
                         //print $vs_sql;
                         $qr_res = $this->opo_db->query($vs_sql, $vn_element_id);
                         if ($qr_res->numRows() < sizeof($va_results)) {
                             $vb_unknown_is_set = true;
                         }
                     }
                     if ($vb_unknown_is_set && sizeof($va_values) > 0) {
                         $va_values['999999999'][_t('Date unknown')] = array('id' => 'null', 'label' => _t('Date unknown'));
                     }
                     if (!is_null($vs_single_value) && !$vb_single_value_is_present) {
                         return array();
                     }
                     ksort($va_values);
                     if ($vs_dir == 'DESC') {
开发者ID:kai-iak,项目名称:pawtucket2,代码行数:67,代码来源:BrowseEngine.php

示例4: testNormalizationDecades

 function testNormalizationDecades()
 {
     $o_tep = new TimeExpressionParser('16th century', 'en_US');
     $va_historic = $o_tep->getHistoricTimestamps();
     $va_decades_expected = array(1500 => '1500s', 1510 => '1510s', 1520 => '1520s', 1530 => '1530s', 1540 => '1540s', 1550 => '1550s', 1560 => '1560s', 1570 => '1570s', 1580 => '1580s', 1590 => '1590s');
     $va_decades = $o_tep->normalizeDateRange($va_historic['start'], $va_historic['end'], 'decades');
     $this->assertEquals(10, sizeof($va_decades));
     $this->assertEquals($va_decades_expected, $va_decades);
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:9,代码来源:TimeExpressionParserTest.php

示例5: array

print $t_set->getLabelForDisplay();
?>
</div>
<div id="featuresDescription"><?php 
print $t_set->getSimpleAttributeValue('set_introduction');
?>
</div>
<div style="clear: both;"><!-- empty --></div>
<div>
<?php 
// Run through the facet and sort out occurrences by year
$va_exhibition_list_by_year = array();
foreach ($va_facet as $vn_id => $va_item) {
    $va_v = $va_item['ca_attribute_51'][0];
    // 51=the element_id of the "dates" attribute attached to each occurrence
    $va_normalized_v = $o_tep->normalizeDateRange($va_v['value_decimal1'], $va_v['value_decimal2'], 'years');
    // convert the exhibition date from a day-specific date range to a year
    $vn_year = array_shift($va_normalized_v);
    $va_exhibition_list_by_year[$vn_year][$va_v['value_decimal1']][$va_item['label']] = $va_item['id'];
    // array is key'ed by year, then by occurrence title; the value is the occurrence_id
}
//print_r($va_exhibition_list_by_year);
// Output occurrences
ksort($va_exhibition_list_by_year);
// sort by year
# --- public programs should be ordered in reverse chronological order
# --- see if we're displaying public programs by testing the vn_chronology_type_id (set above) against the occurrence type_id for public programs
# --- if they match, reverse the array
$t_list = new ca_lists();
$vn_public_program_type_id = $t_list->getItemIDFromList('occurrence_types', 'public_program');
if ($vn_public_program_type_id == $vn_chronology_type_id) {
开发者ID:guaykuru,项目名称:pawtucket,代码行数:31,代码来源:features_contents_chronology_html.php

示例6: getFacetContent


//.........这里部分代码省略.........
             $o_tep = new TimeExpressionParser();
             $vn_min_date = $vn_max_date = null;
             $vs_min_sql = $vs_max_sql = '';
             if (isset($va_facet_info['minimum_date'])) {
                 if ($o_tep->parse($va_facet_info['minimum_date'])) {
                     $va_tmp = $o_tep->getHistoricTimestamps();
                     $vn_min_date = (double) $va_tmp['start'];
                     $vs_min_sql = " AND (ca_attribute_values.value_decimal1 >= {$vn_min_date})";
                 }
             }
             if (isset($va_facet_info['maximum_date'])) {
                 if ($o_tep->parse($va_facet_info['maximum_date'])) {
                     $va_tmp = $o_tep->getHistoricTimestamps();
                     $vn_max_date = (double) $va_tmp['end'];
                     $vs_max_sql = " AND (ca_attribute_values.value_decimal2 <= {$vn_max_date})";
                 }
             }
             if ($vb_check_availability_only) {
                 $vs_sql = "\n\t\t\t\t\t\t\tSELECT 1\n\t\t\t\t\t\t\tFROM ca_attributes\n\t\t\t\t\t\t\t{$vs_join_sql}\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tca_attribute_values.element_id = ? \n\t\t\t\t\t\t\t\t{$vs_min_sql}\n\t\t\t\t\t\t\t\t{$vs_max_sql}\n\t\t\t\t\t\t\t\t{$vs_where_sql}\n\t\t\t\t\t\t\t\tLIMIT 1";
                 //print $vs_sql;
                 $qr_res = $this->opo_db->query($vs_sql, $vn_element_id);
                 return (int) $qr_res->numRows() > 0 ? true : false;
             } else {
                 $vs_sql = "\n\t\t\t\t\t\t\tSELECT DISTINCT ca_attribute_values.value_decimal1, ca_attribute_values.value_decimal2\n\t\t\t\t\t\t\tFROM ca_attributes\n\t\t\t\t\t\t\t{$vs_join_sql}\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tca_attribute_values.element_id = ? \n\t\t\t\t\t\t\t\t{$vs_min_sql}\n\t\t\t\t\t\t\t\t{$vs_max_sql}\n\t\t\t\t\t\t\t\t{$vs_where_sql}\n\t\t\t\t\t\t";
                 //print $vs_sql;
                 $qr_res = $this->opo_db->query($vs_sql, $vn_element_id);
                 $va_values = array();
                 while ($qr_res->nextRow()) {
                     $vn_start = $qr_res->get('value_decimal1');
                     $vn_end = $qr_res->get('value_decimal2');
                     if (!($vn_start && $vn_end)) {
                         continue;
                     }
                     $va_normalized_values = $o_tep->normalizeDateRange($vn_start, $vn_end, $vs_normalization);
                     foreach ($va_normalized_values as $vn_sort_value => $vs_normalized_value) {
                         if ($va_criteria[$vs_normalized_value]) {
                             continue;
                         }
                         // skip items that are used as browse critera - don't want to browse on something you're already browsing on
                         if (is_numeric($vs_normalized_value) && (int) $vs_normalized_value === 0) {
                             continue;
                         }
                         // don't include year=0
                         $va_values[$vn_sort_value][$vs_normalized_value] = array('id' => $vs_normalized_value, 'label' => $vs_normalized_value);
                         if (!is_null($vs_single_value) && $vs_normalized_value == $vs_single_value) {
                             $vb_single_value_is_present = true;
                         }
                     }
                 }
                 if (!is_null($vs_single_value) && !$vb_single_value_is_present) {
                     return array();
                 }
                 ksort($va_values);
                 if ($vs_dir == 'DESC') {
                     $va_values = array_reverse($va_values);
                 }
                 $va_sorted_values = array();
                 foreach ($va_values as $vn_sort_value => $va_values_for_sort_value) {
                     $va_sorted_values = array_merge($va_sorted_values, $va_values_for_sort_value);
                 }
                 return $va_sorted_values;
             }
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'authority':
开发者ID:guaykuru,项目名称:pawtucket,代码行数:67,代码来源:BrowseEngine.php


注:本文中的TimeExpressionParser::normalizeDateRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。