本文整理汇总了PHP中EM_Event::get_fields方法的典型用法代码示例。如果您正苦于以下问题:PHP EM_Event::get_fields方法的具体用法?PHP EM_Event::get_fields怎么用?PHP EM_Event::get_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EM_Event
的用法示例。
在下文中一共展示了EM_Event::get_fields方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Returns an array of EM_Events that match the given specs in the argument, or returns a list of future evetnts in future
* (see EM_Events::get_default_search() ) for explanation of possible search array values. You can also supply a numeric array
* containing the ids of the events you'd like to obtain
*
* @param array $args
* @return EM_Event array()
*/
function get($args = array(), $count = false)
{
global $wpdb;
$events_table = EM_EVENTS_TABLE;
$locations_table = EM_LOCATIONS_TABLE;
//Quick version, we can accept an array of IDs, which is easy to retrieve
if (self::array_is_numeric($args)) {
//Array of numbers, assume they are event IDs to retreive
//We can just get all the events here and return them
$sql = "\n\t\t\t\tSELECT * FROM {$events_table}\n\t\t\t\tLEFT JOIN {$locations_table} ON {$locations_table}.location_id={$events_table}.location_id\n\t\t\t\tWHERE event_id=" . implode(" OR event_id=", $args) . "\n\t\t\t";
$results = $wpdb->get_results(apply_filters('em_events_get_sql', $sql), ARRAY_A);
$events = array();
foreach ($results as $result) {
$events[$result['event_id']] = new EM_Event($result);
}
return $events;
//We return all the events matched as an EM_Event array.
}
//We assume it's either an empty array or array of search arguments to merge with defaults
$args = self::get_default_search($args);
$limit = $args['limit'] && is_numeric($args['limit']) ? "LIMIT {$args['limit']}" : '';
$offset = $limit != "" && is_numeric($args['offset']) ? "OFFSET {$args['offset']}" : '';
//Get the default conditions
$conditions = self::build_sql_conditions($args);
//Put it all together
$where = count($conditions) > 0 ? " WHERE " . implode(" AND ", $conditions) : '';
//Get ordering instructions
$EM_Event = new EM_Event();
$accepted_fields = $EM_Event->get_fields(true);
$orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order'));
//Now, build orderby sql
$orderby_sql = count($orderby) > 0 ? 'ORDER BY ' . implode(', ', $orderby) : '';
//Create the SQL statement and execute
$selectors = $count ? 'COUNT(*)' : '*';
$sql = "\n\t\t\tSELECT {$selectors} FROM {$events_table}\n\t\t\tLEFT JOIN {$locations_table} ON {$locations_table}.location_id={$events_table}.location_id\n\t\t\t{$where}\n\t\t\t{$orderby_sql}\n\t\t\t{$limit} {$offset}\n\t\t";
//If we're only counting results, return the number of results
if ($count) {
return $wpdb->get_var($sql);
}
$results = $wpdb->get_results(apply_filters('em_events_get_sql', $sql, $args), ARRAY_A);
//If we want results directly in an array, why not have a shortcut here?
if ($args['array'] == true) {
return $results;
}
//Make returned results EM_Event objects
$results = is_array($results) ? $results : array();
$events = array();
foreach ($results as $event) {
$events[] = new EM_Event($event);
}
return apply_filters('em_events_get', $events, $args);
}
示例2: get
/**
* Returns an array of EM_Location objects
* @param boolean $eventful
* @param boolean $return_objects
* @return array
*/
function get($args = array())
{
global $wpdb;
$events_table = $wpdb->prefix . EM_EVENTS_TABLE;
$locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
//Quick version, we can accept an array of IDs, which is easy to retrieve
if (self::array_is_numeric($args) && count()) {
//Array of numbers, assume they are event IDs to retreive
//We can just get all the events here and return them
$sql = "SELECT * FROM {$locations_table} WHERE location_id=" . implode(" OR location_id=", $args);
$results = $wpdb->get_results($sql, ARRAY_A);
$events = array();
foreach ($results as $result) {
$locations[$result['location_id']] = new EM_Location($result);
}
return $locations;
//We return all the events matched as an EM_Event array.
}
//We assume it's either an empty array or array of search arguments to merge with defaults
$args = self::get_default_search($args);
$limit = $args['limit'] && is_numeric($args['limit']) ? "LIMIT {$args['limit']}" : '';
$offset = $limit != "" && is_numeric($args['offset']) ? "OFFSET {$args['offset']}" : '';
//Get the default conditions
$conditions = self::build_sql_conditions($args);
//Put it all together
$EM_Location = new EM_Location(0);
//Empty class for strict message avoidance
$fields = $locations_table . "." . implode(", {$locations_table}.", array_keys($EM_Location->fields));
$where = count($conditions) > 0 ? " WHERE " . implode(" AND ", $conditions) : '';
//Get ordering instructions
$EM_Event = new EM_Event();
//blank event for below
$accepted_fields = $EM_Location->get_fields(true);
$accepted_fields = array_merge($EM_Event->get_fields(true), $accepted_fields);
$orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order'));
//Now, build orderby sql
$orderby_sql = count($orderby) > 0 ? 'ORDER BY ' . implode(', ', $orderby) : '';
//Create the SQL statement and execute
$sql = "\n\t\t\tSELECT {$fields} FROM {$locations_table}\n\t\t\tLEFT JOIN {$events_table} ON {$locations_table}.location_id={$events_table}.location_id\n\t\t\t{$where}\n\t\t\tGROUP BY location_id\n\t\t\t{$orderby_sql}\n\t\t\t{$limit} {$offset}\n\t\t";
$results = $wpdb->get_results($sql, ARRAY_A);
//If we want results directly in an array, why not have a shortcut here?
if ($args['array'] == true) {
return $results;
}
$locations = array();
foreach ($results as $location) {
$locations[] = new EM_Location($location);
}
return apply_filters('em_locations_get', $locations, $args);
}
示例3: get
/**
* Returns an array of EM_Location objects
* @param boolean $eventful
* @param boolean $return_objects
* @return array
*/
public static function get($args = array(), $count = false)
{
global $wpdb;
$events_table = EM_EVENTS_TABLE;
$locations_table = EM_LOCATIONS_TABLE;
$locations = array();
//Quick version, we can accept an array of IDs, which is easy to retrieve
if (self::array_is_numeric($args)) {
//Array of numbers, assume they are event IDs to retreive
//We can just get all the events here and return them
$sql = "SELECT * FROM {$locations_table} WHERE location_id=" . implode(" OR location_id=", $args);
$results = $wpdb->get_results($sql, ARRAY_A);
$events = array();
foreach ($results as $result) {
$locations[$result['location_id']] = new EM_Location($result);
}
return apply_filters('em_locations_get', $locations, $args);
//We return all the events matched as an EM_Event array.
} elseif (is_numeric($args)) {
//return an event in the usual array format
return apply_filters('em_locations_get', array(new EM_Location($args)), $args);
} elseif (is_array($args) && is_object(current($args)) && get_class(current($args)) == 'EM_Location') {
return apply_filters('em_locations_get', $args, $args);
}
//We assume it's either an empty array or array of search arguments to merge with defaults
$args = self::get_default_search($args);
$limit = $args['limit'] && is_numeric($args['limit']) ? "LIMIT {$args['limit']}" : '';
$offset = $limit != "" && is_numeric($args['offset']) ? "OFFSET {$args['offset']}" : '';
//Get the default conditions
$conditions = self::build_sql_conditions($args);
//Put it all together
$EM_Location = new EM_Location(0);
//Empty class for strict message avoidance
$fields = $locations_table . "." . implode(", {$locations_table}.", array_keys($EM_Location->fields));
$where = count($conditions) > 0 ? " WHERE " . implode(" AND ", $conditions) : '';
//Get ordering instructions
$EM_Event = new EM_Event();
//blank event for below
$accepted_fields = $EM_Location->get_fields(true);
$accepted_fields = array_merge($EM_Event->get_fields(true), $accepted_fields);
$orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order'));
//Now, build orderby sql
$orderby_sql = count($orderby) > 0 ? 'ORDER BY ' . implode(', ', $orderby) : '';
$fields = $count ? $locations_table . '.location_id' : $locations_table . '.post_id';
if (EM_MS_GLOBAL) {
$selectors = $count ? 'COUNT(' . $locations_table . '.location_id)' : $locations_table . '.post_id, ' . $locations_table . '.blog_id';
} else {
$selectors = $count ? 'COUNT(' . $locations_table . '.location_id)' : $locations_table . '.post_id';
}
//Create the SQL statement and execute
$sql = "\r\n\t\t\tSELECT {$selectors} FROM {$locations_table}\r\n\t\t\tLEFT JOIN {$events_table} ON {$locations_table}.location_id={$events_table}.location_id\r\n\t\t\t{$where}\r\n\t\t\tGROUP BY {$locations_table}.location_id\r\n\t\t\t{$orderby_sql}\r\n\t\t\t{$limit} {$offset}\r\n\t\t";
//If we're only counting results, return the number of results
if ($count) {
return apply_filters('em_locations_get_array', count($wpdb->get_col($sql)), $args);
}
$results = $wpdb->get_results($sql, ARRAY_A);
//If we want results directly in an array, why not have a shortcut here?
if ($args['array'] == true) {
return apply_filters('em_locations_get_array', $results, $args);
}
if (EM_MS_GLOBAL) {
foreach ($results as $location) {
if (empty($location['blog_id'])) {
$location['blog_id'] = get_current_site()->blog_id;
}
$locations[] = em_get_location($location['post_id'], $location['blog_id']);
}
} else {
foreach ($results as $location) {
$locations[] = em_get_location($location['post_id'], 'post_id');
}
}
return apply_filters('em_locations_get', $locations, $args);
}