当前位置: 首页>>代码示例>>PHP>>正文


PHP R::associate方法代码示例

本文整理汇总了PHP中R::associate方法的典型用法代码示例。如果您正苦于以下问题:PHP R::associate方法的具体用法?PHP R::associate怎么用?PHP R::associate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在R的用法示例。


在下文中一共展示了R::associate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: show_Join

 public function show_Join()
 {
     // check if player is already playing some round
     $isPlaying = R::getCell("SELECT\n\t\t\tcount(pp.id)\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\tWHERE\n\t\t\t(pr.state = 'running' OR pr.state = 'pending') AND\n\t\t\tconn.poker_player_id = pp.id AND\n\t\t\tconn.poker_round_id = pr.id AND\n\t\t\tpp.id = ?", array($this->_pokerPlayer->getID()));
     if ($isPlaying > 0) {
         $this->output('state', 'join_ok');
         return;
     }
     // count number of players in current&pending round
     $num = R::getCell("SELECT\n\t\t\tcount(pp.id)\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\tWHERE\n\t\t\t(pr.state = 'running' OR pr.state = 'pending') AND\n\t\t\tconn.poker_player_id = pp.id AND\n\t\t\tconn.poker_round_id = pr.id");
     if ($num >= 8) {
         $this->output('state', 'table_full');
     } else {
         // get next pending round
         $pending = R::findOne('poker_round', " state = 'pending'");
         if ($pending == null) {
             // open new pending round
             $pending = R::dispense('poker_round');
             $pending->state = 'pending';
             $pending->step = 0;
             $pending->cards = '';
             $pending->ttl = time();
             $pending->current_player = null;
             R::store($pending);
         }
         R::associate($this->_pokerPlayer, $pending);
         $this->output('state', 'join_ok');
     }
 }
开发者ID:agrafix,项目名称:managerslife,代码行数:29,代码来源:Ajax_Poker.class.php

示例2: addRight

 /**
  * add right to user
  * @param string $type
  * @return boolean
  */
 public function addRight($type)
 {
     $right = RCached::findOne('user_right', ' type = ?', array($type), date("d.m.Y"));
     if (!$right) {
         return false;
     }
     R::associate($this->bean, $right);
     return true;
 }
开发者ID:agrafix,项目名称:managerslife,代码行数:14,代码来源:Model_User.class.php

示例3: giveNewQuest

 public function giveNewQuest(RedBean_OODBBean $user)
 {
     $allQuests = Config::getConfig('npc_quests');
     $rnd = array_rand($allQuests, 1);
     $this->accepted = 0;
     $this->quest_id = $rnd;
     $this->startnpc = R::findOne('map_npc', ' map != ? ORDER BY RAND() LIMIT 1', array('adminhouse'));
     $this->stopnpc = R::findOne('map_npc', ' map != ? AND map != ? AND id != ? ORDER BY RAND() LIMIT 1', array($this->startnpc->map, 'adminhouse', $this->startnpc->getID()));
     R::store($this->bean);
     R::associate($this->bean, $user);
 }
开发者ID:agrafix,项目名称:managerslife,代码行数:11,代码来源:Model_Quests_npc.class.php

