晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/rainic/www/oldTZh/wp-content/plugins/gravityforms/includes/orders/ |
Upload File : |
<?php
namespace Gravity_Forms\Gravity_Forms\Orders;
use Gravity_Forms\Gravity_Forms\Orders\Items\GF_Order_Item;
use Gravity_Forms\Gravity_Forms\Orders\Items\GF_Form_Product_Item;
final class GF_Order {
/**
* The order items.
*
* Contains the items grouped by item type.
*
* @since 2.6
*
* @var GF_Order_Item[]
*/
private $items = array();
/**
* Contains all the calculated totals for the order, like sub total, discounts, and final total.
*
* @since 2.6
*
* @var array
*/
private $totals = array();
/**
* The order items groups.
*
* Contains the items grouped by their location in the final order summary.
*
* @since 2.6
*
* @var array[]
*/
private $groups = array(
'body' => array(),
'footer' => array(),
);
/**
* The order currency.
*
* @since 2.6
*
* @var string
*/
public $currency;
/**
* Adds a group of items to the order.
*
* @since 2.6
*
* @param GF_Order_Item[] $items
*/
public function add_items( $items = array() ) {
foreach ( $items as $item ) {
$this->add_item( $item );
}
}
/**
* Adds a single item to the order.
*
* @since 2.6
*
* @param GF_Order_Item $item
*
* @return bool
*/
public function add_item( $item ) {
if ( ! is_a( $item, 'Gravity_Forms\Gravity_Forms\Orders\Items\GF_Order_Item' ) ) {
return false;
}
$item->currency = $this->currency;
if ( ! isset( $this->items[ $item->type ] ) ) {
$this->items[ $item->type ] = array();
}
if ( isset( $this->items[ $item->type ][ $item->get_id() ] ) ) {
return false;
}
$this->items[ $item->type ][ $item->get_id() ] = $item;
if ( ! isset( $this->groups[ $item->belongs_to ] ) ) {
$this->groups[ $item->belongs_to ] = array();
}
$this->groups[ $item->belongs_to ][ $item->get_id() ] = $item;
return true;
}
/**
* Returns a collection of items by item type or all items.
*
* @since 2.6
*
* @param null|string $type The item type to look for.
*
* @return array|GF_Order_Item An empty array if no items found or the items.
*/
public function get_items( $type = null ) {
if ( $type ) {
return $this->items[ $type ];
} else {
$all_items = array();
foreach ( $this->items as $items ) {
foreach ( $items as $item ) {
$all_items[ $item->get_id() ] = $item;
}
}
return $all_items;
}
return array();
}
/**
* Returns a collection of items by item class type.
*
* Item types can be represented by a string, for example a collection of GF_Form_Product_Item added to a type called "recurring".
*
* @since 2.6
*
* @param string $type The item class to look for.
*
* @return array|GF_Order_Item An empty array if no items found or the items.
*/
public function get_items_by_class_type( $type ) {
$items = $this->get_items();
$filtered = array();
foreach ( $items as $item ) {
if ( is_a( $item, $type ) ) {
$filtered[ $item->get_id() ] = $item;
}
}
return $filtered;
}
/**
* Returns a collection of items excluding a certain class type.
*
* @since 2.6
*
* @param string $type The item class to look for.
*
* @return array|GF_Order_Item An empty array if no items found or the items.
*/
public function get_items_exclude_class_type( $type ) {
$items = $this->get_items();
$filtered = $this->get_items_by_class_type( $type );
return array_diff_key( $items, $filtered );
}
/**
* Deletes an item from the order.
*
* @since 2.6
*
* @param string $id The item ID.
*
* @return bool
*/
public function delete_item( $id ) {
$item = $this->get_item( $id );
if ( $item ) {
unset( $this->items[ $item->type ][ $id ] );
unset( $this->groups[ $item->belongs_to ][ $id ] );
$this->totals = array();
return true;
}
return false;
}
/**
* Gets an item from the order.
*
* @since 2.6
*
* @param string $id The item ID.
*
* @return false|GF_Order_Item The found item or false.
*/
public function get_item( $id ) {
return $this->loop_items_return(
function ( $item ) use ( $id ) {
return $id == $item->get_id();
}
);
}
/**
* Searches for an item by a property and its values and returns the first found item.
*
* @since 2.6
*
* @param string $property The property name to look for.
* @param string $value The property value to look for.
*
* @return false|GF_Order_Item false if no items are found or the order item.
*/
public function get_item_by_property( $property, $value ) {
return $this->loop_items_return(
function( $item ) use ( $property, $value ) {
return $item->{$property} == $value;
}
);
}
/**
* Loops over the order item and returns one if it matches the provided callback.
*
* @since 2.6
*
* @param callable $callback The callback to use to evaluate the item.
*
* @return false|GF_Order_Item false if no items are found or the order item.
*/
protected function loop_items_return( $callback ) {
foreach ( $this->items as $item_type => $items ) {
foreach ( $items as $item_id => $item ) {
if ( $callback( $item ) ) {
return $item;
}
}
}
return false;
}
/**
* Returns the order items in a certain group.
*
* @since 2.6
*
* @param string $group The group to look for.
*
* @return array|GF_Order_Item An empty array if no items found or the items.
*/
public function get_group( $group ) {
return rgar( $this->groups, $group, array() );
}
/**
* Returns the order groups.
*
* @since 2.6
*
* @return array[]
*/
public function get_groups() {
return $this->groups;
}
/**
* Calculates the order totals.
*
* @since 2.6
*
* @return array an assoc array that contains each total label and its value.
*/
public function get_totals() {
if ( empty( $this->totals ) ) {
// Sub total is all items in the summary body.
$this->totals['sub_total'] = array_sum(
array_map(
function ( $item ) {
return $item->get_total();
},
$this->groups['body']
)
);
// Final total is the sub total plus everything in footer.
$this->totals['total'] = $this->totals['sub_total'] + array_sum(
array_map(
function ( $item ) {
return $item->get_total();
},
$this->groups['footer']
)
);
// Later on there will be dynamic totals, which will be calculated depending on certain conditions.
}
// Make sure we don't have negative totals.
foreach ( $this->totals as $label => $total_value ) {
$this->totals[ $label ] = max( $total_value, 0 );
}
return $this->totals;
}
}