本文整理汇总了PHP中R::relatedOne方法的典型用法代码示例。如果您正苦于以下问题:PHP R::relatedOne方法的具体用法?PHP R::relatedOne怎么用?PHP R::relatedOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::relatedOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
parent::init();
$id = $_POST["id"];
// check if npc is valid
if (!is_numeric($id) || $id <= 0) {
$this->error('Invalid ' . $this->_type . '-ID');
}
$this->npc = R::load($this->_type, $id);
if ($this->npc->getID() != $id) {
$this->error($this->_type . ' doesnt exist!');
}
// check if npc has right type
if ($this->npc->type != $this->myType) {
$this->error("This " . $this->_type . " is not of " . $this->myType);
}
// check if user is nearby
$userPos = R::findOne('map_position', ' user_id = ?', array($this->user->getID()));
$dist = sqrt(pow($this->npc->x - $userPos->x, 2) + pow($this->npc->y - $userPos->y, 2));
if ($dist > 3 || $this->npc->map != $userPos->map) {
$this->error('Du bist zu weit entfehrt!');
}
// check if quest availible
$this->myNPCQuest = R::relatedOne($this->user, 'quests_npc', ' complete_time = 0 AND (startnpc_id = ? OR stopnpc_id = ?)', array($this->npc->getID(), $this->npc->getID()));
if ($this->myNPCQuest != null) {
if ($this->myNPCQuest->startnpc_id == $this->npc->getID()) {
if ($this->myNPCQuest->accepted == 0) {
$this->myNPCQuestRole = 'startnpc';
$startnpc = $this->npc->name;
$stopnpc = R::getCell('SELECT `name` FROM map_npc WHERE id = ?', array($this->myNPCQuest->stopnpc_id));
}
} else {
if ($this->myNPCQuest->accepted == 1) {
$this->myNPCQuestRole = 'stopnpc';
$stopnpc = $this->npc->name;
$startnpc = R::getCell('SELECT `name` FROM map_npc WHERE id = ?', array($this->myNPCQuest->startnpc_id));
}
}
if ($this->myNPCQuestRole != 'none') {
$all = Config::getConfig('npc_quests');
$this->myNPCQuestData = $all[$this->myNPCQuest->quest_id][$this->myNPCQuestRole];
$this->myNPCQuestData["text"] = str_replace(array('{startnpc}', '{stopnpc}'), array($startnpc, $stopnpc), $this->myNPCQuestData["text"]);
foreach ($this->myNPCQuestData["items"] as $k => $v) {
$this->myNPCQuestData["items"][$k]["param"] = str_replace(array('{startnpc}', '{stopnpc}'), array($startnpc, $stopnpc), $v["param"]);
}
if ($this->_controllerFunc == 'Interact') {
$this->output('quest', '<br /> <br />
<b>Quest:</b> ' . htmlspecialchars($this->myNPCQuestData["text"]) . ' <br />
<a href="#questing">' . ($this->myNPCQuestRole == 'startnpc' ? 'annehmen' : 'abschließen') . '</a>');
}
}
}
}
示例2: showdown
public function showdown()
{
$allPlayers = R::related($this->bean, 'poker_player');
$pokerHands = array(10 => new PokerParser("[a>a>a>a>a"), 9 => new PokerParser("a>a>a>a>a"), 8 => new PokerParser("1{4}"), 7 => new PokerParser("1{3}2{2}"), 6 => new PokerParser("a{5}"), 5 => new PokerParser("?>?>?>?>?"), 4 => new PokerParser("1{3}"), 3 => new PokerParser("1{2}2{2}"), 2 => new PokerParser("1{2}"), 1 => new PokerParser("?"));
$bestValue = -1;
$winners = array();
$totalPot = $this->bean->global_pot;
// new round to move players to
$nextRound = R::findOne('poker_round', " state='pending'");
if ($nextRound == null) {
$nextRound = R::dispense('poker_round');
$nextRound->state = 'pending';
$nextRound->step = 0;
$nextRound->global_pot = 0;
R::store($nextRound);
}
foreach ($allPlayers as $p) {
$cards = array_merge(json_decode($p->cards, true), json_decode($this->bean->cards, true));
$totalPot += $p->bid;
$val = 0;
foreach ($pokerHands as $value => $parser) {
if ($parser->check($cards)) {
// player has this
$val = $value * 100 + $parser->getHighestCardValue();
break;
}
}
if ($val > $bestValue) {
$bestValue = $val;
$winners = array($p);
} elseif ($val == $bestValue) {
$winners[] = $p;
}
// kick from current round
R::unassociate($this->bean, $p);
// put into next round
R::associate($nextRound, $p);
}
$winnerCount = count($winners);
$winAmount = floor($totalPot / $winnerCount);
$winnerNames = array();
foreach ($winners as $win) {
$usr = R::relatedOne($win, 'user');
$usr->cash += $winAmount;
$winnerNames[] = $usr->username;
R::store($usr);
}
R::trash($this->bean);
return array("winners" => $winnerNames, "amount" => $winAmount, "bestValue" => $bestValue);
}
示例3: show_Cancel
public function show_Cancel()
{
if (!$this->user->hasPremium()) {
$this->error('Nur für Premiumaccounts.');
}
if (!is_numeric($this->get(1)) || $this->get(1) < 1) {
$this->error('Ungültige ID');
}
$crule = R::relatedOne($this->myCompany, 'crule', 'id = ?', array($this->get(1)));
if (!$crule) {
$this->error('Die ID wurde nicht gefunden.');
}
R::trash($crule);
$this->output('load', 'show');
}
示例4: show_Main
public function show_Main()
{
$poker_player = R::relatedOne($this->user, 'poker_player');
if ($poker_player == null) {
$poker_player = R::dispense('poker_player');
$poker_player->status = 'view';
$poker_player->cards = '';
$poker_player->bid = 0;
$poker_player->all_in = false;
$poker_player->all_in_amount = 0;
R::store($poker_player);
R::associate($poker_player, $this->user);
}
if ($poker_player->status == 'view') {
Framework::TPL()->assign('can_join', true);
}
}
示例5: 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();
}
示例6: show_News
public function show_News()
{
$id = $this->get(1);
if (!is_numeric($id)) {
$this->error("Invalid ID");
}
$post = R::load('homepage_posts', $id);
if (!$post->id) {
$this->error("Post not found");
}
$author = R::relatedOne($post, 'user');
$this->output('date', date("d.m.Y", $post->time));
$this->output('title', $post->title);
$this->output('text', nl2br(htmlspecialchars($post->content)));
$this->output('link', $post->link);
$this->output('author', $author->username);
}
示例7: show_News
public function show_News()
{
header("Content-Type: application/rss+xml; charset=UTF-8");
$tpl = new Smarty();
$tpl->cache_lifetime = 3600 * 24;
$tpl->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
$cacheID = 'rssFeed';
if (!$tpl->isCached('rss.xml', $cacheID)) {
$items = array();
$dbItems = R::find('homepage_posts', ' 1=1 ORDER BY id DESC LIMIT 15');
foreach ($dbItems as $item) {
$author = R::relatedOne($item, 'user');
$items[] = array('title' => $item->title, 'link' => $item->link == '' ? APP_WEBSITE . APP_DIR : $item->link, 'description' => $item->content, 'author' => $author->username, 'date' => date("D, d M Y H:i:s O", $item->time));
}
$tpl->assign('items', $items);
$tpl->assign('gentime', date("D, d M Y H:i:s O"));
$tpl->assign('link', APP_WEBSITE . APP_DIR);
}
$tpl->display('rss.xml', $cacheID);
}
示例8: cancel_Order
public function cancel_Order()
{
// when deleting an order, cash and ress must be returned to company
$company = R::relatedOne($this->bean, 'company');
if ($this->type == 'buy') {
// buy order needs cash updated
$company->balance += $this->r_amount * $this->price;
R::store($company);
R::trash($this->bean);
} else {
// sell order needs ress updated
if ($this->r_type == 'resource') {
$holder = R::findOne('company_ress', ' company_id = ?', array($company->id));
} else {
$holder = R::findOne('company_products', ' company_id = ?', array($company->id));
}
$holder->{$this->r_name} += $this->r_amount;
R::store($holder);
R::trash($this->bean);
}
}
示例9: show_Main
public function show_Main()
{
if ($this->get(1) == "login") {
Framework::TPL()->assign('first_login', true);
} else {
Framework::TPL()->assign('first_login', false);
}
$session_expired = false;
if ($this->get(1) == "session_expired") {
$session_expired = true;
}
Framework::TPL()->assign('session_expired', $session_expired);
$count = R::getCell('select count(id) from user');
Framework::TPL()->assign("playercount", $count);
// assign news
$news = array();
$dbNews = R::find('homepage_posts', ' 1=1 ORDER BY id DESC LIMIT 3');
foreach ($dbNews as $n) {
$author = R::relatedOne($n, 'user');
$news[] = array('id' => $n->id, 'title' => $n->title, 'author' => $author->username, 'time' => $n->time);
}
Framework::TPL()->assign("news", $news);
}
示例10: array
$s = R::dispense('person');
$s2 = R::dispense('person');
$t->name = 'a';
$t->role = 'teacher';
$s->role = 'student';
$s2->role = 'student';
$s->name = 'a';
$s2->name = 'b';
R::associate($t, $s);
R::associate($t, $s2);
$students = R::related($t, 'person', ' "role" = ? ORDER BY "name" ', array("student"));
$s = array_shift($students);
$s2 = array_shift($students);
asrt($s->name, 'a');
asrt($s2->name, 'b');
$s = R::relatedOne($t, 'person', ' role = ? ORDER BY "name" ', array("student"));
asrt($s->name, 'a');
//empty classroom
R::clearRelations($t, 'person', $s2);
$students = R::related($t, 'person', ' role = ? ORDER BY "name" ', array("student"));
asrt(count($students), 1);
$s = reset($students);
asrt($s->name, 'b');
function getList($beans, $property)
{
$items = array();
foreach ($beans as $bean) {
$items[] = $bean->{$property};
}
sort($items);
return implode(",", $items);
示例11: 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');
}
示例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: array_shift
$s = R::dispense('person');
$s2 = R::dispense('person');
$t->name = 'a';
$t->role = 'teacher';
$s->role = 'student';
$s2->role = 'student';
$s->name = 'a';
$s2->name = 'b';
R::associate($t, $s);
R::associate($t, $s2);
$students = R::related($t, 'person', ' role = "student" ORDER BY `name` ');
$s = array_shift($students);
$s2 = array_shift($students);
asrt($s->name, 'a');
asrt($s2->name, 'b');
$s = R::relatedOne($t, 'person', ' role = "student" ORDER BY `name` ');
asrt($s->name, 'a');
//empty classroom
R::clearRelations($t, 'person', $s2);
$students = R::related($t, 'person', ' role = "student" ORDER BY `name` ');
asrt(count($students), 1);
$s = reset($students);
asrt($s->name, 'b');
$students = R::related($t, 'person', ' role = ? ORDER BY `name` ', array("student"));
asrt(count($students), 1);
$s = reset($students);
asrt($s->name, 'b');
function getList($beans, $property)
{
$items = array();
foreach ($beans as $bean) {
示例14: testScenarios
//.........这里部分代码省略.........
asrt(reset($book->sharedTopic)->name, 'holiday');
// Add and change
$book->sharedTopic[] = $topic3;
$book->sharedTopic[1]->name = 'tropics';
$id = R::store($book);
$book = R::load('book', $id);
asrt(count($book->sharedTopic), 2);
asrt($book->sharedTopic[1]->name, 'tropics');
testids($book->sharedTopic);
R::trash(R::load('topic', $tidx));
$id = R::store($book);
$book = R::load('book', $id);
// Delete without save
unset($book->sharedTopic[1]);
$book = R::load('book', $id);
asrt(count($book->sharedTopic), 2);
$book = R::load('book', $id);
// Delete without init
asrt(R::count('topic'), 3);
unset($book->sharedTopic[1]);
$id = R::store($book);
asrt(R::count('topic'), 3);
asrt(count($book->sharedTopic), 1);
asrt(count($book2->sharedTopic), 0);
// Add same topic to other book
$book2->sharedTopic[] = $topic3;
asrt(count($book2->sharedTopic), 1);
$id2 = R::store($book2);
asrt(count($book2->sharedTopic), 1);
$book2 = R::load('book', $id2);
asrt(count($book2->sharedTopic), 1);
// Get books for topic
asrt(count(R::related($topic3, 'book')), 2);
asrt(R::relatedOne($topic3, 'book') instanceof RedBean_OODBBean, TRUE);
$items = R::related($topic3, 'book');
$a = reset($items);
asrt(R::relatedOne($topic3, 'book')->id, $a->id);
$t3 = R::load('topic', $topic3->id);
asrt(count($t3->sharedBook), 2);
asrt(R::relatedOne($topic3, 'nothingness'), NULL);
// Testing relatedLast
$z = end($items);
asrt(R::relatedLast($topic3, 'book')->id, $z->id);
asrt(R::relatedLast($topic3, 'manuscript'), NULL);
// Nuke an own-array, replace entire array at once without getting first
$page2->id = 0;
$page2->title = 'yet another page 2';
$page4->id = 0;
$page4->title = 'yet another page 4';
$book = R::load('book', $id);
$book->ownPage = array($page2, $page4);
R::store($book);
$book = R::load('book', $id);
asrt(count($book->ownPage), 2);
asrt(reset($book->ownPage)->title, 'yet another page 2');
asrt(end($book->ownPage)->title, 'yet another page 4');
testids($book->ownPage);
// Test with alias format
$book3->cover = $page6;
$idb3 = R::store($book3);
$book3 = R::load('book', $idb3);
$justACover = $book3->fetchAs('page')->cover;
asrt($book3->cover instanceof RedBean_OODBBean, TRUE);
asrt($justACover->title, 'cover1');
// No page property
asrt(isset($book3->page), FALSE);
示例15: testGetBeanWhenThereIsNoneToGet
public function testGetBeanWhenThereIsNoneToGet()
{
$bean = R::dispense('a');
$bean2 = R::relatedOne($bean, 'b');
$this->assertTrue($bean2 === null);
}