function postRankings($classId, $rankings) { $class = R::load(SHOWCLASS, $classId); if (!$class->id) { return null; } $participations = R::exportAll($class->ownParticipation); if ($participations == null) { return null; } foreach ($rankings as $key => $value) { $riderId = $value->id; $rank = $value->rank; if ($riderId == null || $rank == null) { return null; } $rider = R::load(USER, $riderId); if (!$rider->id) { continue; } foreach ($participations as $participationGetter) { $participation = R::load(PARTICIPATION, $participationGetter[ID]); if ($participation->rider_id == $riderId) { $participation->rank = $rank; R::store($participation); break; } } } return R::store($class); }
function index($f3) { $D = \R::find($this->model_name(), 'ORDER BY displayname ASC'); if ($D) { $f3->set('data', \R::exportAll($D)); } else { $f3->set('data', ''); } show_page($f3, $this->template_name() . '.index'); }
/** * Return all records for a type * @param string $type Database table * @return string JSON All of the records and their contents * @throws API\Exceptions\APIException No records found, 404 */ public static function getList($type) { $beans = R::find($type); $response = R::exportAll($beans); if (sizeof($response) > 0) { return new JSON(array("data" => $response)); } else { throw new APIException("No " . $type . " records found.", 404); } }
function index($f3) { $D = \R::findOne('tools', 'name=?', array($f3->get('PARAMS.name'))); if ($D) { $exportTmp = \R::exportAll($D); $f3->set('data', $exportTmp[0]); } else { $f3->set('data', ''); } show_page($f3, $this->template_name() . '.index'); }
function testbook() { global $app; try { $book = R::findAll('book'); // var_dump($book); echo json_encode(R::exportAll($book)); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); } }
function getIndice($idsubmenu) { //$indices = R::findAll( 'indice', "submenu_id = ?", array($idsubmenu)); //$indices = R::find( 'indice', "submenu_id = ? ORDER BY id DESC", array($idsubmenu)); //$indices = R::find( 'indices', "submenu_id = ?", array($idsubmenu)); //echo $indices; //return $indices->export(); $indices = R::find('indice', ' submenu_id = ? ORDER BY titulo ASC', array($idsubmenu)); //$indices = R::load( 'indice', 1 ); //return $indices->exportAll; return R::exportAll($indices); }
public function get_BasicInfo($ProductId) { try { $product = R::find('product', 'id=?', array($ProductId)); if (!isset($product) || empty($product)) { throw new RecordNotFoundException("Record not found, id:" . $ProductId); } echo ResponseJsonHandler::normalizeJsonResponse(R::exportAll($product)); } catch (Exception $ex) { return ExceptionHandler::Response($ex, $this->_app); } }
function info($f3) { $toolgroups = \R::findAll('toolgroups', 'ORDER BY sort_priority DESC, displayname ASC'); foreach ($toolgroups as $key => $element) { $toolgroups[$key]->with("ORDER BY displayname ASC")->ownTools; } $f3->set('toolgroups', \R::exportAll($toolgroups)); $user = \R::findOne('users', 'username=?', array($this->username)); $f3->set('user', $user); $trainings = \R::find('trainings', 'users_id=?', array($user->id)); $f3->set('trainings', $trainings ? reset($trainings)->build_lookup($trainings) : false); show_page($f3, 'user'); }
function index($f3) { $tools = \R::find('tools'); $D = \R::findAll('toolgroups', 'ORDER BY sort_priority DESC, displayname ASC'); foreach ($D as $key => $element) { $D[$key]->with("ORDER BY displayname ASC")->ownTools; } $f3->set('toolgroups', \R::exportAll($D)); $trainings = \R::find('trainings'); $f3->set('trainings', $trainings ? reset($trainings)->build_lookup($trainings) : false); $users = \R::find('users', 'active=1 ORDER BY usergroup ASC, displayname ASC'); $f3->set('usergroups', $users ? reset($users)->group($users) : $users); show_page($f3, 'trainings.index', true); }
function get($clientid = NULL, $id = NULL) { if ($clientid != NULL) { $client = R::load('client', $clientid); if ($id === NULL) { return $client->with(' ORDER BY pos ASC ')->ownMenu; } else { return $client->ownMenu[$id]; } } else { $menu = R::load("menu", $id); return R::exportAll($menu); } }
function edit_form($f3) { // Get Toolgroup Options $D = \R::findAll('toolgroups', 'ORDER BY sort_priority DESC, displayname ASC'); $f3->set('toolgroups', \R::exportAll($D)); // Get Training Levels $f3->set('training_levels', $f3->exists('data.training_levels') ? json_decode($f3->get('data.training_levels')) : $f3->get('TRAINING_LEVELS')); // Get Location Options $D = \R::findAll('locations', 'ORDER BY displayname ASC'); $f3->set('locations', \R::exportAll($D)); foreach ($f3->get('locations') as $i => $location) { $f3->set('locations.' . $i . '.active', isset($this->D->sharedLocationsList[$locations['id']])); } parent::edit_form($f3); }
/** * Test whether recursion happens */ public function testCopyRecursion() { $document = R::dispense('document'); $id = R::store($document); $document->ownDocument[] = $document; R::store($document); $duplicate = R::dup($document); R::store($duplicate); $duplicate = R::load('document', $id); asrt((int) $document->document_id, $id); asrt((int) $duplicate->document_id, $id); // Export variant $duplicate = R::exportAll($document); asrt((int) $duplicate[0]['document_id'], $id); }
function getbyid($id) { global $app; try { $article = R::findOne('articles', 'id=?', array($id)); if ($article) { echo json_encode(R::exportAll($article)); } else { throw new ResourceNotFoundException(); } } catch (ResourceNotFoundException $e) { $app->response()->status(404); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); } }
public function post() { try { /*$requestBody = $app->request->getBody(); $requestJson = json_decode($requestBody, true);*/ $requestJson = RequestBodyHandler::getJsonBody($this->_app); RequestBodyHandler::verifyJsonBody($requestJson, array("ProductId", "Comment", "ConsumerId")); $obj = R::dispense('productcomment'); $obj->productid = $requestJson->ProductId; $obj->comment = $requestJson->Comment; $obj->consumerid = $requestJson->ConsumerId; $obj->lastmodifiedtime = now(); $id = R::store($obj); $response = R::find('productcomment', 'id=?', array($id)); echo ResponseJsonHandler::normalizeJsonResponse(R::exportAll($response)); //sendSuccess(json_encode(R::exportAll($obj)), 201); } catch (Exception $ex) { return ExceptionHandler::Response($ex, $this->_app); } }
$app->get('/schoolContract', function () use($app) { $sql = "select agent.oname as oname, contract.price as price, school.* from contract" . " join agent on agent.aid = contract.aid join school on school.id = contract.sid"; try { $result = R::getAll($sql); $data = R::convertToBeans('contract', $result); success(R::exportAll($data)); } catch (RedBeanPHP\RedException\SQL $e) { fail($e); } }); $app->get('/student/:id', function ($id) use($app) { $sql = "select school.name as sname, user.* from school join user on user.sid='" . $id . "'"; try { $result = R::getAll($sql); $data = R::convertToBeans('user', $result); success(R::exportAll($data)); } catch (RedBeanPHP\RedException\SQL $e) { fail($e); } }); $app->get('/', function () use($app) { header("Location: intro.php"); die; }); function setUnique($bean, $arr) { $bean->setMeta("buildcommand.unique", array($arr)); } function safeStore($obj) { try {
public function post_ConsumerId_ProducerId($ConsumerId, $ProducerId) { try { $product = R::dispense('consumerfavoriteproducer'); $product->consumerid = $ConsumerId; $product->producerid = $ProducerId; $product->lastmodifiedtime = now(); $id = R::store($product); $response = R::find('consumerfavoriteproducer', 'id=?', array($id)); //$app->response->status(201); //echo json_encode(R::exportAll($response)); echo ResponseJsonHandler::normalizeJsonResponse(R::exportAll($response)); } catch (Exception $ex) { return ExceptionHandler::Response($ex, $this->_app); } }
if (empty($channel) || empty($channel->thumbnail_url)) { if (empty($channel)) { $channel = R::dispense('channel'); } $channel->feed = $feed; $channel->thumbnail_url = getChannelThumbnail($feed); //Store the bean $id = R::store($channel); $channel->data_source = 'http'; } else { $channel->data_source = 'database'; } if ($cacheAvailable) { $memcache->add("chthmb-{$feed}", $channel->thumbnail_url, false, 1800); } jsonForAjax(R::exportAll($channel)); break; case 'youtube_thumbnail': getYoutubeThumbnail($_GET['id'], isset($_GET['base64'])); break; case 'ads': getAds(); break; case 'sponsored_channel': getSponsoredChannel(); break; } function getChannelThumbnail($feed) { $thumbnail_url = null; if (preg_match("/\\/domain\\//u", $feed) > 0) {
public function put_RichInfo($ProducerId) { try { //$paramValue = $this->_app->request->getBody(); //$data = json_decode($paramValue); $requestJson = RequestBodyHandler::getJsonBody($this->_app); RequestBodyHandler::verifyJsonBody($requestJson, array("Description", "CreateTime")); $producer = R::findOne('producer', 'id=?', array($ProducerId)); if (!isset($producer) || empty($producer)) { throw new RecordNotFoundException("Record not found, id:" . $ProducerId); } $producer->description = $requestJson->Description; $producer->createtime = $requestJson->CreateTime; R::store($producer); $response = R::find('producer', 'id=?', array($ProducerId)); //echo json_encode(R::exportAll($response), JSON_UNESCAPED_SLASHES); echo ResponseJsonHandler::normalizeJsonResponse(R::exportAll($response)); } catch (Exception $ex) { return ExceptionHandler::Response($ex, $this->_app); } }
<?php require_once 'setup.php'; require_once 'php_ext/RedBeanPHP4_3/rb.php'; R::setup('mysql:host=' . HOSTNAME . ';dbname=' . SCHEMATA, USERNAME, PASSWORD); if (isset($_GET['device']) && NULL != ($device = substr($_GET['device'], 0, 20))) { $data = R::findOne(TABLE, " name = \"{$device}\""); if (!isset($data)) { $data = R::dispense(TABLE); } $data->name = $device; $data->ip = $_SERVER['REMOTE_ADDR']; $data->date = time(); R::store($data); } else { $ips = R::findAll(TABLE); echo json_encode(R::exportAll($ips), JSON_NUMERIC_CHECK); }
protected function getTwigArray($model) { return \R::exportAll($model->unbox())[0]; }
$response = $response->withHeader('X-Status-Reason', $e->getMessage()); return $this->view->render($response->withStatus(400), 'territory_add.twig'); } $this->flash->addMessage('success', 'Added territory ' . $territory->title); $addBuilding = $this->router->pathFor('territory_buildings_add', ['id' => $id]); return $response->withRedirect($addBuilding); }); // territories/add $this->get('/add', function ($request, $response) { try { $territories = R::findAll('territory'); } catch (Exception $e) { $this->messages->addMessage($e->getMessage()); return $response->withRedirect($request->getUri()); } return $this->view->render($response, 'territory_add.twig', ['territories' => R::exportAll($territories), 'messages' => $this->flash->getMessages()]); })->setName('territory_add'); }); // // territory grouping $app->group('/territories/{id:[0-9]+}', function () { // View one (1) territory // GET /territory/123 $this->get('', function ($request, $response, $args) { $buildings = array(); try { $territory = R::load('territory', $args['id']); foreach ($territory->ownBuildingList as $b) { $building = $b->export(); $building['total_people'] = count($b->ownPersonList); $buildings[] = $building; }
$input = json_decode($body); // query database for single vehiculo $vehiculo = R::findOne('vehiculos', 'id=?', array($id)); // store modified vehiculo // return JSON-encoded response body if ($vehiculo) { $vehiculo->tipo_vehiculos_id = $input->tipo_vehiculos_id; $vehiculo->numero = $input->numero; $vehiculo->economico = (string) $input->economico; $vehiculo->placas = (string) $input->placas; $vehiculo->serie = (string) $input->serie; $vehiculo->activo = 1; $vehiculo->nip = (string) $input->nip; R::store($vehiculo); $app->response()->header('Content-Type', 'application/json'); echo json_encode(R::exportAll($vehiculo)[0]); } else { throw new ResourceNotFoundException(); } } catch (ResourceNotFoundException $e) { $app->response()->status(404); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); } }); // handle DELETE requests to /vehiculos/:id $app->delete('/vehiculos/:id', function ($id) use($app) { try { // query database for vehiculo $request = $app->request();
try { // get and decode JSON request body $request = $app->request(); $body = $request->getBody(); $input = json_decode($body); // query database for single article $subsegmento = R::findOne('subsegmento', 'id=?', array($id)); // store modified article // return JSON-encoded response body if ($subsegmento) { $subsegmento->segmento_id = (string) $input->segmento_id; $subsegmento->nombre = (string) $input->nombre; $subsegmento->descripcion = (string) $input->descripcion; R::store($subsegmento); $app->response()->header('Content-Type', 'application/json'); echo json_encode(R::exportAll($subsegmento)[0]); } else { throw new ResourceNotFoundException(); } } catch (ResourceNotFoundException $e) { $app->response()->status(404); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); } }); // handle DELETE requests to /segmentos/:id $app->delete('/subsegmentos/:id', function ($id) use($app) { try { // query database for cliente $request = $app->request();
function updateClientesById($id) { $app = \Slim\Slim::getInstance(); try { // get and decode JSON request body $request = $app->request(); $body = $request->getBody(); $input = json_decode($body); // query database for single cliente $cliente = R::findOne('clientes', 'id=?', array($id)); // store modified cliente // return JSON-encoded response body if ($cliente) { $cliente->nombre = (string) $input->nombre; $cliente->descripcion = (string) $input->descripcion; $cliente->telefono = (string) $input->telefono; $cliente->activo = (string) $input->activo; R::store($cliente); $app->response()->header('Content-Type', 'application/json'); echo json_encode(R::exportAll($cliente)[0]); } else { throw new ResourceNotFoundException(); } } catch (ResourceNotFoundException $e) { $app->response()->status(404); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); } }
public function exportAll($beans, $parents) { return R::exportAll($beans, $parents); }
//IF 404 - 500 } catch (ResourceNotFoundException $e) { echo "404"; } catch (Exception $e) { echo "400"; } }); /** Génère tous les vins de la BDD selon l'ID donné en paramètre - GET **/ $app->get('/{id}', function (Request $request, Response $response) { try { //Recup - Initializing data $id = $request->getAttribute('id'); //Load method (return an object) $wine = R::load('wine', $id); //ExportAll method (transform the object on an array) $arrays = R::exportAll($wine); //Return data if (!empty($arrays)) { $dataStr = json_encode($arrays, JSON_PRETTY_PRINT); echo $dataStr; } else { echo "unvalid"; } //IF 404 - 500 } catch (ResourceNotFoundException $e) { echo "404"; } catch (Exception $e) { echo "400"; } }); /** Function AddWine - POST **/
//$allPostVars = $app->request->post(); //$allPutVars = $app->request->put(); //var_dump($allGetVars); //var_dump($allPostVars); //var_dump($allPutVars); class ResourceNotFoundException extends Exception { } // handle GET requests for /articles/:id $app->get('/articles/:id', function ($id) use($app) { try { // query database for single article $article = R::findOne('articles', 'id=?', array($id)); if ($article) { // if found, return JSON response $app->response()->header('Content-Type', 'application/json'); echo json_encode(R::exportAll($article)); } else { // else throw exception throw new ResourceNotFoundException(); } } catch (ResourceNotFoundException $e) { // return 404 server error $app->response()->status(404); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); } }); // run $app->run();
<?php $app->get('/todos', 'APIrequest', function () use($app) { $todos = R::findAll('todo'); $app->render(200, ['todos' => R::exportAll($todos)]); }); $app->post('/todos/new', 'APIrequest', function () use($app) { $todo = R::dispense('todo'); $todo->done = false; $todo->text = $app->request()->post('text'); R::store($todo); $app->render(200, ['todo' => $todo->export()]); }); $app->post('/todos/update/:id', 'APIrequest', function ($id) use($app) { $todo = R::findOne('todo', ' id = ?', [$id]); if ($todo) { if ($app->request()->post('text')) { $todo->text = $app->request()->post('text'); } if ($app->request()->post('done')) { $todo->done = $app->request()->post('done') == 'true'; } R::store($todo); $app->render(200, ['todo' => $todo->export()]); } else { $app->render(404, ['error' => 'To-Do not found.']); } }); $app->post('/todos/delete/:id', 'APIrequest', function ($id) use($app) { $todo = R::findOne('todo', ' id = ?', [$id]); if ($todo) {
$user = R::findOne('user', "uid = '{$id}' AND pass = PASSWORD('{$pass}') AND usertype ='10'"); if (isset($user)) { session_register('uid'); $_SESSION['login_user'] = $id; header("location: admin.php"); } else { echo '<script language="javascript">'; echo 'alert("아이디 또는 패스워드가 잘못되었습니다");'; echo 'window.location.href="login.php";'; echo '</script>'; } } else { if ($_POST["option"] == "agent") { R::dispense('agent'); $agent = R::findOne('agent', "aid = '{$id}' AND pass = PASSWORD('{$pass}')"); $agent = R::exportAll($agent); if (isset($agent)) { session_register('aid'); $_SESSION['login_user'] = $id; $_SESSION['agent'] = $agent[0]; header("location: agent.php"); } else { echo '<script language="javascript">'; echo 'alert("아이디 또는 패스워드가 잘못되었습니다");'; echo 'window.location.href="login.php";'; echo '</script>'; } } else { echo '<script language="javascript">'; echo 'alert("사용자 타입을 선택해 주세요");'; echo 'window.location.href="login.php";';
<?php include_once 'phpcode/secureSession.php'; include_once 'phpcode/config.php'; sec_session_start(); check_logged(); ?> <?php if (isset($_GET['id']) && intval($_GET['id']) > 0) { //delete the album $event = R::dispense('events'); $event = R::load('events', $_GET['id']); R::trash($event); $event = R::findAll('events'); file_put_contents('json/events.json', json_encode(R::exportAll($event))); redirect("changeCalander.php"); } else { //go back redirect("changeCalander.php"); }