本文整理汇总了PHP中R::begin方法的典型用法代码示例。如果您正苦于以下问题:PHP R::begin方法的具体用法?PHP R::begin怎么用?PHP R::begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit_post
function edit_post($f3)
{
// Update Tool Locations
$this->D->sharedLocationsList = array();
if ($f3->exists('POST.locations')) {
foreach ($f3->get('POST.locations') as $id) {
$this->D->sharedLocationsList[] = \R::load('locations', $id);
}
}
$f3->clear('POST.locations');
$this->D->import($f3->get('POST'));
$this->D->training_levels or $this->D->training_levels = json_encode($f3->get('TRAINING_LEVELS'));
\R::begin();
try {
$id = \R::store($this->D);
\R::commit();
} catch (\Exception $e) {
\R::rollback();
if ($e->getSQLState() == 23000) {
}
throw new \Exception($this->D->name . ' is not a unique name.');
throw new \Exception();
}
if ($f3->get('dry')) {
logger($f3, 'added ' . $this->class_name() . ', id=' . $id);
} else {
logger($f3, 'modified ' . $this->class_name() . ', id=' . $id);
}
$f3->reroute($this->redirect());
}
示例2: save
public function save()
{
$rules = array('customer_id' => 'required|', 'payment_amount' => 'required|numeric', 'payment_memo' => 'required');
$filters = array('payment_memo' => 'trim|sanitize_string', 'payment_amount' => 'trim|sanitize_string|numeric', 'customer_id' => 'trim|numeric');
$postValues = $gump->filter($this->{$postarray}, $filters);
$validated = $gump->validate($gump->filter($postValues, $filters), $rules);
$this->payment_amount = $postValues['payment_amount'];
$this->payment_memo = $postValues['payment_memo'];
$this->who_is_getting_paid = $postValues['customer_id'];
if ($validated === TRUE) {
R::begin();
try {
/*Payment Add*/
$payment = R::findOne('user', ' id = ? and created_by=? ', array($this->who_is_getting_paid, $this->who_is_paying));
$current_balance = $payment->balance2;
$reseller_balance = R::dispense("reseller_balance");
$reseller_balance->user_id = $this->who_is_getting_paid;
$reseller_balance->amount = $this->{$payment_amount};
$reseller_balance->load_by = $this->who_is_paying;
$reseller_balance->note = $this->comments;
$reseller_balance->ip = $_SERVER["REMOTE_ADDR"];
$reseller_balance->updated = CURRENT_DTT;
if ($this->payment_type == "add") {
$payment->balance2 = $payment->balance2 + $this->payment_amount;
$payment->return_payment = 0;
//add
R::exec("CALL preparestatement({$this->who_is_paying},{$this->payment_amount},{$current_balance},{$this->who_is_getting_paid},'debit','{$this->payment_memo}')");
} elseif ($this->payment_type == "return") {
$payment->balance2 = $payment->balance2 - $this->payment_amount;
$payment->return_payment = 1;
//return
R::exec("CALL preparestatement({$this->who_is_paying},{$this->payment_amount},{$current_balance},{$this->who_is_getting_paid},'credit','{$this->payment_memo}')");
}
R::save($payment);
R::save($reseller_balance);
R::commit();
} catch (Exception $e) {
R::rollback();
$this->setError("" . $e->getMessage());
}
} else {
$this->setError($gump->get_readable_errors(true));
}
if ($this->getError() == "") {
$this->fails = FALSE;
} else {
$this->fails = TRUE;
}
}
示例3: removeChild
public static function removeChild($table, $parentBean, $bean)
{
//we still need 2 separate queries because the parent's left_id can't be updated...
R::begin();
try {
R::trash($bean);
R::exec('UPDATE ' . $table . ' SET left_id = left_id-2 WHERE left_id > ?', array($bean->right_id));
R::exec('UPDATE ' . $table . ' SET right_id = right_id-2 WHERE right_id >= ?', array($bean->right_id));
$parentBean->right_id -= 2;
R::commit();
} catch (Exception $e) {
R::rollback();
throw $e;
}
}
示例4: cancel
public function cancel()
{
$cs = Config::getConfig("company_quests");
$details = $cs[$this->name];
//$company = R::relatedOne($this->bean, 'company');
$user = R::relatedOne($this->bean, 'user');
if ($user == null) {
R::trash($this->bean);
return;
}
$company = R::findOne('company', 'user_id = ?', array($user->id));
$company->balance -= floor($details["oncomplete"]["cash"] * 0.1);
R::begin();
R::trash($this->bean);
R::store($company);
R::commit();
}
示例5: save
public function save()
{
$this->amount = abs($this->amount);
if ($this->phone == "") {
$this->setError("Please Give number");
} elseif (strlen($this->phone) < 11) {
$this->setError("Phone number must be 11 digit");
} elseif ($this->amount < 10 || $this->amount > 1000) {
$this->setError("Amount not valid");
} elseif ($this->restrictDublicateLoad($this->phone) == 1) {
$this->setError("You can not request same number within 15 minute.");
} else {
R::begin();
try {
foreach ($this->cut_balance_from_id as $boss_id) {
$current_balance = L::getBalance($boss_id, "flexiload");
if ($current_balance < $this->amount) {
$this->setError("You do not have sufficient amount in your account");
} else {
R::exec("UPDATE user SET {$this->balance_field}={$this->balance_field}-{$this->amount} where id='{$boss_id}'");
R::exec("CALL preparestatement({$boss_id},{$this->amount},{$current_balance},{$this->user_id},'credit','{$this->comments}')");
}
}
$flexiload = R::dispense("flexiload");
$flexiload->phone = $this->phone;
$flexiload->balance = $this->amount;
$flexiload->load_type = $this->type;
$flexiload->user_id = $this->user_id;
$flexiload->s_date = CURRENT_DT;
$flexiload->status = 'pending';
$flexiload->s_time = time();
$flexiload->submitted_date = CURRENT_DTT;
$flexiload->operator = $this->getOperatorName($this->phone);
R::store($flexiload);
R::commit();
} catch (Exception $e) {
R::rollback();
$this->setError("" . $e->getMessage());
}
}
if ($this->getError() == "") {
$this->fails = FALSE;
} else {
$this->fails = TRUE;
}
}
示例6: registerUser
static function registerUser($uname, $keys, $values)
{
#self::connectDb();
R::begin();
for ($i = 0; $i < sizeof($values); $i++) {
$user = R::dispense('users');
$user->uname = $uname;
$user->prop = $keys[$i];
$user->value = $values[$i];
R::store($user);
}
try {
$id = R::commit();
return '1';
} catch (Exception $e) {
return "0";
}
}
示例7: show_Transfer
public function show_Transfer()
{
$bankAccount = R::findOne('bank_account', ' user_id = ?', array($this->user->id));
if (isset($_POST["amount"]) && is_numeric($_POST["amount"]) && $_POST["amount"] > 0) {
$amount = $_POST["amount"];
switch (@$_POST["type"]) {
case "put":
if ($bankAccount->balance < $amount) {
$this->output('maintext', 'Du hast nicht genügend Geld auf deinem Bankkonto');
$this->output('options', array('transfer' => 'Zurück'));
return;
}
$bankAccount->balance -= $amount;
$this->company->balance += $amount;
R::begin();
R::store($bankAccount);
R::store($this->company);
R::commit();
break;
case "take":
if ($this->company->balance < $amount) {
$this->output('maintext', 'Es ist nicht genügend Geld auf dem Firmenkonto');
$this->output('options', array('transfer' => 'Zurück'));
return;
}
$bankAccount->balance += $amount;
$this->company->balance -= $amount;
R::begin();
R::store($bankAccount);
R::store($this->company);
R::commit();
break;
}
}
$this->output('maintext', 'Du kannst Geld von deinem Bankkonto auf das Firmen-Konto
überweisen, oder Geld vom Firmen-Konto auf dein Konto überweisen. <br /><br />
Firmen-Konto: <b>' . formatCash($this->company->balance) . '</b> {money}<br />
Dein Bankkonto: <b>' . formatCash($bankAccount->balance) . ' {money}</b>');
$this->output('form', array('target' => 'transfer', 'elements' => array(array('desc' => "Betrag", 'name' => 'amount', 'type' => 'text'), array('desc' => "Aktion", 'name' => 'type', 'type' => 'select', 'options' => array('put' => 'Von deinem Bankkonto auf das Firmen-Konto überweisen', 'take' => 'Vom Firmen-Konto auf dein Bankkonto buchen')))));
$this->output('options', array('interact' => 'Zurück'));
}
示例8: cronHandleCrule
/**
* handle company rules
*/
protected function cronHandleCrule()
{
// delete old rules
R::exec('DELETE FROM `crule` WHERE `until` < ?', array(time()));
// get new rules
$crules = R::find('crule');
// counter
$counter = array('buy' => 0, 'sell' => 0);
foreach ($crules as $crule) {
$company = R::relatedOne($crule, 'company');
$amount = R::getCell('SELECT
`' . $crule->r_name . '`
FROM
`company_' . ($crule->r_type == 'product' ? 'products' : 'ress') . '`
WHERE
company_id = ?', array($company->id));
// fix amount with existant orders
$existant = R::related($company, 'order', 'r_name = ? AND type = ?', array($crule->r_name, $crule->action));
foreach ($existant as $e) {
if ($e->type == 'buy') {
$amount += $e->r_amount;
} else {
$amount -= $e->r_amount;
}
}
$order = R::dispense('order');
$order->type = $crule->action;
$order->r_type = $crule->r_type;
$order->r_name = $crule->r_name;
$order->price = $crule->r_price;
$order->date = time();
$order->automatic = false;
$order->a_expires = 0;
$sold = 0;
if ($crule->action == 'buy' && $amount < $crule->r_limit) {
// create buy order
$maxBuy = $crule->r_limit - $amount;
$costs = $maxBuy * $crule->r_price;
if ($costs > $company->balance) {
$maxBuy = floor($company->balance / $crule->r_price);
}
if ($maxBuy == 0) {
continue;
}
$company->balance -= $maxBuy * $crule->r_price;
$order->r_amount = $maxBuy;
$counter['buy']++;
} else {
if ($crule->action == 'sell' && $amount > $crule->r_limit) {
// create sell order
$order->r_amount = $amount - $crule->r_limit;
$sold += $amount - $crule->r_limit;
$counter['sell']++;
} else {
continue;
}
}
R::begin();
if ($sold != 0) {
R::exec('UPDATE
`company_' . ($crule->r_type == 'product' ? 'products' : 'ress') . '`
SET
`' . $crule->r_name . '` = `' . $crule->r_name . '`-?
WHERE
company_id = ?', array($sold, $company->id));
}
R::store($order);
R::store($company);
R::associate($order, $company);
R::commit();
}
$this->log('handleCrule', $counter['buy'] . ' new buy-orders, ' . $counter['sell'] . ' new sell-orders');
}
示例9: commitBean
/**
* commit a bean with transactions
* @param object $bean
* @return $res false or last insert id
*/
public static function commitBean($bean)
{
R::begin();
try {
$res = R::store($bean);
R::commit();
} catch (Exception $e) {
R::rollback();
$res = false;
}
return $res;
}
示例10: show_Questing
public function show_Questing()
{
if ($this->myNPCQuestRole == 'none') {
$this->error('Dieses NPC hat keine Quest für dich!');
}
if ($this->myNPCQuestRole == 'startnpc' && $this->myNPCQuest->accepted == 0) {
$this->output('maintext', $this->myNPCQuestData["text2"] . ' Denk daran:
Je schneller du dieses Quest erledigst, desto mehr Erfahrungspunkte bekommst
du als Belohnung!');
R::begin();
foreach ($this->myNPCQuestData["items"] as $k => $v) {
$inv = R::dispense('inventory');
$inv->amount = $v["amount"];
$inv->param = $v["param"];
$inv->item_id = $v["id"];
$inv->user = $this->user;
R::store($inv);
}
$this->myNPCQuest->accepted = 1;
$this->myNPCQuest->accept_time = time();
R::store($this->myNPCQuest);
R::commit();
} elseif ($this->myNPCQuestRole == 'stopnpc' && $this->myNPCQuest->accepted == 1) {
// check if user has needed items in inventory
$items = array();
foreach ($this->myNPCQuestData["items"] as $k => $v) {
$inv = R::findOne('inventory', ' item_id = ? AND amount >= ? AND param = ? AND user_id = ?', array($v["id"], $v["amount"], $v["param"], $this->user->getID()));
if ($inv == null) {
$this->output('maintext', 'Leider hast du nicht alle nötigen Items dabei!');
$this->output('options', array('interact' => 'Zurück'));
return;
}
$items[$v["id"]]["data"] = $inv;
$items[$v["id"]]["amount"] = $v["amount"];
}
// calculate bonus
$this->myNPCQuest->complete_time = time();
$took = $this->myNPCQuest->complete_time - $this->myNPCQuest->accept_time;
$xp = $this->myNPCQuestData["base_xp"];
$cash = $this->myNPCQuestData["base_cash"];
// randomize xp/cash
$xp += 2 - mt_rand(0, 4);
$cash += 2 - mt_rand(0, 4);
if ($took > $this->myNPCQuestData["base_time"]) {
$diff = $took - $this->myNPCQuestData["base_time"];
// subtract of the bonus
$xp -= floor($diff / 10);
// every ten seconds late subtract 1xp
if ($xp < 1) {
$xp = 1;
}
$cash -= floor($diff / 5);
// every five seconds late substract 1 cash
if ($cash < 0) {
$cash = 0;
}
}
R::begin();
$this->user->cash += $cash;
$this->user->changeXP($this->user->xp + $xp);
// take items from inventory
foreach ($items as $i) {
$i["data"]->amount -= $i["amount"];
R::store($i["data"]);
}
R::store($this->myNPCQuest);
R::commit();
$quest = R::dispense('quests_npc');
$quest->giveNewQuest($this->user);
$this->output('maintext', $this->myNPCQuestData["text2"] . ' <br />
<b>Du erhälst als Belohnung: ' . formatCash($cash) . ' {money} und ' . formatCash($xp) . ' {eye}</b>');
} else {
$this->output('maintext', 'Ich habe leider im Moment nichts zu tun für dich!');
}
$this->output('options', array('interact' => 'Zurück'));
}
示例11: logresult
function logresult($userid, $text)
{
R::selectDatabase('localdb');
R::begin();
$logtext = "";
if (is_array($text)) {
foreach ($text as $value) {
$logtext .= $value . "; ";
}
} else {
$logtext = $text;
}
$logtext = strip_tags($logtext);
$sent = R::dispense('sent');
$sent->number = $userid;
$sent->text = $logtext;
R::store($sent);
R::commit();
R::selectDatabase('default');
}
示例12: actionM
protected function actionM($action, $name, $details, $type, $id)
{
if (!is_numeric($id) || $id < 0) {
$this->output('maintext', 'Ungültige Order!');
return;
}
$order = R::findOne('order', ' id = ? AND type = ? AND r_name = ?', array($id, $action == 'sell' ? 'buy' : 'sell', $name));
if (!$order) {
$this->output('maintext', 'Die angegebene Order konnte nicht gefunden werden!');
return;
}
if (R::areRelated($order, $this->myCompany)) {
$this->output('maintext', 'Die angegebene Order konnte nicht gefunden werden!');
return;
}
$orderCompany = R::relatedOne($order, 'company');
if (isset($_POST['amount']) && is_numeric($_POST['amount']) && $_POST['amount'] > 0) {
$amount = $_POST['amount'];
if ($action == 'sell') {
if ($amount > ($type == 'r' ? $this->myRess->{$name} : $this->myProducts->{$name})) {
$this->output('maintext', 'Deine Firma lagert nicht genügend Ressourcen für diesen Verkauf!');
return;
}
if ($amount > $order->r_amount) {
$this->output('maintext', 'Diese Firma Ordert {' . $type . '_' . $name . '} maximal ' . formatCash($order->r_amount) . ' mal!');
return;
}
// checks done
$this->myCompany->balance += $amount * $order->price;
if ($type == 'r') {
$this->myRess->{$name} -= $amount;
$order->r_amount -= $amount;
$targetComp = R::findOne('company_ress', ' company_id = ?', array($orderCompany->id));
$targetComp->{$name} += $amount;
R::begin();
R::store($this->myRess);
if ($order->r_amount <= 0) {
R::trash($order);
} else {
R::store($order);
}
R::store($targetComp);
R::store($this->myCompany);
R::commit();
} else {
$this->myProducts->{$name} -= $amount;
$order->r_amount -= $amount;
$targetComp = R::findOne('company_products', ' company_id = ?', array($orderCompany->id));
$targetComp->{$name} += $amount;
R::begin();
R::store($this->myProducts);
if ($order->r_amount <= 0) {
R::trash($order);
} else {
R::store($order);
}
R::store($targetComp);
R::store($this->myCompany);
R::commit();
}
$this->output('maintext', 'Der Verkauf war erfolgreich!');
return;
} else {
$totalPrice = $amount * $order->price;
if ($totalPrice > $this->myCompany->balance) {
$this->output('maintext', 'Deine Firma hat nicht genügend Geld für diesen Kauf!');
return;
}
if ($amount > $order->r_amount) {
$this->output('maintext', 'Es werden maximal ' . formatCash($order->r_amount) . ' Verkaufseinheiten verkaufen!');
return;
}
// buy
$this->myCompany->balance -= $totalPrice;
if ($type == 'r') {
$this->myRess->{$name} += $amount;
} else {
$this->myProducts->{$name} += $amount;
}
$order->r_amount -= $amount;
R::begin();
R::store($this->myCompany);
R::store($this->myRess);
R::store($this->myProducts);
if ($order->r_amount <= 0) {
R::trash($order);
} else {
R::store($order);
}
R::commit();
$this->output('maintext', 'Der Kauf war erfolgreich!');
return;
}
}
$this->output('maintext', '<h3>Fremde ' . ($order->type == 'sell' ? 'Verkauf' : 'Kauf') . 'order</h3>
<p>{' . $type . '_' . $name . '}</p>
<p>Firma: <b>' . htmlspecialchars($orderCompany->name) . '</b><br />
Preis pro VE: <b>' . formatCash($order->price) . ' {money}</b> <br />
Maximal Verfügbare VE\'s: <b>' . formatCash($order->r_amount) . '</b>
//.........这里部分代码省略.........
示例13: helAction
/**
* /event/user/halv
*/
public function helAction()
{
$this->checkAccess();
$eDb = new eDb();
$halv = $eDb->getUserHalvFromUserId(session::getUserId());
if (empty($halv)) {
http::locationHeader('/event/user/index', 'Du skal være del af en halv kvadrille for at oprette en hel');
}
http::prg();
if (isset($_POST['send'])) {
$this->validateHel();
if (empty($this->errors)) {
// Prepare
$ary = db::prepareToPostArray(array('halv'), true);
R::begin();
// Delete other hele
$eDb->deleteHelFromUserId(session::getUserId());
// Create
$id = $eDb->createHel($ary);
// Set a better name
$name = $eDb->getUsersStrFromHel($id);
$bean = rb::getBean('hel', 'id', $id);
$bean->name = $name;
R::store($bean);
$res = R::commit();
if (!$res) {
R::rollback();
}
http::locationHeader('/event/user/index');
} else {
echo html::getErrors($this->errors);
}
}
echo $this->formCreateHel();
}
示例14: testTransactions
/**
* Test Transactions.
*
* @return void
*/
public function testTransactions()
{
testpack('transactions');
R::begin();
$bean = R::dispense('bean');
R::store($bean);
R::commit();
asrt(R::count('bean'), 1);
R::wipe('bean');
R::freeze(1);
R::begin();
$bean = R::dispense('bean');
R::store($bean);
R::rollback();
asrt(R::count('bean'), 0);
R::freeze(FALSE);
testpack('genSlots');
asrt(R::genSlots(array('a', 'b')), '?,?');
asrt(R::genSlots(array('a')), '?');
asrt(R::genSlots(array()), '');
}
示例15: create_record
function create_record($f3, $user, $instructor, $timestamp = false)
{
// Create Training Record
$training = \R::dispense('trainings');
$training->users = $user;
$training->tools = $this->D;
$training->instructor = $instructor;
$training->timestamp = $timestamp !== false ? $timestamp : time();
$training->level = $f3->get('POST.level');
$this->D->verify_training_level($f3->get('POST.level'));
// Store Training Record
\R::begin();
try {
$id = \R::store($training);
\R::commit();
$f3->set('message', $user->displayname . ' has been trained!');
$f3->set('success', 1);
} catch (\Exception $e) {
\R::rollback();
$f3->set('message', $user->displayname . ' is already trained on this machine at this level. No training record added.');
$f3->set('success', 0);
}
if ($f3->get('success')) {
logger($f3, 'added ' . $this->class_name() . ', id=' . $id);
}
}