本文整理汇总了PHP中R::related方法的典型用法代码示例。如果您正苦于以下问题:PHP R::related方法的具体用法?PHP R::related怎么用?PHP R::related使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::related方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show_Show
public function show_Show()
{
if (!$this->user->hasPremium()) {
$this->error('Nur für Premiumaccounts.');
}
$o = '<h3>Aktuelle Lagerverwaltungs-Regeln</h3>';
$o .= '<table class="ordered">
<tr>
<th>Aktion</th>
<th>Ressource/Produkt</th>
<th>Lager-Limit</th>
<th>Preis pro VE</th>
<th>Gültig bis</th>
<th></th>
</tr>';
$show = R::related($this->myCompany, 'crule');
foreach ($show as $s) {
$o .= '<tr>
<td>' . ($s->action == 'buy' ? 'Kaufen' : 'Verkaufen') . '</td>
<td>{' . ($s->r_type == 'resource' ? 'r' : 'p') . '_' . $s->r_name . '}</td>
<td>' . ($s->action == 'buy' ? '<' : '>') . ' ' . formatCash($s->r_limit) . '</td>
<td>' . formatCash($s->r_price) . ' {money}</td>
<td>' . date('d.m.Y - H:i:s', $s->until) . '</td>
<td><a href="#cancel/' . $s->id . '">{cross title="Stornieren"}</a></td>
</tr>';
}
$o .= '</table>';
$this->output('maintext', $o);
$this->output('options', array('add' => 'Neue Regel hinzufügen'));
}
示例2: testOCIVaria
/**
* Various.
* Various test for OCI. Some basic test cannot be performed because
* practical issues (configuration testing VM image etc..).
*
* @return void
*/
public function testOCIVaria()
{
$village = R::dispense('village');
$village->name = 'Lutry';
$id = R::store($village);
$village = R::load('village', $id);
asrt($village->name, 'Lutry');
list($mill, $tavern) = R::dispense('building', 2);
$village->ownBuilding = array($mill, $tavern);
//replaces entire list
$id = R::store($village);
asrt($id, 1);
$village = R::load('village', $id);
asrt(count($village->ownBuilding), 2);
$village2 = R::dispense('village');
$army = R::dispense('army');
$village->sharedArmy[] = $army;
$village2->sharedArmy[] = $army;
R::store($village);
$id = R::store($village2);
$village = R::load('village', $id);
$army = $village->sharedArmy;
$myVillages = R::related($army, 'village');
asrt(count($myVillages), 2);
echo PHP_EOL;
}
示例3: __construct
/**
* Constructs a new RedBeanModels which is a collection of classes extending model.
* The models are created lazily.
* Models are only constructed with beans by the model. Beans are
* never used by the application directly.
*/
public function __construct(RedBean_OODBBean $bean, $modelClassName)
{
assert('is_string($modelClassName)');
assert('$modelClassName != ""');
$this->modelClassName = $modelClassName;
$tableName = RedBeanModel::getTableName($modelClassName);
$this->bean = $bean;
$this->relatedBeansAndModels = array_values(R::related($this->bean, $tableName));
}
示例4: init
public function init()
{
parent::init();
$this->myQuests = R::related($this->user, 'company_quest');
if (!R::findOne('company', ' user_id = ?', array($this->user->id))) {
$this->error('Du besitzt keine Firma. Geh ins Nachbargebäude und gründe dort
eine Firma bevor du Aufträge annehmen kannst.');
}
}
示例5: getUnrelatedMainDomains
/**
* Returns all the domains that does not have an owner and is of type: name
*
* @return array Contains Domain Beans
* @author Henrik Farre <hf@bellcom.dk>
**/
function getUnrelatedMainDomains()
{
$allDomains = R::find('domain');
$unrelatedDomains = array();
foreach ($allDomains as $domain) {
$relations = array();
$relations = R::related($domain, 'owner');
if (empty($relations)) {
$unrelatedDomains[] = $domain;
}
}
return $unrelatedDomains;
}
示例6: init
public function init()
{
parent::init();
$this->company = R::findOne('company', ' user_id = ?', array($this->user->id));
if ($this->company) {
$this->company_ress = R::findOne('company_ress', 'company_id = ?', array($this->company->id));
$this->company_products = R::findOne('company_products', 'company_id = ?', array($this->company->id));
$this->company_machines = R::findOne('company_machines', 'company_id = ?', array($this->company->id));
$this->initRess();
$this->quests_running = R::related($this->user, 'company_quest', ' completed = 0');
$this->quests_complete = R::related($this->user, 'company_quest', ' completed = 1');
}
}
示例7: 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);
}
示例8: __construct
/**
* Constructs a new RedBeanModels which is a collection of classes extending model.
* The models are created lazily.
* Models are only constructed with beans by the model. Beans are
* never used by the application directly.
*/
public function __construct(RedBean_OODBBean $bean, $modelClassName, $linkType, $linkName = null)
{
assert('is_string($modelClassName)');
assert('$modelClassName != ""');
assert('is_int($linkType)');
assert('is_string($linkName) || $linkName == null');
assert('($linkType == RedBeanModel::LINK_TYPE_ASSUMPTIVE && $linkName == null) ||
($linkType == RedBeanModel::LINK_TYPE_SPECIFIC && $linkName != null)');
$this->modelClassName = $modelClassName;
$tableName = RedBeanModel::getTableName($modelClassName);
$this->bean = $bean;
$this->linkName = $linkName;
if ($this->bean->id > 0) {
$this->relatedBeansAndModels = array_values(R::related($this->bean, $tableName, null, array(), $this->getTableName(R::dispense($tableName))));
} else {
$this->relatedBeansAndModels = array();
}
}
示例9: beforeRender
public function beforeRender()
{
parent::beforeRender();
$listsAvailable = R::find('list');
$html = '';
foreach ($listsAvailable as $l) {
$html .= "<option value='{$l->id}'>{$l->name}</option>";
}
$this->listsAvailable = $html;
$user = self::getUser();
if (!($user && $user->id)) {
return;
}
$inLists = R::related($user, 'list');
$html = '';
foreach ($inLists as $l) {
$html .= "<li value='{$l->id}'>{$l->name}</li>";
}
$this->inLists = "<ul>{$html}</ul>";
}
示例10: strtolower
echo '</td>';
break;
case 'uptime':
echo '<td class="' . $key . '">' . ($server->{$key} > 0 ? (int) ($server->{$key} / 60 / 60 / 24) . ' days' : '') . '</td>';
break;
case 'os':
echo '<td class="os ' . strtolower($server->os) . '">' . $server->os . '</td>';
break;
case 'cpu_count':
echo '<td class="hardware cpu' . ($hardware['cpucount'] ? '' : ' error') . '">' . ($hardware['cpucount'] ?: '<span class="error">?</span>') . '</td>';
break;
case 'memory':
echo '<td class="hardware memory' . (empty($hardware['memory']) ? ' error' : '') . '">' . (empty($hardware['memory']) ? '?' : $hardware['memory']) . '</td>';
break;
case 'drives':
$drives = R::related($server, 'drive');
echo '<td class="hardware drives">';
if (!empty($drives)) {
foreach ($drives as $d) {
echo '<div class="tooltip_trigger"><img src="/design/desktop/images/' . ($d->type == 'harddrive' ? 'harddrive' : 'drive-cdrom') . '.png" class="icon"/></div>
<div class="tooltip">
' . $d->brand . '<br/>
Model: ' . $d->model . '<br/>
Serial: ' . $d->serial_no . '<br/>
Firmware: ' . $d->fw_revision . '</div>';
}
}
echo '</td>';
break;
case 'partitions':
echo '<td class="hardware partitions">';
示例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: ownerSearch
/**
* Searches for owners (accounts assigned to domains)
*
* @return array
* @author Henrik Farre <hf@bellcom.dk>
**/
private function ownerSearch($str)
{
$finalResults = array();
$initialResults = R::find('owner', 'name LIKE ?', array($str));
foreach ($initialResults as $result) {
$domains = R::related($result, 'domain');
$str = '';
foreach ($domains as $domain) {
$str .= $domain->name . '<br/>';
}
$formattedResult = array('id' => $result->id, 'label' => $result->name, 'type' => $this->type, 'desc' => '<tr><td></td><td>' . $result->name . '</td><td>' . $str . '</td></tr>');
$finalResults[] = $formattedResult;
}
return $finalResults;
}
示例13: asrt
//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);
$t3 = R::load('topic', $topic3->id);
asrt(count($t3->sharedBook), 2);
//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);
示例14: related
public function related($bean, $type, $sql = ' true ', $values = array())
{
return R::related($bean, $type, $sql, $values);
}
示例15: array
$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);
}
testpack("unrelated");
$pdo->Execute("DROP TABLE person_person");
$pdo->Execute("DROP TABLE person");