findAll() public static method

See also: Facade::find The findAll() method differs from the find() method in that it does not assume a WHERE-clause, so this is valid: R::findAll('person',' ORDER BY name DESC '); Your SQL does not have to start with a valid WHERE-clause condition.
public static findAll ( string $type, string $sql = NULL, array $bindings = [] ) : array
$type string the type of bean you are looking for
$sql string SQL query to find the desired bean, starting right after WHERE clause
$bindings array array of values to be bound to parameters in query
return array
Esempio n. 1
0
 public function index(Request $request)
 {
     $beans = R::findAll($model);
     $records = R::exportAll($beans, true);
     $tables = R::getAll('SELECT name FROM sqlite_master WHERE type = "table"');
     return view('umodel.index', ['records' => $records, 'tables' => $tables]);
 }
Esempio n. 2
0
 public function getSettings()
 {
     $settings = array();
     $result = RedBean::findAll('settings');
     foreach ($result as $setting) {
         $settings[$setting->name] = $setting->value;
     }
     return $settings;
 }
 /**
  * @return array
  */
 public function getResults()
 {
     if ($this->storedNumber > $this->maxResults) {
         $startFrom = $this->maxResults * $this->startPage;
         $extraSQL = 'ORDER BY id ASC LIMIT ' . $startFrom . ',' . $this->maxResults;
         return Facade::findAll($this->DBTable, $extraSQL);
     } else {
         return Facade::findAll($this->DBTable);
     }
 }
