本文整理汇总了PHP中R::areRelated方法的典型用法代码示例。如果您正苦于以下问题:PHP R::areRelated方法的具体用法?PHP R::areRelated怎么用?PHP R::areRelated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::areRelated方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hasRight
/**
* check if user has given right
* @param string $type
* @return boolean
*/
public function hasRight($type)
{
$right = RCached::findOne('user_right', ' type = ?', array($type), date("d.m.Y - H"));
if (!$right) {
return false;
}
return R::areRelated($this->bean, $right);
}
示例2: testAreRelatedAndVariations
/**
* Test areRelated().
*
* @return void
*/
public function testAreRelatedAndVariations()
{
$sheep = R::dispense('sheep');
$sheep->name = 'Shawn';
$sheep2 = R::dispense('sheep');
$sheep2->name = 'Billy';
$sheep3 = R::dispense('sheep');
$sheep3->name = 'Moo';
R::store($sheep3);
R::associate($sheep, $sheep2);
asrt(R::areRelated($sheep, $sheep2), TRUE);
R::exec('DELETE FROM sheep_sheep WHERE sheep2_id = ? -- keep-cache', array($sheep2->id));
asrt(R::areRelated($sheep, $sheep2), FALSE);
// Use cache?
R::associate($sheep, $sheep2);
R::$writer->setUseCache(TRUE);
asrt(R::areRelated($sheep, $sheep2), TRUE);
R::exec('DELETE FROM sheep_sheep WHERE sheep2_id = ? -- keep-cache', array($sheep2->id));
asrt(R::areRelated($sheep, $sheep2), TRUE);
// Use cache?
R::associate($sheep, $sheep2);
asrt(R::areRelated($sheep, $sheep3), FALSE);
$pig = R::dispense('pig');
asrt(R::areRelated($sheep, $pig), FALSE);
R::freeze(TRUE);
asrt(R::areRelated($sheep, $pig), FALSE);
R::freeze(FALSE);
$foo = R::dispense('foo');
$bar = R::dispense('bar');
$foo->id = 1;
$bar->id = 2;
asrt(R::areRelated($foo, $bar), FALSE);
}
示例3: 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>
//.........这里部分代码省略.........
示例4: posthookHomepage_posts
private function posthookHomepage_posts(&$bean)
{
if (!R::areRelated($bean, $this->user)) {
R::associate($bean, $this->user);
}
}
示例5: testFastTrackRelations
/**
* Fast track link block code should not affect self-referential N-M relations.
*
* @return void
*/
public function testFastTrackRelations()
{
testpack('Test fast-track linkBlock exceptions');
list($donald, $mickey, $goofy, $pluto) = R::dispense('friend', 4);
$donald->name = 'D';
$mickey->name = 'M';
$goofy->name = 'G';
$pluto->name = 'P';
$donald->sharedFriend = array($mickey, $goofy);
$mickey->sharedFriend = array($pluto, $goofy);
$mickey->sharedBook = array(R::dispense('book'));
R::storeAll(array($mickey, $donald, $goofy, $pluto));
$donald = R::load('friend', $donald->id);
$mickey = R::load('friend', $mickey->id);
$goofy = R::load('friend', $goofy->id);
$pluto = R::load('friend', $pluto->id);
$names = implode(',', R::gatherLabels($donald->sharedFriend));
asrt($names, 'G,M');
$names = implode(',', R::gatherLabels($goofy->sharedFriend));
asrt($names, 'D,M');
$names = implode(',', R::gatherLabels($mickey->sharedFriend));
asrt($names, 'D,G,P');
$names = implode(',', R::gatherLabels($pluto->sharedFriend));
asrt($names, 'M');
// Now in combination with with() conditions...
$donald = R::load('friend', $donald->id);
$names = implode(',', R::gatherLabels($donald->withCondition(' name = ? ', array('M'))->sharedFriend));
asrt($names, 'M');
// Now in combination with with() conditions...
$donald = R::load('friend', $donald->id);
$names = implode(',', R::gatherLabels($donald->with(' ORDER BY name ')->sharedFriend));
asrt($names, 'G,M');
// Now counting
$goofy = R::load('friend', $goofy->id);
asrt((int) $goofy->countShared('friend'), 2);
asrt((int) $donald->countShared('friend'), 2);
asrt((int) $mickey->countShared('friend'), 3);
asrt((int) $pluto->countShared('friend'), 1);
R::unassociate($donald, $mickey);
asrt((int) $donald->countShared('friend'), 1);
asrt(R::areRelated($donald, $mickey), FALSE);
asrt(R::areRelated($mickey, $donald), FALSE);
asrt(R::areRelated($mickey, $goofy), TRUE);
asrt(R::areRelated($goofy, $mickey), TRUE);
R::getWriter()->setUseCache(TRUE);
$mickeysFriends = R::$associationManager->related($mickey, 'friend', TRUE);
asrt(count($mickeysFriends), 2);
$mickeysFriends = R::$associationManager->related($mickey, 'friend', TRUE);
asrt(count($mickeysFriends), 2);
$plutosFriends = R::$associationManager->related($pluto, 'friend', TRUE);
asrt(count($plutosFriends), 1);
$mickeysBooks = R::$associationManager->related($mickey, 'book', TRUE);
asrt(count($mickeysBooks), 1);
R::getWriter()->setUseCache(FALSE);
}
示例6: show_Play
//.........这里部分代码省略.........
// kick out specific player
$this->_pokerRound->kick(R::load('poker_player', $this->_pokerRound->current_player_id));
$this->_pokerRound->next_player();
if ($usr != null) {
$this->chatMessage(htmlspecialchars($usr->username) . ' verlässt das Spiel.');
}
}
// output game state
$nC = array();
$cC = json_decode($this->_pokerRound->cards, true);
foreach ($cC as $k => $v) {
if ($v['turned']) {
$nC[] = $v;
} else {
$nC[] = array('card' => '?', 'color' => '?', 'turned' => 'true');
}
}
$this->output('maxbid', $this->_maxBid);
$this->output('pot', $this->_pot);
// my turn?
if ($this->_pokerRound->current_player_id == $this->_pokerPlayer->getID()) {
$this->output('myturn', true);
$opts = array();
if ($this->_pokerPlayer->bid < $this->_maxBid) {
$opts = array('fold');
$diff = $this->_maxBid - $this->_pokerPlayer->bid;
if ($diff <= $this->user->cash) {
$opts[] = 'call';
$opts[] = 'raise';
}
} else {
$opts = array('fold', 'check', 'raise');
}
$this->output('options', $opts);
// handle player actions
if ($this->get(1) != "" && in_array($this->get(1), $opts)) {
switch ($this->get(1)) {
case "fold":
$this->_pokerRound->kick($this->_pokerPlayer);
$this->_pokerRound->next_player();
$this->chatMessage('{me}: FOLD');
break;
case "call":
$diff = $this->_maxBid - $this->_pokerPlayer->bid;
$this->user->cash -= $diff;
$this->_pokerPlayer->bid += $diff;
R::store($this->user);
R::store($this->_pokerPlayer);
$this->_pokerRound->next_player();
$this->chatMessage('{me}: CALL');
break;
case "raise":
$diff = $this->_maxBid - $this->_pokerPlayer->bid;
if ($diff < 0) {
$diff = 0;
}
if (is_numeric($this->get(2))) {
if ($this->user->cash - $diff - $this->get(2) < 0) {
return;
}
$this->user->cash -= $diff + $this->get(2);
$this->_pokerPlayer->bid += $diff + $this->get(2);
$this->_pokerRound->next_player();
$this->chatMessage('{me}: RAISE ' . formatCash($this->get(2)) . ' {money}');
} else {
return;
// invalid input
}
break;
case "check":
$this->_pokerRound->next_player();
$this->chatMessage('{me}: CHECK');
break;
}
$this->_pokerPlayer->game_state = $this->_pokerRound->step;
R::store($this->_pokerPlayer);
return;
}
} else {
$this->output('myturn', false);
}
// own cards?
if (R::areRelated($this->_pokerPlayer, $this->_pokerRound)) {
$this->output('my_bid', $this->_pokerPlayer->bid);
$this->output('my_cards', json_decode($this->_pokerPlayer->cards, true));
}
$this->output('center_cards', $nC);
// now output opp cards/status
$opps = array();
$q = R::getAll("SELECT\n\t\t\tpp.bid AS bid,\n\t\t\tpp.cards AS cards,\n\t\t\tpp.all_in AS all_in,\n\t\t\tpp.all_in_amount AS all_in_amount,\n\t\t\tu.username AS username\n\t\tFROM\n\t\t\tpoker_player AS pp, poker_round AS pr,\n\t\t\tpoker_player_poker_round As conn,\n\t\t\tpoker_player_user AS uconn,\n\t\t\tuser AS u\n\t\tWHERE\n\t\t\tpr.id = ? AND\n\t\t\tconn.poker_round_id = pr.id AND\n\t\t\tconn.poker_player_id = pp.id AND\n\t\t\tuconn.poker_player_id = pp.id AND\n\t\t\tuconn.user_id = u.id AND\n\t\t\tu.id != ?", array($this->_pokerRound->getID(), $this->user->getID()));
foreach ($q as $o) {
$o['cards'] = json_decode($o['cards'], true);
foreach ($o['cards'] as $k => $card) {
$o['cards'][$k]['card'] = "?";
$o['cards'][$k]['color'] = "?";
}
$opps[] = $o;
}
$this->output('players', $opps);
}