示例4: testFUSE

 /**
  * Test FUSE and model formatting.
  * 
  * @todo move tagging tests to tag tester.
  * 
  * @return void
  */
 public function testFUSE()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $blog = R::dispense('blog');
     $blog->title = 'testing';
     $blog->blog = 'tesing';
     R::store($blog);
     $blogpost = R::load("blog", 1);
     $post = R::dispense("post");
     $post->message = "hello";
     R::associate($blog, $post);
     $a = R::getAll("select * from blog ");
     RedBean_ModelHelper::setModelFormatter(new mymodelformatter());
     $w = R::dispense("weirdo");
     asrt($w->blah(), "yes!");
     R::tag($post, "lousy,smart");
     asrt(implode(',', R::tag($post)), "lousy,smart");
     R::tag($post, "clever,smart");
     $tagz = implode(',', R::tag($post));
     asrt($tagz == "smart,clever" || $tagz == "clever,smart", TRUE);
     R::tag($blog, array("smart", "interesting"));
     asrt(implode(',', R::tag($blog)), "smart,interesting");
     try {
         R::tag($blog, array("smart", "interesting", "lousy!"));
         pass();
     } catch (RedBean_Exception $e) {
         fail();
     }
     asrt(implode(',', R::tag($blog)), "smart,interesting,lousy!");
     asrt(implode(",", R::tag($blog)), "smart,interesting,lousy!");
     R::untag($blog, array("smart", "interesting"));
     asrt(implode(",", R::tag($blog)), "lousy!");
     asrt(R::hasTag($blog, array("lousy!")), TRUE);
     asrt(R::hasTag($blog, array("lousy!", "smart")), TRUE);
     asrt(R::hasTag($blog, array("lousy!", "smart"), TRUE), FALSE);
     R::tag($blog, FALSE);
     asrt(count(R::tag($blog)), 0);
     R::tag($blog, array("funny", "comic"));
     asrt(count(R::tag($blog)), 2);
     R::addTags($blog, array("halloween"));
     asrt(count(R::tag($blog)), 3);
     asrt(R::hasTag($blog, array("funny", "commic", "halloween"), TRUE), FALSE);
     R::unTag($blog, array("funny"));
     R::addTags($blog, "horror");
     asrt(count(R::tag($blog)), 3);
     asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
     // No double tags
     R::addTags($blog, "horror");
     asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
     asrt(count(R::tag($blog)), 3);
 }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:59,代码来源:Fuse.php

示例5: 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);
 }
开发者ID:agrafix,项目名称:managerslife,代码行数:50,代码来源:Model_Poker_round.class.php

示例6: api_postcommit

 public function api_postcommit()
 {
     $revision = $_POST["rev"];
     $message = $_POST["msg"];
     $post = R::dispense('homepage_posts');
     $post->title = "Update R" . $revision;
     $post->content = "Ein Update auf R" . $revision . " wurde aufgespielt. \nÄnderungen: \n\n" . $message;
     $post->link = "";
     $post->time = time();
     R::store($post);
     $usr = R::load('user', 10);
     R::associate($post, $usr);
     echo "ok";
 }
开发者ID:agrafix,项目名称:managerslife,代码行数:14,代码来源:dev_api.php

示例7: subscribe

 /**
     User adds himself to a mailing list
 */
 public static function subscribe()
 {
     if (!$_REQUEST['list']) {
         return RedView::set('error', "Choose a list.");
     }
     $list = R::load('list', $_REQUEST['list']);
     if (!$list->id) {
         return RedView::set('error', "List doesn't exist.");
     }
     $scrip = Model_Subscription::createBean($_REQUEST);
     $scrip->main = self::getUser();
     R::associate($list, $scrip);
     $_SESSION['user'] = $scrip->main->export();
     return RedView::set('message', 'Success!');
 }
开发者ID:paulk12,项目名称:redskeleton,代码行数:18,代码来源:subscribe.php

示例8: 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);
     }
 }
开发者ID:agrafix,项目名称:managerslife,代码行数:17,代码来源:Game_Poker.class.php

示例9: domainToAccount

function domainToAccount($domainname, $account, $account_id)
{
    $owner = R::findOne('owner', 'account_id=?', array($account_id));
    if ($owner === false) {
        $owner = R::dispense("owner");
        $owner->name = $account;
        $owner->account_id = $account_id;
        $id = R::store($owner);
    }
    $domain = R::findOne('domain', 'name=?', array($domainname));
    #$domain = R::load( 'domain', $id );
    R::associate($owner, $domain);
    $otherDomainsDefinedInVhost = R::find("domain", "vhost_group_key = ?", array($domain->vhost_group_key));
    foreach ($otherDomainsDefinedInVhost as $otherDomain) {
        if ($otherDomain->type === 'name') {
            continue;
        }
        R::associate($owner, $otherDomain);
    }
}
开发者ID:henrik-farre,项目名称:domains,代码行数:20,代码来源:suggest-match.php