Esempio n. 4
0
 /**
  * Test for issue #386.
  * Can we use large numbers in LIMIT ?
  * 
  * @return void
  */
 public function testLargeNum()
 {
     $number = R::dispense('number');
     $number->name = 'big number';
     R::store($number);
     //This should not cause an error... (some people use LIMIT 0, HUGE to simulate OFFSET on MYSQL).
     $beans = R::findAll('number', ' LIMIT ? ', array(PHP_INT_MAX));
     asrt(is_array($beans), TRUE);
     asrt(count($beans), 1);
     pass();
 }
    protected function listData()
    {
        $instances = R::findAll($this->model());
        $instanceList = array();
        if (!empty($instances)) {
            foreach ($instances as $instance) {
                $actions = array('data' => '<a title="View" href="' . $this->app->getRouter()->getUrl('admin/admins/edit', array('id' => $instance->id)) . '" data-toggle="dialog"><span class="icon-pencil"></span></a>
					<a title="Delete" href="' . $this->app->getRouter()->getUrl('admin/admins/delete', array('id' => $instance->id)) . '" data-toggle="dialog"><span class="icon-trash"></span></a>', 'class' => 'TAC');
                $instanceList[] = array($instance->email, $instance->name, $instance->status, TimeHelper::date($this->app->config('adminLongDateTimeFormat'), $instance->created_at), $actions);
            }
        }
        return $instanceList;
    }
Esempio n. 6
0
 /**
  * Test for issue #386.
  * Can we use large numbers in LIMIT ?
  * 
  * @return void
  */
 public function testLargeNum()
 {
     if (defined('HHVM_VERSION')) {
         return;
     }
     //oops hhvm has incorrect binding for large nums.
     $number = R::dispense('number');
     $number->name = 'big number';
     R::store($number);
     //This should not cause an error... (some people use LIMIT 0, HUGE to simulate OFFSET on MYSQL).
     $beans = R::findAll('number', ' LIMIT ? ', array(PHP_INT_MAX));
     asrt(is_array($beans), TRUE);
     asrt(count($beans), 1);
     pass();
 }
Esempio n. 7
0
 /**
  * Merge settings to config.
  */
 protected function mergeSettingsToConfig()
 {
     try {
         $dbConfig = $this->getConfigObject()->getProtected('dbConfig');
         if (!empty($dbConfig)) {
             $settings = R::findAll('setting');
             if (!empty($settings)) {
                 foreach ($settings as $setting) {
                     $value = $setting->value;
                     settype($value, $setting->type);
                     if ($setting->is_client) {
                         $this->config->setPublic($setting->name, $value);
                     } else {
                         $this->config->setProtected($setting->name, $value);
                     }
                 }
             }
         }
     } catch (\Exception $e) {
     }
 }
Esempio n. 8
0
 public function testValidatesUniqueness()
 {
     R::freeze(false);
     $foo1 = $this->app->createModel('foo', array('name' => 'a', 'exists_create' => 'b', 'exists_update' => 'c', 'unique' => 'unique', 'unique_create' => 'unique_create', 'unique_update' => 'unique_update'));
     R::store($foo1);
     $this->assertNotEmpty($foo1->getID());
     $rows = R::findAll('foo', "`unique` = ?", array('unique'));
     $this->assertEquals(1, count($rows));
     $foo = $this->app->createModel('foo', array('name' => 'a', 'exists_create' => 'b', 'exists_update' => 'c', 'unique' => 'unique', 'unique_create' => 'unique_create', 'unique_update' => 'unique_update'));
     try {
         R::store($foo);
     } catch (\Exception $e) {
         $this->assertNotEmpty($foo->getErrors('unique'));
         $this->assertNotEmpty($foo->getErrors('unique_create'));
         $this->assertEmpty($foo->getErrors('unique_update'));
     }
     $foo->import(array('unique' => 'unique1', 'unique_create' => 'unique_create1'));
     R::store($foo);
     $this->assertNotEmpty($foo->getID());
     $this->assertEmpty($foo->getErrors('unique'));
     $this->assertEmpty($foo->getErrors('unique_create'));
     $this->assertEmpty($foo->getErrors('unique_update'));
     // Must change an attribute otherwise RedBean does not want to update.
     $foo->set('unique_create', 'unique_create');
     try {
         R::store($foo);
     } catch (\Exception $e) {
         $this->assertEmpty($foo->getErrors('unique'));
         $this->assertEmpty($foo->getErrors('unique_create'));
         $this->assertNotEmpty($foo->getErrors('unique_update'));
     }
     $foo->set('unique_update', 'unique_update1');
     R::store($foo);
     $this->assertEmpty($foo->getErrors('unique'));
     $this->assertEmpty($foo->getErrors('unique_create'));
     $this->assertEmpty($foo->getErrors('unique_update'));
     R::freeze($this->frozen);
 }
 /**
  * Data used in index listing.
  * @return array
  */
 protected function listData()
 {
     $sql = "is_visible = ? ORDER BY position";
     /** @var \RedBean_SimpleModel[] $instanceBeans */
     $instanceBeans = R::findAll('setting', $sql, array(true));
     $instanceRows = array();
     if (!empty($instanceBeans)) {
         $this->app->getTemplateEngine()->loadPlugin('smarty_modifier_truncate', true);
         foreach ($instanceBeans as $instanceBean) {
             /** @var \TestApp\Models\Setting $instance */
             $instance = $instanceBean->box();
             $actions = array('data' => '<a title="View" href="' . $this->app->getRouter()->getUrl('admin/settings/edit', array('id' => $instance->get('id'))) . '" data-toggle="dialog"><span class="icon-pencil"></span></a>', 'class' => 'TAC');
             if ($instance->get('input_type') == 'password') {
                 $value = '********';
             } else {
                 $value = smarty_modifier_truncate($instance->getDisplayValue(), 40, '...', true);
             }
             $instanceRow = array($instance->get('name'), $value, $actions, $instance->get('position'));
             $instanceRows[] = $instanceRow;
         }
     }
     return $instanceRows;
 }
 /**
  * @param int $qid
  *
  * @return void
  */
 public function delete($qid)
 {
     Facade::trash('questions', $qid);
     $answersToDelete = Facade::findAll('answers', 'qid = :qid', [':qid' => $qid]);
     Facade::trashAll($answersToDelete);
 }
Esempio n. 11
0
 /**
  * Test common Facade usage scenarios.
  *
  * @return void
  */
 public function testCommonUsageFacade()
 {
     $toolbox = R::getToolBox();
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $a = new AssociationManager($toolbox);
     asrt(R::getRedBean() instanceof OODB, TRUE);
     asrt(R::getToolBox() instanceof ToolBox, TRUE);
     asrt(R::getDatabaseAdapter() instanceof Adapter, TRUE);
     asrt(R::getWriter() instanceof QueryWriter, TRUE);
     $book = R::dispense("book");
     asrt($book instanceof 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");
     asrt(R::load('book', 999)->title, NULL);
     R::freeze(TRUE);
     try {
         R::load('bookies', 999);
         fail();
     } catch (\Exception $e) {
         pass();
     }
     R::freeze(FALSE);
     $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);
     $book3 = R::dispense("book");
     $book3->title = "third";
     R::store($book3);
     asrt(count(R::find("book")), 3);
     asrt(count(R::findAll("book")), 3);
     asrt(count(R::findAll("book", " LIMIT 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);
     // Find without where clause
     asrt(count(R::findAll('book', ' order by id')), 3);
     R::trash($book3);
     R::trash($book2);
     asrt(count(R::getAll("SELECT * FROM book ")), 1);
     asrt(count(R::getCol("SELECT title FROM book ")), 1);
     asrt((int) R::getCell("SELECT 123 "), 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);
     $author = R::findOne("author", " name = ? ", array("Bobby"));
 }
Esempio n. 12
0
 /**
  * This method won't get called when R::store() called when no change to instance is made.
  */
 public function validates()
 {
     $this->errors = array();
     if (!$this->getID()) {
         $this->validatesOnCreate();
     } else {
         $this->validatesOnUpdate();
     }
     $this->validatesOnSave();
     $mustExists = $this->validatesExistenceOf();
     if (!$this->getID()) {
         $mustExists = array_merge($mustExists, $this->validatesExistenceOnCreateOf());
     } else {
         $mustExists = array_merge($mustExists, $this->validatesExistenceOnUpdateOf());
     }
     if (!empty($mustExists)) {
         foreach ($mustExists as $var) {
             $value = $this->{$var};
             // PHP Gotcha: somehow empty($this->$var) does not work, maybe because $var is a (magic) function.
             if (empty($value)) {
                 $varStr = str_replace('_', ' ', $var);
                 $varStr = preg_replace('/(?!^)[A-Z]{2,}(?=[A-Z][a-z])|[A-Z][a-z]/', ' $0', $varStr);
                 $varStr = ucfirst(strtolower($varStr));
                 $this->addError($this->app->getTranslator()->translate('mustExists', array('varStr' => $varStr)), $var);
             }
         }
     }
     $mustUnique = $this->validatesUniquenessOf();
     if (!$this->getID()) {
         $mustUnique = array_merge($mustUnique, $this->validatesUniquenessOnCreateOf());
     } else {
         $mustUnique = array_merge($mustUnique, $this->validatesUniquenessOnUpdateOf());
     }
     if (!empty($mustUnique)) {
         foreach ($mustUnique as $var) {
             $rows = R::findAll($this->getTableName(), "`{$var}` = ?", array($this->get($var)));
             $count = count($rows);
             $varStr = str_replace('_', ' ', $var);
             $varStr = preg_replace('/(?!^)[A-Z]{2,}(?=[A-Z][a-z])|[A-Z][a-z]/', ' $0', $varStr);
             $varStr = ucfirst(strtolower($varStr));
             if ($count > 0) {
                 $id = $this->getID() ? $this->getID() : 0;
                 foreach ($rows as $row) {
                     if ($row->getID() != $id) {
                         $this->addError($this->app->getTranslator()->translate('mustUnique', array('varStr' => $varStr)), $var);
                         break;
                     }
                 }
             }
         }
     }
     return !$this->hasError();
 }
Esempio n. 13
0
 /**
  * Test Full fluid UUID support.
  *
  */
 public function testFullSupport()
 {
     //Rewire objects to support UUIDs.
     $oldToolBox = R::getToolBox();
     $oldAdapter = $oldToolBox->getDatabaseAdapter();
     $uuidWriter = new \UUIDWriterPostgres($oldAdapter);
     $newRedBean = new OODB($uuidWriter);
     $newToolBox = new ToolBox($newRedBean, $oldAdapter, $uuidWriter);
     R::configureFacadeWithToolbox($newToolBox);
     list($mansion, $rooms, $ghosts, $key) = R::dispenseAll('mansion,room*3,ghost*4,key');
     $mansion->name = 'Haunted Mansion';
     $mansion->xownRoomList = $rooms;
     $rooms[0]->name = 'Green Room';
     $rooms[1]->name = 'Red Room';
     $rooms[2]->name = 'Blue Room';
     $ghosts[0]->name = 'zero';
     $ghosts[1]->name = 'one';
     $ghosts[2]->name = 'two';
     $ghosts[3]->name = 'three';
     $rooms[0]->noLoad()->sharedGhostList = array($ghosts[0], $ghosts[1]);
     $rooms[1]->noLoad()->sharedGhostList = array($ghosts[0], $ghosts[2]);
     $rooms[2]->noLoad()->sharedGhostList = array($ghosts[1], $ghosts[3], $ghosts[2]);
     $rooms[2]->xownKey = array($key);
     //Can we store a bean hierachy with UUIDs?
     R::debug(1);
     $id = R::store($mansion);
     //exit;
     asrt(is_string($id), TRUE);
     asrt(strlen($id), 36);
     $haunted = R::load('mansion', $id);
     asrt($haunted->name, 'Haunted Mansion');
     asrt(is_string($haunted->id), TRUE);
     asrt(strlen($haunted->id), 36);
     asrt(is_array($haunted->xownRoomList), TRUE);
     asrt(count($haunted->ownRoom), 3);
     $rooms = $haunted->xownRoomList;
     //Do some counting...
     $greenRoom = NULL;
     foreach ($rooms as $room) {
         if ($room->name === 'Green Room') {
             $greenRoom = $room;
             break;
         }
     }
     asrt(!is_null($greenRoom), TRUE);
     asrt(is_array($greenRoom->with(' ORDER BY id ')->sharedGhostList), TRUE);
     asrt(count($greenRoom->sharedGhostList), 2);
     $names = array();
     foreach ($greenRoom->sharedGhost as $ghost) {
         $names[] = $ghost->name;
     }
     sort($names);
     $names = implode(',', $names);
     asrt($names, 'one,zero');
     $rooms = $haunted->xownRoomList;
     $blueRoom = NULL;
     foreach ($rooms as $room) {
         if ($room->name === 'Blue Room') {
             $blueRoom = $room;
             break;
         }
     }
     asrt(!is_null($blueRoom), TRUE);
     asrt(is_array($blueRoom->sharedGhostList), TRUE);
     asrt(count($blueRoom->sharedGhostList), 3);
     $names = array();
     foreach ($blueRoom->sharedGhost as $ghost) {
         $names[] = $ghost->name;
     }
     sort($names);
     $names = implode(',', $names);
     asrt($names, 'one,three,two');
     $rooms = $haunted->xownRoomList;
     $redRoom = NULL;
     foreach ($rooms as $room) {
         if ($room->name === 'Red Room') {
             $redRoom = $room;
             break;
         }
     }
     $names = array();
     foreach ($redRoom->sharedGhost as $ghost) {
         $names[] = $ghost->name;
     }
     sort($names);
     $names = implode(',', $names);
     asrt($names, 'two,zero');
     asrt(!is_null($redRoom), TRUE);
     asrt(is_array($redRoom->sharedGhostList), TRUE);
     asrt(count($redRoom->sharedGhostList), 2);
     //Can we repaint a room?
     $redRoom->name = 'Yellow Room';
     $id = R::store($redRoom);
     $yellowRoom = R::load('room', $id);
     asrt($yellowRoom->name, 'Yellow Room');
     asrt(!is_null($yellowRoom), TRUE);
     asrt(is_array($yellowRoom->sharedGhostList), TRUE);
     asrt(count($yellowRoom->sharedGhostList), 2);
     //Can we throw one ghost out?
     array_pop($yellowRoom->sharedGhost);
     R::store($yellowRoom);
     $yellowRoom = $yellowRoom->fresh();
     asrt($yellowRoom->name, 'Yellow Room');
     asrt(!is_null($yellowRoom), TRUE);
     asrt(is_array($yellowRoom->sharedGhostList), TRUE);
     asrt(count($yellowRoom->sharedGhostList), 1);
     //can we remove one of the rooms?
     asrt(R::count('key'), 1);
     $list = $mansion->withCondition(' "name" = ? ', array('Blue Room'))->xownRoomList;
     $room = reset($list);
     unset($mansion->xownRoomList[$room->id]);
     R::store($mansion);
     asrt(R::count('room'), 2);
     //and what about its dependent beans?
     asrt(R::count('key'), 0);
     asrt(R::count('ghost_room'), 3);
     //and can we find ghosts?
     $ghosts = R::find('ghost');
     asrt(count($ghosts), 4);
     $ghosts = R::findAll('ghost', 'ORDER BY id');
     asrt(count($ghosts), 4);
     $ghosts = R::findAll('ghost', 'ORDER BY id LIMIT 2');
     asrt(count($ghosts), 2);
     $ghostZero = R::findOne('ghost', ' "name" = ? ', array('zero'));
     asrt($ghostZero instanceof OODBBean, TRUE);
     //can we create link properties on existing tables?
     $blackRoom = R::dispense('room');
     $blackRoom->name = 'Black Room';
     $ghostZero->link('ghost_room', array('mood' => 'grumpy'))->room = $blackRoom;
     R::store($ghostZero);
     $ghostZero = $ghostZero->fresh();
     $list = $ghostZero->sharedRoomList;
     asrt(count($list), 3);
     $ghostZero = $ghostZero->fresh();
     $list = $ghostZero->withCondition(' ghost_room.mood = ? ', array('grumpy'))->sharedRoomList;
     asrt(count($list), 1);
     //can we load a batch?
     $ids = R::getCol('SELECT id FROM ghost');
     $ghosts = R::batch('ghost', $ids);
     asrt(count($ghosts), 4);
     //can we do an aggregation?
     $ghosts = $greenRoom->aggr('ownGhostRoom', 'ghost', 'ghost');
     asrt(count($ghosts), 2);
     //can we duplicate the mansion?
     asrt(R::count('mansion'), 1);
     asrt(R::count('room'), 3);
     asrt(R::count('ghost'), 4);
     $copy = R::dup($mansion);
     R::store($copy);
     asrt(R::count('mansion'), 2);
     asrt(R::count('room'), 5);
     //black room does not belong to mansion 1
     asrt(R::count('ghost'), 4);
     //can we do some counting using the list?
     asrt($copy->countOwn('room'), 2);
     $rooms = $copy->withCondition(' "name" = ? ', array('Green Room'))->xownRoomList;
     $room = reset($rooms);
     asrt($room->countShared('ghost'), 2);
     //Finally restore old toolbox
     R::configureFacadeWithToolbox($oldToolBox);
 }
function readPackageCost()
{
    $packageCost = R::findAll('packagecost');
    return json_encode(R::exportAll($packageCost));
}
Esempio n. 15
0
 /**
  * Returns an array of all users
  *
  * @param string $orderBy Order By $orderBy ASC
  *
  * @return array
  */
 public static function userList($orderBy = "id")
 {
     $a = [];
     foreach (R::findAll('user', ' ORDER BY ? ASC ', [$orderBy]) as $bean) {
         $a[$bean->id] = [];
         foreach ($bean as $key => $value) {
             $a[$bean->id][$key] = $value;
         }
     }
     return $a;
 }
Esempio n. 16
0
 /**
  * Begin testing.
  * This method runs the actual test pack.
  *
  * @return void
  */
 public function testFinding()
 {
     $toolbox = R::getToolBox();
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $a = new AssociationManager($toolbox);
     $page = $redbean->dispense("page");
     $page->name = "John's page";
     $idpage = $redbean->store($page);
     $page2 = $redbean->dispense("page");
     $page2->name = "John's second page";
     $idpage2 = $redbean->store($page2);
     $a->associate($page, $page2);
     $pageOne = $redbean->dispense("page");
     $pageOne->name = "one";
     $pageMore = $redbean->dispense("page");
     $pageMore->name = "more";
     $pageEvenMore = $redbean->dispense("page");
     $pageEvenMore->name = "evenmore";
     $pageOther = $redbean->dispense("page");
     $pageOther->name = "othermore";
     set1toNAssoc($a, $pageOther, $pageMore);
     set1toNAssoc($a, $pageOne, $pageMore);
     set1toNAssoc($a, $pageOne, $pageEvenMore);
     asrt(count($redbean->find("page", array(), " name LIKE '%more%' ", array())), 3);
     asrt(count($redbean->find("page", array(), " name LIKE :str ", array(":str" => '%more%'))), 3);
     asrt(count($redbean->find("page", array(), array(" name LIKE :str ", array(":str" => '%more%')))), 3);
     asrt(count($redbean->find("page", array(), " name LIKE :str ", array(":str" => '%mxore%'))), 0);
     asrt(count($redbean->find("page", array("id" => array(2, 3)))), 2);
     $bean = $redbean->dispense("wine");
     $bean->name = "bla";
     for ($i = 0; $i < 10; $i++) {
         $redbean->store($bean);
     }
     $redbean->find("wine", array("id" => 5));
     //  Finder:where call OODB::convertToBeans
     $bean2 = $redbean->load("anotherbean", 5);
     asrt($bean2->id, 0);
     $keys = $adapter->getCol("SELECT id FROM page WHERE " . $writer->esc('name') . " LIKE '%John%'");
     asrt(count($keys), 2);
     $pages = $redbean->batch("page", $keys);
     asrt(count($pages), 2);
     $p = R::findLast('page');
     pass();
     $row = R::getRow('select * from page ');
     asrt(is_array($row), TRUE);
     asrt(isset($row['name']), TRUE);
     // Test findAll -- should not throw an exception
     asrt(count(R::findAll('page')) > 0, TRUE);
     asrt(count(R::findAll('page', ' ORDER BY id ')) > 0, TRUE);
     $beans = R::findOrDispense("page");
     asrt(count($beans), 6);
     asrt(is_null(R::findLast('nothing')), TRUE);
     try {
         R::find('bean', ' id > 0 ', 'invalid bindings argument');
         fail();
     } catch (RedException $exception) {
         pass();
     }
 }
Esempio n. 17
0
<?php

//inlcude of Slim Framework and RedBeanPHP
require 'vendor/autoload.php';
/* Declare RedBeanPHP
 * RedBean version : 4.2.1
 */
use RedBeanPHP\Facade as R;
//Declare Slim
$app = new \Slim\Slim();
//Connection at the database by RedBeanPHP
R::setup('mysql:host=localhost;dbname=GoBus_v3.0', 'root', 'pwsio');
//Route
$app->get('/city', function () {
    $city = R::findAll('city');
    echo json_encode(R::exportAll($city));
});
$app->run();
Esempio n. 18
0
 /**
  * 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');
 }
Esempio n. 19
0
 public function index()
 {
     $items = R::findAll('item');
     $tables = R::getAll('SELECT name FROM sqlite_master WHERE type = "table"');
     return view('item.index', ['items' => $items, 'tables' => $tables]);
 }
Esempio n. 20
0
//Declare Slim Framework
$app = new \Slim\Slim(array('templates.path' => 'css/template'));
//Declare RedBeanPHP
use RedBeanPHP\Facade as R;
/*Prepare Connexion
* @TODO edit $connect : $connect=new Connection("host","dbname","user","password");
*/
$connect = new Connection();
//Connection at the database
R::setup('mysql:host=' . $connect->getHost() . ';dbname=' . $connect->getDbname() . '', $connect->getUser(), $connect->getPassword());
//Add the template header
$app->render('head.php');
//Route
$app->get('/', function () use($app) {
    include 'core_mod/people.php';
    $user = R::findAll('user');
});
$app->get('/:mod', function ($mod) use($app) {
    $file = '/__mod/' . $mod . '/index.php';
    if (file_exists($file)) {
        include $file;
        /*
         *	Rank authorisation
         */
    } else {
        $app->redirect('/');
    }
});
$app->run();
//Add the template footer
$app->render('foot.php');
Esempio n. 21
0
<?php

require 'vendor/autoload.php';
use RedBeanPHP\Facade as R;
$app = new \Slim\Slim();
$app->get('/line/:numLine', function ($numLine) {
    R::setup('mysql:host=localhost;  
        dbname=db_goBus', 'root', 'pwsio');
    $row = R::findAll('line', ' where id=' . $numLine);
    //display data line entered into id   'name table', 'condition sup'
    $exportRow = R::exportAll($row);
    echo json_encode($exportRow);
    //js_encode serve to display data all in the inpu line on url
});
$app->run();