本文整理汇总了PHP中R::storeAll方法的典型用法代码示例。如果您正苦于以下问题:PHP R::storeAll方法的具体用法?PHP R::storeAll怎么用?PHP R::storeAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::storeAll方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addItemToDB
function addItemToDB($filename, $categories)
{
$itemData = json_decode(file_get_contents(__DIR__ . "/../data/items/{$filename}"), true);
$itemData = array_map(function ($x) use($categories) {
$x['_type'] = 'item';
$x['shop'] = R::findOne('shop', 'reference = ?', [$x['shopReference']]);
unset($x['shopReference']);
foreach ($categories as $cat) {
if (strtolower($x['category']) === strtolower($cat['name'])) {
$x['category'] = $cat;
break;
}
}
return $x;
}, $itemData);
$items = R::dispense($itemData);
foreach ($items as $item) {
R::storeAll($items);
}
}
示例2: json_decode
exit;
}
} else {
if (isset($_POST) && count($_POST) > 0) {
// push 模式 part 2:從手機上傳送資料給伺服器
if (isset($_POST["logs"]) && isset($_POST["uuid"])) {
$uuid = $_POST["uuid"];
$logs_ary = json_decode($_POST["logs"]);
} else {
exit;
}
//print_r($logs_ary);
if (count($logs_ary) > 1) {
$log_beans = R::dispense("log", count($logs_ary));
foreach ($logs_ary as $i => $log) {
$log_beans[$i]->uuid = $uuid;
$log_beans[$i]->import($log);
}
R::storeAll($log_beans);
} else {
if (count($logs_ary) === 1) {
$log_bean = R::dispense("log");
$log_bean->uuid = $uuid;
$log_bean->import($logs_ary);
R::store($log_bean);
}
}
//sync_complete($uuid, "push");
jsonp_callback(true);
}
}
示例3: testOneToOne
/**
* Test limited support for 1-to-1 associations.
*
* @return void
*/
public function testOneToOne()
{
testpack('Testing one-to-ones');
$author = R::dispense('author')->setAttr('name', 'a');
$bio = R::dispense('bio')->setAttr('name', 'a');
R::storeAll(array($author, $bio));
$id1 = $author->id;
$author = R::dispense('author')->setAttr('name', 'b');
$bio = R::dispense('bio')->setAttr('name', 'b');
R::storeAll(array($author, $bio));
$id2 = $author->id;
list($a, $b) = R::loadMulti('author,bio', $id1);
asrt($a->name, $b->name);
asrt($a->name, 'a');
list($a, $b) = R::loadMulti('author,bio', $id2);
asrt($a->name, $b->name);
asrt($a->name, 'b');
list($a, $b) = R::loadMulti(array('author', 'bio'), $id1);
asrt($a->name, $b->name);
asrt($a->name, 'a');
list($a, $b) = R::loadMulti(array('author', 'bio'), $id2);
asrt($a->name, $b->name);
asrt($a->name, 'b');
asrt(is_array(R::loadMulti(NULL, 1)), TRUE);
asrt(count(R::loadMulti(NULL, 1)) === 0, TRUE);
}
示例4: install
//.........这里部分代码省略.........
$previewimg = 'web/images/module/idiomswitcher.png';
$langblock = $this->layout_model->createModule('Language Selection', 'crm/lang_lblock', NULL, $previewimg);
$langblock->owner = $account_admin;
R::store($langblock);
// Register featuresearch block
$previewimg = 'web/images/module/featuresearch.png';
$searchblock = $this->layout_model->createModule('Feature Search', 'openlayers/featuresearch_lblock', 'olmap', $previewimg);
$searchblock->owner = $account_admin;
R::store($searchblock);
// Register Google Maps Api module
$modgmapsapi = $this->layout_model->createModule('Load Google Maps API', 'openlayers/modgmapsapiv3_lblock');
$modgmapsapi->owner = $account_admin;
R::store($modgmapsapi);
// Register gefeaturesearch block
$previewimg = 'web/images/module/gefeaturesearch.png';
$gesearchblock = $this->layout_model->createModule('Google Earth Search', 'googleearth/gefeaturesearch_lblock', 'gemap', $previewimg);
$gesearchblock->owner = $account_admin;
R::store($gesearchblock);
// Create layout
$layout_public = $this->layout_model->create('public', 'layout/publicfullscreen2');
$layout_public->owner = $account_admin;
R::store($layout_public);
// Create public layout slots
$pslot1 = $this->layout_model->createSlot('slot1', $layout_public);
$pslot2 = $this->layout_model->createSlot('slot2', $layout_public);
$pslot3 = $this->layout_model->createSlot('slot3', $layout_public);
$pslot4 = $this->layout_model->createSlot('slot4', $layout_public);
$pslot5 = $this->layout_model->createSlot('slot5', $layout_public);
$pslot1->owner = $account_admin;
$pslot2->owner = $account_admin;
$pslot3->owner = $account_admin;
$pslot4->owner = $account_admin;
$pslot5->owner = $account_admin;
R::storeAll(array($pslot1, $pslot2, $pslot3, $pslot4, $pslot5));
// Create module layout
$layout_mod = $this->layout_model->create('module', 'layout/module');
$layout_mod->owner = $account_admin;
R::store($layout_mod);
// Create module layout slots
$mslot1 = $this->layout_model->createSlot('slot1', $layout_mod);
$mslot2 = $this->layout_model->createSlot('slot2', $layout_mod);
$mslot3 = $this->layout_model->createSlot('slot3', $layout_mod);
$mslot1->owner = $account_admin;
$mslot2->owner = $account_admin;
$mslot3->owner = $account_admin;
R::storeAll(array($mslot1, $mslot2, $mslot3));
// Create layout blocks
$lblock2 = $this->layout_model->createBlock('authblock', $authblock, 1);
$lblock2->owner = $account_admin;
R::storeAll(array($lblock2));
// Create tickets layout block
$lblock3 = $this->layout_model->createBlock('tickets', $ticketsblock, 2);
$lblock3->owner = $account_admin;
R::storeAll(array($lblock3));
// Create layerswitcher layout block
$lblock4 = $this->layout_model->createBlock('layerswitcher1', $layerswitcherblock, 3, '', 1);
$lblock4->owner = $account_admin;
R::storeAll(array($lblock4));
// Create layout blocks
$footerblock = $this->layout_model->createBlock('footerblock', $footermod, 1);
$footerblock->owner = $account_admin;
$creditsblock = $this->layout_model->createBlock('creditsblock', $creditsmod, 2);
$creditsblock->owner = $account_admin;
R::storeAll(array($footerblock, $creditsblock));
// Create language blocks
$lblock5 = $this->layout_model->createBlock('langblock', $langblock, 3);
示例5: testEmbeddedSQLPart2
/**
* More variations...
*
* @return void
*/
public function testEmbeddedSQLPart2()
{
list($book1, $book2, $book3) = R::dispense('book', 3);
$book1->position = 1;
$book2->position = 2;
$book3->position = 3;
$shelf = R::dispense('shelf');
$shelf->ownBook = array($book1, $book2, $book3);
$id = R::store($shelf);
$shelf = R::load('shelf', $id);
$books = $shelf->with(' ORDER BY position ASC ')->ownBook;
$book1 = array_shift($books);
asrt((int) $book1->position, 1);
$book2 = array_shift($books);
asrt((int) $book2->position, 2);
$book3 = array_shift($books);
asrt((int) $book3->position, 3);
$books = $shelf->with(' ORDER BY position DESC ')->ownBook;
$book1 = array_shift($books);
asrt((int) $book1->position, 3);
$book2 = array_shift($books);
asrt((int) $book2->position, 2);
$book3 = array_shift($books);
asrt((int) $book3->position, 1);
//R::debug(1);
$shelf = R::load('shelf', $id);
$books = $shelf->with(' AND position > 2 ')->ownBook;
asrt(count($books), 1);
$shelf = R::load('shelf', $id);
$books = $shelf->with(' AND position < ? ', array(3))->ownBook;
asrt(count($books), 2);
$shelf = R::load('shelf', $id);
$books = $shelf->with(' AND position = 1 ')->ownBook;
asrt(count($books), 1);
$shelf = R::load('shelf', $id);
$books = $shelf->withCondition(' position > -1 ')->ownBook;
asrt(count($books), 3);
// With-condition should not affect storing
$shelf = R::load('shelf', $id);
$books = $shelf->with(' AND position = 1 ')->ownBook;
asrt(count($books), 1);
asrt(count($shelf->ownBook), 1);
$book = reset($shelf->ownBook);
$book->title = 'Trees and other Poems';
R::store($shelf);
$books = $shelf->withCondition(' position > -1 ')->ownBook;
asrt(count($books), 3);
asrt(count($shelf->ownBook), 3);
$shelf = R::load('shelf', $id);
$books = $shelf->with(' AND position = 1 ')->ownBook;
// Also with trashing -- just trash one!
$shelf->ownBook = array();
R::store($shelf);
$books = $shelf->withCondition(' position > -1 ')->ownBook;
asrt(count($books), 2);
// With should cause a reload of a list
$shelf = R::load('shelf', $id);
$books = $shelf->with(' AND position = 2 ')->ownBook;
asrt(count($books), 1);
$books = $shelf->withCondition(' position > -1 ')->ownBook;
asrt(count($books), 2);
$book = reset($books);
$book->title = 'Venetian Music';
// Should not affect storage (fact that we used with twice, unsetting prop)
R::store($shelf);
$shelf = R::load('shelf', $id);
asrt(count($shelf->ownBook), 2);
// Alias
list($game1, $game2, $game3) = R::dispense('game', 3);
list($t1, $t2, $t3) = R::dispense('team', 3);
$t1->name = 'Bats';
$t2->name = 'Tigers';
$t3->name = 'Eagles';
$game1->name = 'a';
$game1->team1 = $t1;
$game1->team2 = $t2;
$game2->name = 'b';
$game2->team1 = $t1;
$game2->team2 = $t3;
$game3->name = 'c';
$game3->team1 = $t2;
$game3->team2 = $t3;
R::storeAll(array($game1, $game2, $game3));
$team1 = R::load('team', $t1->id);
$team2 = R::load('team', $t2->id);
$team3 = R::load('team', $t3->id);
asrt(count($team1->alias('team1')->ownGame), 2);
asrt(count($team2->alias('team1')->ownGame), 1);
$team1 = R::load('team', $t1->id);
$team2 = R::load('team', $t2->id);
asrt(count($team1->alias('team2')->ownGame), 0);
asrt(count($team2->alias('team2')->ownGame), 1);
asrt(count($team3->alias('team1')->ownGame), 0);
$team3 = R::load('team', $t3->id);
asrt(count($team3->alias('team2')->ownGame), 2);
//.........这里部分代码省略.........
示例6: json_encode
echo json_encode(['result' => 'failed', 'error' => 'invalid post data']);
die;
}
// Insert
R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
R::selectDatabase('wechat_csc');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
// Insert
try {
$surveys = R::getRedBean()->dispense('wxcsc_survey', count($answers));
for ($i = 0; $i < count($answers); $i++) {
list($q, $a) = explode(':', $answers[$i]);
$surveys[$i]->survey_id = $survey_id;
$surveys[$i]->username = $user_name;
$surveys[$i]->question_id = $q;
$surveys[$i]->answer = $a;
}
$ids = R::storeAll($surveys);
} catch (Exception $e) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'db error wechat', 'details' => $e->getMessage()]);
die;
}
R::close();
// Return
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'true']);
die;
示例7: testDriver
/**
* Test the database driver and low level functions.
*
* @return void
*/
public function testDriver()
{
$currentDriver = $this->currentlyActiveDriverID;
R::store(R::dispense('justabean'));
$adapter = new TroubleDapter(R::$toolbox->getDatabaseAdapter()->getDatabase());
$adapter->setSQLState('HY000');
$writer = new RedBean_QueryWriter_SQLiteT($adapter);
$redbean = new RedBean_OODB($writer);
$toolbox = new RedBean_ToolBox($redbean, $adapter, $writer);
// We can only test this for a known driver...
if ($currentDriver === 'sqlite') {
try {
$redbean->find('bean');
pass();
} catch (Exception $e) {
var_dump($e->getSQLState());
fail();
}
}
$adapter->setSQLState(-999);
try {
$redbean->find('bean');
fail();
} catch (Exception $e) {
pass();
}
$beanA = R::dispense('bean');
$beanB = R::dispense('bean');
R::storeAll(array($beanA, $beanB));
$associationManager = new RedBean_AssociationManager($toolbox);
$adapter->setSQLState('HY000');
// We can only test this for a known driver...
if ($currentDriver === 'sqlite') {
try {
$associationManager->areRelated($beanA, $beanB);
pass();
} catch (Exception $e) {
fail();
}
}
$adapter->setSQLState(-999);
try {
$associationManager->areRelated($beanA, $beanA);
fail();
} catch (Exception $e) {
pass();
}
try {
$redbean->wipe('justabean');
fail();
} catch (Exception $e) {
pass();
}
$toolbox = R::$toolbox;
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
$page = $redbean->dispense("page");
try {
$adapter->exec("an invalid query");
fail();
} catch (RedBean_Exception_SQL $e) {
pass();
}
// Special data type description should result in magic number 99 (specified)
if ($currentDriver == 'mysql') {
asrt($writer->code(RedBean_QueryWriter_MySQL::C_DATATYPE_SPECIAL_DATE), 99);
}
if ($currentDriver == 'pgsql') {
asrt($writer->code(RedBean_QueryWriter_PostgreSQL::C_DATATYPE_SPECIAL_DATE), 99);
}
if ($currentDriver == 'CUBRID') {
asrt($writer->code(RedBean_QueryWriter_CUBRID::C_DATATYPE_SPECIAL_DATE), 99);
}
asrt((int) $adapter->getCell("SELECT 123"), 123);
$page->aname = "my page";
$id = (int) $redbean->store($page);
asrt((int) $page->id, 1);
asrt((int) $pdo->GetCell("SELECT count(*) FROM page"), 1);
asrt($pdo->GetCell("SELECT aname FROM page LIMIT 1"), "my page");
asrt((int) $id, 1);
$page = $redbean->load("page", 1);
asrt($page->aname, "my page");
asrt((bool) $page->getMeta("type"), TRUE);
asrt(isset($page->id), TRUE);
asrt($page->getMeta("type"), "page");
asrt((int) $page->id, $id);
}
示例8: testBatchAliasLoadAll
/**
* Test batch alias loadAll.
*
* @return void
*/
public function testBatchAliasLoadAll()
{
$ids = R::storeAll(R::dispense('page', 2));
$pages = R::loadAll('page', $ids);
asrt(is_array($pages), true);
asrt(count($pages), 2);
asrt($pages[$ids[0]] instanceof RedBean_OODBBean, true);
}
示例9: testPreloadingVariationsAndCache2
/**
* Test variations and cache 2.
*
* @return void
*/
public function testPreloadingVariationsAndCache2()
{
R::$writer->setUseCache(FALSE);
$villages = R::dispense('village', 3);
foreach ($villages as $v) {
$v->ownBuilding = R::dispense('building', 3);
}
foreach ($villages as $v) {
foreach ($v->ownBuilding as $b) {
$b->ownFurniture = R::dispense('furniture', 2);
}
}
$armies = R::dispense('army', 3);
$villages[0]->sharedArmy = array($armies[1], $armies[2]);
$villages[1]->sharedArmy = array($armies[0], $armies[1]);
$villages[2]->sharedArmy = array($armies[2]);
$soldiers = R::dispense('soldier', 4);
$armies[0]->sharedSoldier = array($soldiers[0], $soldiers[1], $soldiers[2]);
$armies[1]->sharedSoldier = array($soldiers[2], $soldiers[1]);
$armies[2]->sharedSoldier = array($soldiers[2]);
$counter = 0;
foreach ($villages as $v) {
$v->name = $counter++;
}
$counter = 0;
foreach ($armies as $a) {
$a->name = $counter++;
}
$counter = 0;
foreach ($soldiers as $s) {
$s->name = $counter++;
}
$buildings = R::dispense('building', 4);
$villages[0]->ownBuilding = array($buildings[0]);
$villages[1]->ownBuilding = array($buildings[1], $buildings[2]);
$villages[2]->ownBuilding = array($buildings[3]);
$counter = 0;
foreach ($buildings as $b) {
$b->name = $counter++;
}
$books = R::dispense('book', 5);
$counter = 0;
foreach ($books as $b) {
$b->name = $counter++;
}
$buildings[0]->ownBook = array($books[0], $books[1]);
$buildings[1]->ownBook = array($books[2]);
$buildings[2]->ownBook = array($books[3], $books[4]);
$world = R::dispense('world');
$world->name = 'w1';
$villages[1]->world = $world;
R::storeAll($villages);
$towns = R::find('village');
$counter = 0;
R::each($towns, array('sharedArmy' => 'army', 'sharedArmy.sharedSoldier' => array('soldier', array(' ORDER BY soldier.name DESC ', array())), 'ownBuilding' => array('building', array(' ORDER BY building.name DESC ', array())), 'ownBuilding.ownBook' => 'book', 'world'), function ($t, $a, $s, $b, $x, $w) use(&$counter) {
if ($counter === 0) {
asrt($w, NULL);
asrt((string) $t->name, '0');
asrt(count($t->sharedArmy), 2);
$list = array();
foreach ($a as $item) {
$list[] = $item->name;
}
sort($list);
asrt(implode(',', $list), '1,2');
$list = array();
foreach ($s as $item) {
$list[] = $item->name;
}
asrt(implode(',', $list), '2,1');
$list = array();
foreach ($b as $item) {
$list[] = $item->name;
}
sort($list);
asrt(implode(',', $list), '0');
$list = array();
foreach ($x as $item) {
$list[] = $item->name;
}
sort($list);
asrt(implode(',', $list), '0,1');
$first = reset($a);
asrt($first->getMeta('type'), 'army');
$first = reset($s);
asrt($first->getMeta('type'), 'soldier');
$first = reset($b);
asrt($first->getMeta('type'), 'building');
$first = reset($x);
asrt($first->getMeta('type'), 'book');
} elseif ($counter === 1) {
asrt($w->name, 'w1');
asrt((string) $t->name, '1');
asrt(count($t->sharedArmy), 2);
$list = array();
//.........这里部分代码省略.........
示例10: testMultiDeleteUpdate
/**
* Test trashAll().
*/
public function testMultiDeleteUpdate()
{
testpack('test multi delete and multi update');
$beans = R::dispenseLabels('bean', array('a', 'b'));
$ids = R::storeAll($beans);
asrt((int) R::count('bean'), 2);
R::trashAll(R::batch('bean', $ids));
asrt((int) R::count('bean'), 0);
testpack('test assocManager check');
$rb = new RedBean_OODB(R::$writer);
try {
$rb->getAssociationManager();
fail();
} catch (RedBean_Exception_Security $e) {
pass();
}
}
示例11: testShadow
/**
* Switching aliases (->alias) should not change other list during
* storage.
*
* @return void
*/
public function testShadow()
{
list($project1, $project2) = R::dispense('project', 2);
list($irene, $ilse) = R::dispense('person', 2);
$project1->developer = $ilse;
$project1->designer = $irene;
$project2->developer = $ilse;
R::storeAll(array($project1, $project2));
$ilse = R::load('person', $ilse->id);
$irene = R::load('person', $irene->id);
asrt(count($ilse->alias('developer')->ownProject), 2);
asrt(count($ilse->alias('designer')->ownProject), 0);
R::store($ilse);
$ilse = R::load('person', $ilse->id);
$irene = R::load('person', $irene->id);
asrt(count($ilse->alias('designer')->ownProject), 0);
asrt(count($ilse->alias('developer')->ownProject), 2);
R::storeAll(array($ilse, $irene));
$ilse = R::load('person', $ilse->id);
$irene = R::load('person', $irene->id);
asrt(count($ilse->alias('designer')->ownProject), 0);
asrt(count($ilse->alias('developer')->ownProject), 2);
asrt(count($irene->alias('designer')->ownProject), 1);
asrt(count($irene->alias('developer')->ownProject), 0);
R::storeAll(array($ilse, $irene));
$ilse = R::load('person', $ilse->id);
$irene = R::load('person', $irene->id);
asrt(count($ilse->alias('designer')->ownProject), 0);
asrt(count($ilse->alias('developer')->ownProject), 2);
asrt(count($irene->alias('designer')->ownProject), 1);
asrt(count($irene->alias('developer')->ownProject), 0);
}
示例12: testAssociationRenaming
/**
* test emulation via association renaming
*
* @return void
*/
public function testAssociationRenaming()
{
list($p1, $p2, $p3) = R::dispense('painting', 3);
list($m1, $m2, $m3) = R::dispense('museum', 3);
$p1->name = 'painting1';
$p2->name = 'painting2';
$p3->name = 'painting3';
$m1->thename = 'a';
$m2->thename = 'b';
$m3->thename = 'c';
R::renameAssociation('museum_painting', 'exhibited');
// Also test array syntax
R::renameAssociation(array('museum_museum' => 'center'));
$m1->link('center', array('name' => 'History Center'))->museum2 = $m2;
$m1->link('exhibited', '{"from":"2014-02-01","til":"2014-07-02"}')->painting = $p3;
$m2->link('exhibited', '{"from":"2014-07-03","til":"2014-10-02"}')->painting = $p3;
$m3->link('exhibited', '{"from":"2014-02-01","til":"2014-07-02"}')->painting = $p1;
$m2->link('exhibited', '{"from":"2014-02-01","til":"2014-07-02"}')->painting = $p2;
R::storeAll(array($m1, $m2, $m3));
list($m1, $m2, $m3) = array_values(R::findAll('museum', ' ORDER BY thename ASC'));
asrt(count($m1->sharedMuseum), 1);
asrt(count($m1->sharedPainting), 1);
asrt(count($m2->sharedPainting), 2);
asrt(count($m3->sharedPainting), 1);
$p3 = reset($m1->sharedPainting);
asrt(count($p3->ownExhibited), 2);
asrt(count($m2->ownExhibited), 2);
R::storeAll(array($m1, $m2, $m3));
list($m1, $m2, $m3) = array_values(R::findAll('museum', ' ORDER BY thename ASC'));
asrt(count($m1->sharedPainting), 1);
asrt(count($m2->sharedPainting), 2);
asrt(count($m3->sharedPainting), 1);
$p3 = reset($m1->sharedPainting);
asrt(count($p3->ownExhibited), 2);
$paintings = $m2->sharedPainting;
foreach ($paintings as $painting) {
if ($painting->name === 'painting2') {
pass();
$paintingX = $painting;
}
}
unset($m2->sharedPainting[$paintingX->id]);
R::store($m2);
$m2 = R::load('museum', $m2->id);
asrt(count($m2->sharedPainting), 1);
$left = reset($m2->sharedPainting);
asrt($left->name, 'painting3');
asrt(count($m2->ownExhibited), 1);
$exhibition = reset($m2->ownExhibited);
asrt($exhibition->from, '2014-07-03');
asrt($exhibition->til, '2014-10-02');
}