本文整理汇总了PHP中TimeExpressionParser::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP TimeExpressionParser::parse方法的具体用法?PHP TimeExpressionParser::parse怎么用?PHP TimeExpressionParser::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeExpressionParser
的用法示例。
在下文中一共展示了TimeExpressionParser::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGets
public function testGets()
{
$vm_ret = $this->opt_object->get('ca_objects.type_id', array('convertCodesToDisplayText' => true));
$this->assertEquals('Moving Image', $vm_ret);
$vm_ret = $this->opt_object->get('ca_objects.preferred_labels');
$this->assertEquals('My test moving image', $vm_ret);
$vm_ret = $this->opt_object->get('ca_objects.duration');
$this->assertEquals('0:23:28', $vm_ret);
$vm_ret = $this->opt_object->get('ca_objects.access');
$this->assertEquals('0', $vm_ret);
$vm_ret = $this->opt_object->get('ca_objects.access', array('convertCodesToDisplayText' => true));
$this->assertEquals('not accessible to public', $vm_ret);
$o_tep = new TimeExpressionParser();
$vn_now = time();
$vm_ret = $this->opt_object->get('ca_objects.lastModified');
$this->assertTrue($o_tep->parse($vm_ret));
$va_modified_unix = $o_tep->getUnixTimestamps();
//$this->assertEquals($vn_now, $va_modified_unix['start'], 'lastModified timestamp cannot be more than 1 minute off', 60);
}
示例2: testGets
public function testGets()
{
$vm_ret = $this->opt_object->get('ca_objects.type_id', array('convertCodesToDisplayText' => true));
$this->assertEquals('Moving Image', $vm_ret);
$vm_ret = $this->opt_object->get('ca_objects.preferred_labels');
$this->assertEquals('My test moving image', $vm_ret);
$vm_ret = $this->opt_object->get('ca_objects.duration');
$this->assertEquals('0:23:28', $vm_ret);
$vm_ret = $this->opt_object->get('ca_item_comments.comment');
$this->assertEquals('I like this very much.', $vm_ret);
$this->assertTrue(!is_numeric($this->opt_object->get('ca_item_comments.created_on')));
// should always be current date/time as text
$o_tep = new TimeExpressionParser();
$vn_now = time();
$vm_ret = $this->opt_object->get('ca_objects.lastModified');
$this->assertTrue($o_tep->parse($vm_ret));
$va_modified_unix = $o_tep->getUnixTimestamps();
//$this->assertEquals($vn_now, $va_modified_unix['start'], 'lastModified timestamp cannot be more than 1 minute off', 60);
}
示例3: parseValue
public function parseValue($ps_value, $pa_element_info, $pa_options = null)
{
$o_date_config = Configuration::load(__CA_CONF_DIR__ . '/datetime.conf');
$show_Undated = $o_date_config->get('showUndated');
$ps_value = trim($ps_value);
$va_settings = $this->getSettingValuesFromElementArray($pa_element_info, array('dateRangeBoundaries', 'mustNotBeBlank'));
if ($ps_value) {
if (!DateRangeAttributeValue::$o_tep->parse($ps_value)) {
// invalid date
$this->postError(1970, _t('%1 is invalid', $pa_element_info['displayLabel']), 'DateRangeAttributeValue->parseValue()');
return false;
}
$va_dates = DateRangeAttributeValue::$o_tep->getHistoricTimestamps();
if ($va_settings['dateRangeBoundaries']) {
if (DateRangeAttributeValue::$o_tep->parse($va_settings['dateRangeBoundaries'])) {
$va_boundary_dates = DateRangeAttributeValue::$o_tep->getHistoricTimestamps();
if ($va_dates[0] < $va_boundary_dates[0] || $va_dates[0] > $va_boundary_dates[1] || $va_dates[1] < $va_boundary_dates[0] || $va_dates[1] > $va_boundary_dates[1]) {
// date is out of bounds
$this->postError(1970, _t('%1 must be within %2', $pa_element_info['displayLabel'], $va_settings['dateRangeBoundaries']), 'DateRangeAttributeValue->parseValue()');
return false;
}
}
}
} else {
if ((bool) $va_settings['mustNotBeBlank']) {
$this->postError(1970, _t('%1 must not be empty', $pa_element_info['displayLabel']), 'DateRangeAttributeValue->parseValue()');
return false;
} else {
$o_date_config = Configuration::load(__CA_CONF_DIR__ . '/datetime.conf');
// Default to "undated" date for blanks
$vs_undated_date = '';
if ((bool) $o_date_config->get('showUndated')) {
$o_lang_config = DateRangeAttributeValue::$o_tep->getLanguageSettings();
$vs_undated_date = array_shift($o_lang_config->getList('undatedDate'));
}
return array('value_longtext1' => $vs_undated_date, 'value_decimal1' => null, 'value_decimal2' => null);
}
}
return array('value_longtext1' => $ps_value, 'value_decimal1' => $va_dates[0], 'value_decimal2' => $va_dates[1]);
}
示例4: search
/**
*
*/
public function search($ps_datetime_expression, $ps_code = null)
{
$o_tep = new TimeExpressionParser();
if ($o_tep->parse($ps_datetime_expression)) {
list($vn_period_start, $vn_period_end) = $o_tep->getUnixTimestamps();
if ($vn_period_start && $vn_period_end) {
$o_db = new Db();
$qr_log = $o_db->query("\n\t\t\t\t\tSELECT sl.*, u.fname, u.lname, u.email, sfl.name form\n\t\t\t\t\tFROM ca_search_log sl\n\t\t\t\t\tLEFT JOIN ca_users AS u ON sl.user_id = u.user_id\n\t\t\t\t\tLEFT JOIN ca_search_form_labels AS sfl ON sl.form_id = sfl.form_id\n\t\t\t\t\tWHERE \n\t\t\t\t\t\t(log_datetime BETWEEN {$vn_period_start} AND {$vn_period_end})\n\t\t\t\t\tORDER BY log_datetime DESC\n\t\t\t\t");
$o_dm = Datamodel::load();
$va_rows = array();
while ($qr_log->nextRow()) {
$va_row = $qr_log->getRow();
$t_table = $o_dm->getInstanceByTableNum($va_row['table_num'], true);
$va_row['table_name'] = $t_table->getProperty('NAME_PLURAL');
$va_row['user_name'] = $va_row['fname'] . ' ' . $va_row['lname'];
$va_rows[$va_row['search_id']] = $va_row;
}
return $va_rows;
}
}
return null;
}
示例5: caGetISODates
/**
*
*
* @param string $ps_date_expression Start of date range, as Unix timestamp
* @param array $pa_options All options supported by TimeExpressionParser::getText() are supported
*
* @return array
*/
function caGetISODates($ps_date_expression, $pa_options = null)
{
if (!is_array($pa_options)) {
$pa_options = array();
}
$o_tep = new TimeExpressionParser();
if (!$o_tep->parse($ps_date_expression)) {
return null;
}
return array('start' => $o_tep->getText(array_merge($pa_options, array('start_as_iso8601' => true))), 'end' => $o_tep->getText(array_merge($pa_options, array('end_as_iso8601' => true))));
}
示例6: now
/**
* Return current date/time
*
* @param array $pa_options Options include:
* format = format of return value. Options are:
* unix = Unix-timestamp
* historic = Historic timestamp
* [Default is historic]
*
*/
public static function now($pa_options = null)
{
$ps_format = caGetOption('format', $pa_options, null, ['toLowerCase' => true]);
$o_tep = new TimeExpressionParser();
$o_tep->parse(__TEP_NOW__);
switch ($ps_format) {
case 'unix':
return array_shift($o_tep->getUnixTimestamps());
break;
case 'historic':
default:
return array_shift($o_tep->getHistoricTimestamps());
break;
}
return null;
}
示例7: search
/**
*
*/
public function search($ps_datetime_expression, $ps_code = null)
{
$o_tep = new TimeExpressionParser();
if ($o_tep->parse($ps_datetime_expression)) {
list($vn_period_start, $vn_period_end) = $o_tep->getUnixTimestamps();
if ($vn_period_start && $vn_period_end) {
$o_db = new Db();
$qr_codes = $o_db->query("SELECT DISTINCT code FROM ca_eventlog ORDER BY code");
$va_codes = array();
while ($qr_codes->nextRow()) {
$va_codes[] = $qr_codes->get("code");
}
if (in_array($ps_code, $va_codes)) {
$qr_log = $o_db->query("\n\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\tFROM ca_eventlog\n\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t(date_time BETWEEN {$vn_period_start} AND {$vn_period_end}) \n\t\t\t\t\t\t\tAND (code = ?)\n\t\t\t\t\t\tORDER BY date_time DESC\n\t\t\t\t\t", $ps_code);
} else {
$qr_log = $o_db->query("\n\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\tFROM ca_eventlog\n\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t(date_time BETWEEN {$vn_period_start} AND {$vn_period_end})\n\t\t\t\t\t\tORDER BY date_time DESC\n\t\t\t\t\t");
}
return $qr_log->getAllRows();
}
}
return null;
}
示例8: parseValue
public function parseValue($ps_value, $pa_element_info, $pa_options = null)
{
$ps_value = trim($ps_value);
$va_settings = $this->getSettingValuesFromElementArray($pa_element_info, array('dateRangeBoundaries', 'mustNotBeBlank'));
$o_tep = new TimeExpressionParser();
if ($ps_value) {
if (!$o_tep->parse($ps_value)) {
// invalid date
$this->postError(1970, _t('%1 is invalid', $pa_element_info['displayLabel']), 'DateRangeAttributeValue->parseValue()');
return false;
}
$va_dates = $o_tep->getHistoricTimestamps();
if ($va_settings['dateRangeBoundaries']) {
if ($o_tep->parse($va_settings['dateRangeBoundaries'])) {
$va_boundary_dates = $o_tep->getHistoricTimestamps();
if ($va_dates[0] < $va_boundary_dates[0] || $va_dates[0] > $va_boundary_dates[1] || $va_dates[1] < $va_boundary_dates[0] || $va_dates[1] > $va_boundary_dates[1]) {
// date is out of bounds
$this->postError(1970, _t('%1 must be within %2', $pa_element_info['displayLabel'], $va_settings['dateRangeBoundaries']), 'DateRangeAttributeValue->parseValue()');
return false;
}
}
}
} else {
if ((bool) $va_settings['mustNotBeBlank']) {
$this->postError(1970, _t('%1 must not be empty', $pa_element_info['displayLabel']), 'DateRangeAttributeValue->parseValue()');
return false;
} else {
// Default to "undated" date for blanks
$o_config = $o_tep->getLanguageSettings();
$va_undated_dates = $o_config->getList('undatedDate');
return array('value_longtext1' => $va_undated_dates[0], 'value_decimal1' => null, 'value_decimal2' => null);
}
}
return array('value_longtext1' => $ps_value, 'value_decimal1' => $va_dates[0], 'value_decimal2' => $va_dates[1]);
}
示例9: getMessages
/**
* Gets list of messages conforming to specified options.
* @param array $pa_options
* readOnly =
* unreadOnly =
* user_id =
* created_on =
* transaction_id =
* type =
* @return array
*/
public function getMessages($pn_user_id, $pa_options = null)
{
$o_db = $this->getDb();
$pb_read_only = (bool) (isset($pa_options['readOnly']) && $pa_options['readOnly']);
$pb_unread_only = (bool) (isset($pa_options['unreadOnly']) && $pa_options['unreadOnly']);
$pn_restrict_to_transaction_user_id = isset($pa_options['user_id']) && (int) $pa_options['user_id'] ? (int) $pa_options['user_id'] : null;
$ps_created_on = isset($pa_options['created_on']) && (string) $pa_options['created_on'] ? (string) $pa_options['created_on'] : null;
$va_sql_wheres = array();
$va_sql_params = array();
if ($pn_restrict_to_transaction_user_id) {
$va_sql_wheres[] = "tra.user_id = ?";
$va_sql_params[] = $pn_restrict_to_transaction_user_id;
}
if (is_array($pa_options) && array_key_exists('transaction_id', $pa_options)) {
$va_sql_wheres[] = "tra.transaction_id = ?";
$va_sql_params[] = (int) $pa_options['transaction_id'];
}
if ($ps_created_on) {
$o_tep = new TimeExpressionParser();
if ($o_tep->parse($ps_created_on) && ($va_dates = $o_tep->getUnixTimestamps())) {
$va_sql_wheres[] = "(comm.created_on BETWEEN ? AND ?)";
$va_sql_params[] = $va_dates['start'];
$va_sql_params[] = $va_dates['end'];
}
}
if (isset($pa_options['type']) && in_array($pa_options['type'], array('O', 'L'))) {
$va_sql_wheres[] = "(comm.communication_type = ?)";
$va_sql_params[] = (string) $pa_options['type'];
}
if (isset($pa_options['search']) && strlen($pa_options['search'])) {
$o_search = new CommerceCommunicationSearch();
if ($qr_hits = $o_search->search($pa_options['search'])) {
$va_ids = array();
while ($qr_hits->nextHit()) {
$va_ids[] = $qr_hits->get('communication_id');
}
if (sizeof($va_ids)) {
$va_sql_wheres[] = "(comm.communication_id IN (?))";
$va_sql_params[] = $va_ids;
} else {
$va_sql_wheres[] = "(comm.communication_id = 0)";
}
}
}
if ($pb_read_only) {
$va_sql_wheres[] = "(comm.read_on IS NOT NULL) AND (comm.from_user_id <> " . (int) $pn_user_id . ")";
}
if ($pb_unread_only) {
$va_sql_wheres[] = "(comm.read_on IS NULL) AND (comm.from_user_id <> " . (int) $pn_user_id . ")";
}
$qr_res = $o_db->query($vs_sql = "\n\t \t\tSELECT comm.*, tra.short_description, tra.transaction_id, tra.created_on transaction_created_on, tra.set_id\n\t \t\tFROM ca_commerce_communications comm\n\t \t\tINNER JOIN ca_commerce_transactions AS tra ON tra.transaction_id = comm.transaction_id\n\t \t\t" . (sizeof($va_sql_wheres) ? " WHERE " . join(" AND ", $va_sql_wheres) : '') . "\n\t \t\tORDER BY\n\t \t\t\tcomm.created_on DESC\n\t \t", $va_sql_params);
//print $vs_sql;
$va_messages = array();
while ($qr_res->nextRow()) {
$va_messages[$qr_res->get('transaction_id')][] = $qr_res->getRow();
}
return $va_messages;
}
示例10: getFacetContent
//.........这里部分代码省略.........
}
if ($vs_browse_type_limit_sql) {
$va_wheres[] = $vs_browse_type_limit_sql;
}
if ($t_item->hasField('deleted')) {
$va_wheres[] = "(" . $vs_browse_table_name . ".deleted = 0)";
}
if ($va_facet_info['relative_to']) {
if ($t_subject->hasField('deleted')) {
$va_wheres[] = "(" . $t_subject->tableName() . ".deleted = 0)";
}
if ($va_relative_sql_data = $this->_getRelativeFacetSQLData($va_facet_info['relative_to'], $pa_options)) {
$va_joins = array_merge($va_joins, $va_relative_sql_data['joins']);
$va_wheres = array_merge($va_wheres, $va_relative_sql_data['wheres']);
}
}
if ($this->opo_config->get('perform_item_level_access_checking')) {
if ($t_item = $this->opo_datamodel->getInstanceByTableName($vs_browse_table_name, true)) {
// Join to limit what browse table items are used to generate facet
$va_joins[] = 'LEFT JOIN ca_acl ON ' . $vs_browse_table_name . '.' . $t_item->primaryKey() . ' = ca_acl.row_id AND ca_acl.table_num = ' . $t_item->tableNum() . "\n";
$va_wheres[] = "(\n\t\t\t\t\t\t\t\t((\n\t\t\t\t\t\t\t\t\t(ca_acl.user_id = " . (int) $vn_user_id . ")\n\t\t\t\t\t\t\t\t\t" . (sizeof($va_group_ids) > 0 ? "OR\n\t\t\t\t\t\t\t\t\t(ca_acl.group_id IN (" . join(",", $va_group_ids) . "))" : "") . "\n\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t(ca_acl.user_id IS NULL and ca_acl.group_id IS NULL)\n\t\t\t\t\t\t\t\t) AND ca_acl.access >= " . __CA_ACL_READONLY_ACCESS__ . ")\n\t\t\t\t\t\t\t\t" . ($vb_show_if_no_acl ? "OR ca_acl.acl_id IS NULL" : "") . "\n\t\t\t\t\t\t\t)";
}
}
$vs_join_sql = join("\n", $va_joins);
$vs_where_sql = '';
if (is_array($va_wheres) && sizeof($va_wheres) && ($vs_where_sql = join(' AND ', $va_wheres))) {
$vs_where_sql = ' AND (' . $vs_where_sql . ')';
}
$vs_dir = strtoupper($va_facet_info['sort']) === 'DESC' ? "DESC" : "ASC";
$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;
示例11: getOrders
//.........这里部分代码省略.........
if (is_array($va_dates = caDateToUnixTimestamps($pa_options['created_on']))) {
$va_sql_wheres[] = "(o.created_on BETWEEN ? AND ?)";
$va_sql_values[] = (double) $va_dates['start'];
$va_sql_values[] = (double) $va_dates['end'];
}
}
if (isset($pa_options['object_id']) && strlen($pa_options['object_id'])) {
$va_sql_wheres[] = "(i.object_id = ?)";
$va_sql_values[] = (int) $pa_options['object_id'];
}
if (isset($pa_options['loan_checkout_date']) && strlen($pa_options['loan_checkout_date'])) {
if (is_array($va_dates = caDateToUnixTimestamps($pa_options['loan_checkout_date']))) {
$va_sql_wheres[] = "(i.loan_checkout_date BETWEEN ? AND ?)";
$va_sql_values[] = (double) $va_dates['start'];
$va_sql_values[] = (double) $va_dates['end'];
}
}
if (isset($pa_options['loan_due_date']) && strlen($pa_options['loan_due_date'])) {
if (is_array($va_dates = caDateToUnixTimestamps($pa_options['loan_due_date']))) {
$va_sql_wheres[] = "(i.loan_due_date BETWEEN ? AND ?)";
$va_sql_values[] = (double) $va_dates['start'];
$va_sql_values[] = (double) $va_dates['end'];
}
}
if (isset($pa_options['loan_return_date']) && strlen($pa_options['loan_return_date'])) {
if (is_array($va_dates = caDateToUnixTimestamps($pa_options['loan_return_date']))) {
$va_sql_wheres[] = "(i.loan_return_date BETWEEN ? AND ?)";
$va_sql_values[] = (double) $va_dates['start'];
$va_sql_values[] = (double) $va_dates['end'];
}
}
if (isset($pa_options['shipping_date']) && strlen($pa_options['shipping_date'])) {
$o_tep = new TimeExpressionParser();
if ($o_tep->parse($pa_options['shipping_date'])) {
$va_dates = $o_tep->getUnixTimestamps();
$va_sql_wheres[] = "(o.shipping_date BETWEEN ? AND ?)";
$va_sql_values[] = (double) $va_dates['start'];
$va_sql_values[] = (double) $va_dates['end'];
}
}
if (isset($pa_options['shipped_on_date']) && strlen($pa_options['shipped_on_date'])) {
$o_tep = new TimeExpressionParser();
if ($o_tep->parse($pa_options['shipped_on_date'])) {
$va_dates = $o_tep->getUnixTimestamps();
$va_sql_wheres[] = "(o.shipped_on_date BETWEEN ? AND ?)";
$va_sql_values[] = (double) $va_dates['start'];
$va_sql_values[] = (double) $va_dates['end'];
}
}
if (isset($pa_options['search']) && strlen($pa_options['search'])) {
$o_search = new CommerceOrderSearch();
if ($qr_hits = $o_search->search($pa_options['search'])) {
$va_ids = array();
while ($qr_hits->nextHit()) {
$va_ids[] = $qr_hits->get('order_id');
}
if (sizeof($va_ids)) {
$va_sql_wheres[] = "(o.order_id IN (?))";
$va_sql_values[] = $va_ids;
} else {
$va_sql_wheres[] = "(o.order_id = 0)";
}
}
}
$vs_sql_wheres = '';
if (sizeof($va_sql_wheres)) {
示例12: refine
/**
*
*/
public function refine(&$pa_destination_data, $pa_group, $pa_item, $pa_source_data, $pa_options = null)
{
$o_log = isset($pa_options['log']) && is_object($pa_options['log']) ? $pa_options['log'] : null;
$pm_value = $pa_source_data[$pa_item['source']];
// not actually used
$va_item_dest = explode(".", $pa_item['destination']);
$vs_item_terminal = array_pop($va_item_dest);
$vs_group_terminal = array_pop($va_item_dest);
$o_tep = new TimeExpressionParser();
$o_tep->setLanguage('en_US');
switch ($vs_mode = $pa_item['settings']['dateJoiner_mode']) {
default:
case 'range':
$vs_date_expression = $pa_item['settings']['dateJoiner_expression'];
$vs_date_start = $pa_item['settings']['dateJoiner_start'];
$vs_date_end = $pa_item['settings']['dateJoiner_end'];
if ($vs_date_expression && ($vs_exp = BaseRefinery::parsePlaceholder($vs_date_expression, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
if ($o_tep->parse($vs_exp)) {
return $o_tep->getText();
} else {
if ($o_log) {
$o_log->logWarn(_t('[dateJoinerRefinery] Could not parse date expression %1 assembled from range', $vs_exp));
}
}
}
$va_date = array();
if ($vs_date_start = BaseRefinery::parsePlaceholder($vs_date_start, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' '))) {
if (!($vs_skip_start_exp = $pa_item['settings']['dateJoiner_skipStartIfExpression']) || !ExpressionParser::evaluate($vs_skip_start_exp, array_merge($pa_source_data, array('start' => $vs_date_start, 'end' => $vs_date_end, 'expression' => $ps_expression)))) {
$va_date[] = $vs_date_start;
} elseif ($vs_skip_start_replacement = $pa_item['settings']['dateJoiner_skipStartIfExpressionReplacementValue']) {
$va_date[] = $vs_skip_start_replacement;
}
}
if ($vs_date_end = BaseRefinery::parsePlaceholder($vs_date_end, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' '))) {
if (!($vs_skip_end_exp = $pa_item['settings']['dateJoiner_skipEndIfExpression']) || !ExpressionParser::evaluate($vs_skip_end_exp, array_merge($pa_source_data, array('start' => $vs_date_start, 'end' => $vs_date_end, 'expression' => $ps_expression)))) {
$va_date[] = $vs_date_end;
} elseif ($vs_skip_end_replacement = $pa_item['settings']['dateJoiner_skipEndIfExpressionReplacementValue']) {
$va_date[] = $vs_skip_end_replacement;
}
}
foreach ($va_date as $vn_i => $vs_date) {
$va_date[$vn_i] = preg_replace("![^\\d]+\$!", "", $vs_date);
}
$vs_date_expression = join(" - ", $va_date);
if ($vs_date_expression && ($vs_exp = BaseRefinery::parsePlaceholder($vs_date_expression, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
if ($o_tep->parse($vs_exp)) {
return $o_tep->getText();
} else {
if ($o_log) {
$o_log->logWarn(_t('[dateJoinerRefinery] Could not parse date expression %1 assembled from range', $vs_exp));
}
}
}
break;
case 'multiColumnDate':
$va_month_list = $o_tep->getMonthList();
$va_date = array();
if ($vs_date_month = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_month'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
if (($vn_m = array_search($vs_date_month, $va_month_list)) !== false) {
$vs_date_month = $vn_m + 1;
}
$va_date[] = $vs_date_month;
}
if ($vs_date_day = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_day'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
$va_date[] = $vs_date_day;
}
if ($vs_date_year = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_year'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
$va_date[] = $vs_date_year;
}
if (sizeof($va_date)) {
// TODO: this is assuming US-style dates for now
if ($o_tep->parse(join("/", $va_date))) {
return $o_tep->getText();
} else {
if ($o_log) {
$o_log->logWarn(_t('[dateJoinerRefinery] Could not parse date expression %1 assembled from multiColumnDate', join("/", $va_date)));
}
}
}
break;
case 'multiColumnRange':
$va_dates = array();
$va_month_list = $o_tep->getMonthList();
// Process start date
$va_date = array();
if ($vs_date_month = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_startMonth'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
if (($vn_m = array_search($vs_date_month, $va_month_list)) !== false) {
$vs_date_month = $vn_m + 1;
}
$va_date[] = $vs_date_month;
}
if ($vs_date_day = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_startDay'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
$va_date[] = $vs_date_day;
}
if ($vs_date_year = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_startYear'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
$va_date[] = $vs_date_year;
}
//.........这里部分代码省略.........
示例13: caCalculateDateRangeAvgInDays
function caCalculateDateRangeAvgInDays()
{
$va_date_ranges = func_get_args();
$o_tep = new TimeExpressionParser();
$va_days = array();
foreach ($va_date_ranges as $vs_date_range) {
if (!$o_tep->parse($vs_date_range)) {
print "no parse {$vs_date_range}";
return false;
}
$va_arg_historic_stamps = $o_tep->getHistoricTimestamps();
$va_start_parts = $o_tep->getHistoricDateParts($va_arg_historic_stamps['start']);
$va_end_parts = $o_tep->getHistoricDateParts($va_arg_historic_stamps['end']);
$vs_start = $o_tep->getISODateTime($va_start_parts);
$vs_end = $o_tep->getISODateTime($va_end_parts);
$o_start = new DateTime($vs_start);
$o_end = new DateTime($vs_end);
$va_days[] = $o_start->diff($o_end)->days;
}
if (sizeof($va_days)) {
return array_sum($va_days) / sizeof($va_days);
} else {
return false;
}
}
示例14: getFacetContent
//.........这里部分代码省略.........
$va_wheres[] = $vs_browse_type_limit_sql;
}
if ($t_item->hasField('deleted')) {
$va_wheres[] = "(" . $vs_browse_table_name . ".deleted = 0)";
}
if ($va_facet_info['relative_to']) {
if ($t_subject->hasField('deleted')) {
$va_wheres[] = "(" . $t_subject->tableName() . ".deleted = 0)";
}
if ($va_relative_sql_data = $this->_getRelativeFacetSQLData($va_facet_info['relative_to'], $pa_options)) {
$va_joins = array_merge($va_joins, $va_relative_sql_data['joins']);
$va_wheres = array_merge($va_wheres, $va_relative_sql_data['wheres']);
}
}
if ($this->opo_config->get('perform_item_level_access_checking')) {
if ($t_item = $this->opo_datamodel->getInstanceByTableName($vs_browse_table_name, true)) {
// Join to limit what browse table items are used to generate facet
$va_joins[] = 'LEFT JOIN ca_acl ON ' . $vs_browse_table_name . '.' . $t_item->primaryKey() . ' = ca_acl.row_id AND ca_acl.table_num = ' . $t_item->tableNum() . "\n";
$va_wheres[] = "(\n\t\t\t\t\t\t\t\t((\n\t\t\t\t\t\t\t\t\t(ca_acl.user_id = " . (int) $vn_user_id . ")\n\t\t\t\t\t\t\t\t\t" . (sizeof($va_group_ids) > 0 ? "OR\n\t\t\t\t\t\t\t\t\t(ca_acl.group_id IN (" . join(",", $va_group_ids) . "))" : "") . "\n\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t(ca_acl.user_id IS NULL and ca_acl.group_id IS NULL)\n\t\t\t\t\t\t\t\t) AND ca_acl.access >= " . __CA_ACL_READONLY_ACCESS__ . ")\n\t\t\t\t\t\t\t\t" . ($vb_show_if_no_acl ? "OR ca_acl.acl_id IS NULL" : "") . "\n\t\t\t\t\t\t\t)";
}
}
$vs_where_sql = '';
if (is_array($va_wheres) && sizeof($va_wheres) && ($vs_where_sql = join(' AND ', $va_wheres))) {
$vs_where_sql = ' AND (' . $vs_where_sql . ')';
}
$vs_join_sql = join("\n", $va_joins);
if ($vb_is_element) {
$vn_element_id = $t_element->getPrimaryKey();
$vs_dir = strtoupper($va_facet_info['sort']) === 'DESC' ? "DESC" : "ASC";
$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\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;
}
示例15: testIncompleteRanges
public function testIncompleteRanges()
{
$o_tep = new TimeExpressionParser();
$o_tep->setLanguage('en_US');
$va_date = getDate();
$vb_res = $o_tep->parse('August 20 - 27 2011');
$this->assertEquals($vb_res, true);
$va_parse = $o_tep->getHistoricTimestamps();
$this->assertEquals($va_parse['start'], '2011.082000000000');
$this->assertEquals($va_parse['end'], '2011.082723595900');
$vb_res = $o_tep->parse('August 20 - 27');
$this->assertEquals($vb_res, true);
$va_parse = $o_tep->getHistoricTimestamps();
$this->assertEquals($va_parse['start'], $va_date['year'] . '.082000000000');
$this->assertEquals($va_parse['end'], $va_date['year'] . '.082723595900');
$vb_res = $o_tep->parse('March - June 1850');
$this->assertEquals($vb_res, true);
$va_parse = $o_tep->getHistoricTimestamps();
$this->assertEquals($va_parse['start'], '1850.030100000000');
$this->assertEquals($va_parse['end'], '1850.063023595900');
}