本文整理汇总了PHP中Piwik_Common::hashStringToInt方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_Common::hashStringToInt方法的具体用法?PHP Piwik_Common::hashStringToInt怎么用?PHP Piwik_Common::hashStringToInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik_Common
的用法示例。
在下文中一共展示了Piwik_Common::hashStringToInt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _test_hashStringToInt
function _test_hashStringToInt()
{
$tests = array(1 => 10000, 200000 => 300000, 100000001 => 100100001, 200000001 => 200211111, 'inv' => 10000, 'INV-' => 10000);
$alreadyHashed = array();
$c = 0;
$collisions = 0;
foreach ($tests as $start => $finish) {
$prefix = false;
if (is_string($start)) {
$prefix = $start;
$start = 0;
}
for ($i = $start; $i < $finish; $i++) {
$value = $i;
if (!empty($prefix)) {
$value = $prefix . $value;
}
$hash = Piwik_Common::hashStringToInt($value);
if (isset($alreadyHashed[$hash])) {
$collisions++;
$diff = $value - $alreadyHashed[$hash];
$this->fail("Hash of {$value} is the same as hash of " . $alreadyHashed[$hash] . " DIFF WAS " . $diff);
}
$alreadyHashed[$hash] = $value;
$c++;
}
}
// $interval = PHP_INT_MAX / 50;
// foreach($alreadyHashed as $hash => $value)
// {
// $hash %
// }
echo "Collision = {$collisions} - Total hashed = {$c} - Collision rate = " . round(100 * $collisions / $c, 5) . "%";
$this->pass();
}
示例2: recordEcommerceGoal
/**
* Records an Ecommerce conversion in the DB. Deals with Items found in the request.
* Will deal with 2 types of conversions: Ecommerce Order and Ecommerce Cart update (Add to cart, Update Cart etc).
*
* @param array $goal
* @param array $visitorInformation
*/
protected function recordEcommerceGoal($goal, $visitorInformation)
{
// Is the transaction a Cart Update or an Ecommerce order?
$updateWhere = array('idvisit' => $visitorInformation['idvisit'], 'idgoal' => self::IDGOAL_CART, 'buster' => 0);
if ($this->isThereExistingCartInVisit) {
printDebug("There is an existing cart for this visit");
}
if ($this->isGoalAnOrder) {
$orderIdNumeric = Piwik_Common::hashStringToInt($this->orderId);
$goal['idgoal'] = self::IDGOAL_ORDER;
$goal['idorder'] = $this->orderId;
$goal['buster'] = $orderIdNumeric;
$goal['revenue_subtotal'] = $this->getRevenue(Piwik_Common::getRequestVar('ec_st', false, 'float', $this->request));
$goal['revenue_tax'] = $this->getRevenue(Piwik_Common::getRequestVar('ec_tx', false, 'float', $this->request));
$goal['revenue_shipping'] = $this->getRevenue(Piwik_Common::getRequestVar('ec_sh', false, 'float', $this->request));
$goal['revenue_discount'] = $this->getRevenue(Piwik_Common::getRequestVar('ec_dt', false, 'float', $this->request));
$debugMessage = 'The conversion is an Ecommerce order';
} else {
$goal['buster'] = 0;
$goal['idgoal'] = self::IDGOAL_CART;
$debugMessage = 'The conversion is an Ecommerce Cart Update';
}
$goal['revenue'] = $this->getRevenue(Piwik_Common::getRequestVar('revenue', 0, 'float', $this->request));
printDebug($debugMessage . ':' . var_export($goal, true));
// INSERT or Sync items in the Cart / Order for this visit & order
$items = $this->getEcommerceItemsFromRequest();
if ($items === false) {
return;
}
$itemsCount = 0;
foreach ($items as $item) {
$itemsCount += $item[self::INTERNAL_ITEM_QUANTITY];
}
$goal['items'] = $itemsCount;
// If there is already a cart for this visit
// 1) If conversion is Order, we update the cart into an Order
// 2) If conversion is Cart Update, we update the cart
$recorded = $this->recordGoal($goal, $this->isThereExistingCartInVisit, $updateWhere);
if ($recorded) {
$this->recordEcommerceItems($goal, $items);
}
}