示例10: save

 public function save($runValidation = true)
 {
     foreach ($this->deferredRelateBeans as $bean) {
         R::associate($this->bean, $bean);
         if (!RedBeanDatabase::isFrozen()) {
             $types = array($this->bean->getMeta("type"), $bean->getMeta("type"));
             sort($types);
             $tableName = implode("_", $types);
             foreach ($types as $type) {
                 $columnName = "{$type}_id";
                 RedBeanColumnTypeOptimizer::optimize($tableName, $columnName, 'id');
             }
         }
     }
     $this->deferredRelateBeans = array();
     foreach ($this->deferredUnrelateBeans as $bean) {
         R::unassociate($this->bean, $bean);
     }
     $this->deferredUnrelateBeans = array();
     return true;
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:21,代码来源:RedBeanManyToManyRelatedModels.php

示例11: testBasicThroughFacade

 /**
  * Basic tests through Facade.
  * 
  * @return void
  */
 public function testBasicThroughFacade()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $a = new RedBean_AssociationManager($toolbox);
     asrt(R::$redbean instanceof RedBean_OODB, TRUE);
     asrt(R::$toolbox instanceof RedBean_Toolbox, TRUE);
     asrt(R::$adapter instanceof RedBean_Adapter, TRUE);
     asrt(R::$writer instanceof RedBean_QueryWriter, TRUE);
     $book = R::dispense("book");
     asrt($book instanceof RedBean_OODBBean, TRUE);
     $book->title = "a nice book";
     $id = R::store($book);
     asrt($id > 0, TRUE);
     $book = R::load("book", (int) $id);
     asrt($book->title, "a nice book");
     $author = R::dispense("author");
     $author->name = "me";
     R::store($author);
     $book9 = R::dispense("book");
     $author9 = R::dispense("author");
     $author9->name = "mr Nine";
     $a9 = R::store($author9);
     $book9->author_id = $a9;
     $bk9 = R::store($book9);
     $book9 = R::load("book", $bk9);
     $author = R::load("author", $book9->author_id);
     asrt($author->name, "mr Nine");
     R::trash($author);
     R::trash($book9);
     pass();
     $book2 = R::dispense("book");
     $book2->title = "second";
     R::store($book2);
     R::associate($book, $book2);
     asrt(count(R::related($book, "book")), 1);
     $book3 = R::dispense("book");
     $book3->title = "third";
     R::store($book3);
     R::associate($book, $book3);
     asrt(count(R::related($book, "book")), 2);
     asrt(count(R::find("book")), 3);
     asrt(count(R::findAll("book")), 3);
     asrt(count(R::findAll("book", " WHERE ROWNUM <= 2")), 2);
     asrt(count(R::find("book", " id=id ")), 3);
     asrt(count(R::find("book", " title LIKE ?", array("third"))), 1);
     asrt(count(R::find("book", " title LIKE ?", array("%d%"))), 2);
     // Now with new SQL Helper argument
     asrt(count(R::find("book", R::$f->begin()->addSQL('title LIKE ? ')->put('third'))), 1);
     asrt(count(R::find("book", R::$f->begin()->addSQL('title LIKE ? ')->put('%d%'))), 2);
     asrt(count(R::find("book", R::$f->begin()->addSQL('title')->like(' ? ')->addSQL(' ORDER BY id ')->desc()->put('%d%'))), 2);
     //Find without where clause
     asrt(count(R::findAll('book', ' order by id')), 3);
     R::unassociate($book, $book2);
     asrt(count(R::related($book, "book")), 1);
     R::trash($book3);
     R::trash($book2);
     asrt(count(R::related($book, "book")), 0);
     asrt(count(R::getAll("SELECT * FROM book ")), 1);
     asrt(count(R::getCol("SELECT title FROM book ")), 1);
     asrt((int) R::getCell("SELECT 123 FROM DUAL "), 123);
     $book = R::dispense("book");
     $book->title = "not so original title";
     $author = R::dispense("author");
     $author->name = "Bobby";
     R::store($book);
     $aid = R::store($author);
     R::associate($book, $author);
     $author = R::findOne("author", " name = ? ", array("Bobby"));
     $books = R::related($author, "book");
     $book = reset($books);
     testpack("Test Swap function in R-facade");
     $book = R::dispense("book");
     $book->title = "firstbook";
     $book->rating = 2;
     $id1 = R::store($book);
     $book = R::dispense("book");
     $book->title = "secondbook";
     $book->rating = 3;
     $id2 = R::store($book);
     $book1 = R::load("book", $id1);
     $book2 = R::load("book", $id2);
     asrt($book1->rating, '2');
     asrt($book2->rating, '3');
     $books = R::batch("book", array($id1, $id2));
     R::swap($books, "rating");
     $book1 = R::load("book", $id1);
     $book2 = R::load("book", $id2);
     asrt($book1->rating, '3');
     asrt($book2->rating, '2');
     testpack("Test R::convertToBeans");
     $SQL = "SELECT '1' as id, a.name AS name, b.title AS title, '123' as rating FROM author a LEFT JOIN book b ON b.id = ?  WHERE a.id = ? ";
//.........这里部分代码省略.........
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:101,代码来源:Facade.php

示例12: tag

 public static function tag(RedBean_OODBBean $bean, $tagList = null)
 {
     if (is_null($tagList)) {
         $tags = R::related($bean, "tag");
         $foundTags = array();
         foreach ($tags as $tag) {
             $foundTags[] = $tag->title;
         }
         if (self::$flagUseLegacyTaggingAPI) {
             return implode(",", $foundTags);
         }
         return $foundTags;
     }
     if ($tagList !== false && !is_array($tagList)) {
         $tags = explode(",", (string) $tagList);
     } else {
         $tags = $tagList;
     }
     R::clearRelations($bean, "tag");
     if ($tagList === false) {
         return;
     }
     foreach ($tags as $tag) {
         $t = R::findOne("tag", " title = ? ", array($tag));
         if (!$t) {
             $t = R::dispense("tag");
             $t->title = $tag;
             R::store($t);
         }
         R::associate($bean, $t);
     }
 }
开发者ID:bobseven,项目名称:Slim-Blog,代码行数:32,代码来源:rb.php

示例13: exec

 public function exec($params)
 {
     $data = unserialize(base64_decode($_POST['data']));
     $linker = mvc\retrieve('beanLinker');
     if ($data['hostname'] == null || empty($data['hostname'])) {
         die('Missing hostname');
     }
     $server = R::findOne("server", "name = ? ", array($data['hostname']));
     if (!$server instanceof RedBean_OODBBean) {
         $server = R::dispense('server');
         $server->created = mktime();
     }
     $server->updated = mktime();
     $server->name = $data['hostname'];
     $server->int_ip = $data['ipaddress'];
     $server->ext_ip = preg_match('/^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:[.](?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$/', $data['external_ip']) ? $data['external_ip'] : '';
     $hardware = array('memory' => $data['memorysize'], 'cpucount' => $data['processorcount'], 'cpu' => $data['processor0']);
     if (isset($data['disk']['partitions'])) {
         $hardware['partitions'] = $data['disk']['partitions'];
     }
     $server->kernel_release = $data['kernelrelease'];
     $server->os = $data['lsbdistid'];
     $server->os_release = $data['lsbdistrelease'];
     $server->arch = $data['hardwaremodel'];
     $server->hardware = serialize($hardware);
     $server->type = $data['virtual'];
     $server->comment = $server->comment;
     // keep existing comment - should be dropped when schema is frozen
     $server->is_active = true;
     $server->uptime = isset($data['uptime']) ? $data['uptime'] : 0.0;
     $server->software_updates = !empty($data['software_updates']) ? serialize($data['software_updates']) : null;
     $serverID = R::store($server);
     if (isset($data['disk']['physical'])) {
         foreach ($data['disk']['physical'] as $disk) {
             // TODO: set drives inactive to make sure only active drives are is_active = true;
             $drive = R::findOne("drive", "serial_no=?", array($disk['SerialNo']));
             if (!$drive instanceof RedBean_OODBBean) {
                 $drive = R::dispense('drive');
                 $drive->created = mktime();
                 $drive->updated = mktime();
                 $drive->is_active = true;
                 $drive->setBrand($disk['Model']);
                 $drive->model = $disk['Model'];
                 $drive->serial_no = $disk['SerialNo'];
                 $drive->fw_revision = $disk['FwRev'];
                 $drive->type = $disk['type'];
             } else {
                 $drive->is_active = true;
                 $drive->updated = mktime();
             }
             R::store($drive);
             R::associate($server, $drive);
         }
     }
     if ($server->type === 'xen0' && isset($data['domUs']) && !empty($data['domUs'])) {
         foreach ($data['domUs'] as $domUName) {
             $domU = array();
             $result = array();
             $domU = R::findOne("server", "name=?", array($domUName));
             if (!$domU instanceof RedBean_OODBBean) {
                 $domU = R::dispense('server');
                 $domU->name = $domUName;
                 $domU->created = mktime();
                 $domU->updated = mktime();
                 $domU->type = 'xenu';
                 R::attach($server, $domU);
                 $domUID = R::store($domU);
             } else {
                 $domU->updated = mktime();
                 R::attach($server, $domU);
                 // server is parent of domU
             }
         }
     }
     // Handle domains
     if (isset($data['vhosts'])) {
         $updateTimestamp = mktime();
         foreach ($data['vhosts'] as $v) {
             $vhost = R::findOne('vhost', 'server_id=? AND server_name=?', array($serverID, $v['servername']));
             if (!$vhost instanceof RedBean_OODBBean) {
                 $vhost = R::dispense('vhost');
                 $vhost->created = $updateTimestamp;
             }
             $vhost->updated = $updateTimestamp;
             $vhost->server_name = $v['servername'];
             $vhost->file_name = isset($v['filename']) ? $v['filename'] : null;
             $vhost->document_root = isset($v['documentroot']) ? $v['documentroot'] : null;
             $vhost->server_admin = isset($v['serveradmin']) ? $v['serveradmin'] : null;
             $app = null;
             if (isset($v['app']['name'])) {
                 $app = R::findOne('app', 'name=?', array($v['app']['name']));
                 if (!$app instanceof RedBean_OODBBean) {
                     $app = R::dispense('app');
                     $app->name = $v['app']['name'];
                     R::store($app);
                 }
             }
             $vhost->app_version = isset($v['app']['version']) ? $v['app']['version'] : null;
             //$vhost->is_valid      = true;
             $vhost->comment = '';
//.........这里部分代码省略.........
开发者ID:henrik-farre,项目名称:domains,代码行数:101,代码来源:class.dataCollectorHandler.php

示例14: testViews

 function testViews($p)
 {
     R::exec(" drop table if exists bandmember_musician CASCADE");
     R::exec(" drop table if exists band_bandmember CASCADE");
     R::exec(" drop table if exists prefix_bandmember_musician CASCADE");
     R::exec(" drop table if exists prefix_band_bandmember CASCADE");
     R::exec(" drop table if exists musician CASCADE ");
     R::exec(" drop table if exists bandmember CASCADE");
     R::exec(" drop table if exists band CASCADE");
     R::exec(" drop table if exists prefix_musician CASCADE");
     R::exec(" drop table if exists prefix_bandmember CASCADE");
     R::exec(" drop table if exists prefix_band CASCADE");
     list($mickey, $donald, $goofy) = R::dispense("musician", 3);
     list($vocals1, $vocals2, $keyboard1, $drums, $vocals3, $keyboard2) = R::dispense("bandmember", 6);
     list($band1, $band2) = R::dispense("band", 2);
     $band1->name = "The Groofy";
     $band2->name = "Wickey Mickey";
     $mickey->name = "Mickey";
     $goofy->name = "Goofy";
     $donald->name = "Donald";
     $vocals1->instrument = "voice";
     $vocals2->instrument = "voice";
     $keyboard1->instrument = "keyboard";
     $drums->instrument = "drums";
     $vocals3->instrument = "voice";
     $keyboard2->instrument = "keyboard";
     $vocals3->bandleader = true;
     $drums->bandleader = true;
     $drums->notes = "noisy";
     $vocals3->notes = "tenor";
     R::associate($mickey, $vocals1);
     R::associate($donald, $vocals2);
     R::associate($donald, $keyboard1);
     R::associate($goofy, $drums);
     R::associate($mickey, $vocals3);
     R::associate($donald, $keyboard2);
     R::associate($band1, $vocals1);
     R::associate($band1, $vocals2);
     R::associate($band1, $keyboard1);
     R::associate($band1, $drums);
     R::associate($band2, $vocals3);
     R::associate($band2, $keyboard2);
     try {
         R::view("bandlist", "band");
         fail();
     } catch (Exception $e) {
         pass();
     }
     try {
         R::view("bandlist", "band,bandmember,musician");
         pass();
     } catch (Exception $e) {
         print_r($e);
         fail();
     }
     //can we do a simple query?
     $nameOfBandWithID1 = R::getCell("select name from " . $p . "bandlist where " . R::$writer->getIDField("band") . " = 1\ngroup by  " . R::$writer->getIDField("band") . ",\"name\"");
     asrt($nameOfBandWithID1, "The Groofy");
     //can we generate a report? list all bandleaders
     $bandleaders = R::getAll("select  bandleader_of_bandmember,name_of_musician,\"name\" AS bandname\n\tfrom " . $p . "bandlist where bandleader_of_bandmember =  1 group by id ");
     foreach ($bandleaders as $bl) {
         if ($bl["bandname"] == "Wickey Mickey") {
             asrt($bl["name_of_musician"], "Mickey");
         }
         if ($bl["bandname"] == "The Groofy") {
             asrt($bl["name_of_musician"], "Goofy");
         }
     }
     //can we draw statistics?
     $inHowManyBandsDoYouPlay = R::getAll("select\nname_of_musician ,count( distinct " . R::$writer->getIDField("band") . ") as bands\nfrom " . $p . "bandlist group by " . R::$writer->getIDField("musician") . "_of_musician,name_of_musician order by name_of_musician asc\n");
     asrt($inHowManyBandsDoYouPlay[0]["name_of_musician"], "Donald");
     asrt($inHowManyBandsDoYouPlay[0]["bands"], '2');
     asrt($inHowManyBandsDoYouPlay[1]["name_of_musician"], "Goofy");
     asrt($inHowManyBandsDoYouPlay[1]["bands"], '1');
     asrt($inHowManyBandsDoYouPlay[2]["name_of_musician"], "Mickey");
     asrt($inHowManyBandsDoYouPlay[2]["bands"], '2');
     //who plays in band 2
     //can we make a selectbox
     $selectbox = R::getAll("\n\tselect m." . R::$writer->getIDField("musician") . ", m.name, b." . R::$writer->getIDField("band") . " as selected from " . $p . "musician as m\n\tleft join " . $p . "bandlist as b on b." . R::$writer->getIDField("musician") . "_of_musician = m." . R::$writer->getIDField("musician") . " and\n\tb." . R::$writer->getIDField("band") . " =2\n\torder by m.name asc\n");
     asrt($selectbox[0]["name"], "Donald");
     asrt($selectbox[0]["selected"], "2");
     asrt($selectbox[1]["name"], "Goofy");
     asrt($selectbox[1]["selected"], null);
     asrt($selectbox[2]["name"], "Mickey");
     asrt($selectbox[2]["selected"], "2");
 }
开发者ID:ryjkov,项目名称:redbean,代码行数:86,代码来源:pgtest.php

示例15: testCreationOfLinkTable

 /**
  * Test creation of link table.
  * 
  * @return void
  */
 public function testCreationOfLinkTable()
 {
     asrt(in_array('consult', R::$writer->getTables()), FALSE);
     $d = R::dispense('doctor')->setAttr('name', 'd1');
     $p = R::dispense('patient')->setAttr('name', 'p1');
     R::associate($d, $p);
     asrt(in_array('consult', R::$writer->getTables()), TRUE);
 }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:13,代码来源:Relations.php


注:本文中的R::associate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。