/** * Store a new framework config item * @param string $name * @param string $value * * @return void **/ function addfwconfig($name, $value) { $fwc = R::dispense('fwconfig'); $fwc->name = $name; $fwc->value = $value; R::store($fwc); }
function addFollower($userid) { $following = R::dispense('following'); $following->userid = $_SESSION['user_id']; $following->follows = $userid; $id = R::store($following); }
public static function doDeleteById($id) { $user = R::dispense('user'); $user->id = $id; R::trash($user); //for one bean }
public function save() { if ($this->is_validated()) { if ($this->isDublicateUser($this->validated_data['user_name'])) { $this->setError('Duplicate username,Please choose another'); } elseif ($this->isNotStrongPassword($this->validated_data['user_password'])) { $this->setError('Please choose strong password'); } else { $clientreseller = R::dispense("user"); $clientreseller->fullname = $this->validated_data['reseller_user_id']; $clientreseller->linetitle = $this->validated_data['reseller_line_id']; $clientreseller->currencyrate = $this->validated_data['reseller_currency_conversion_rate']; $clientreseller->username = $this->validated_data['reseller_cpanel_user_name']; $clientreseller->password = md5(SALT . $this->validated_data['reseller_cpanel_password']); $clientreseller->resellerlevel = $this->validated_data['reseller_level']; $clientreseller->note = $this->validated_data['reseller_notes']; $clientreseller->type = 4; $clientreseller->createdate = CURRENT_DTT; $clientreseller->updatedate = CURRENT_DTT; $clientreseller->createby = 1001; $clientreseller->isactive = 1; $clientresellerid = R::store($clientreseller); } } if ($this->getError() == "") { $this->fails = FALSE; } else { $this->fails = TRUE; } }
public function create_group($name) { $group = R::dispense('group'); $group->name = $name; R::store($group); return $group; }
/** * creates a user with the $data provided in local DB * * @param array $data [description] * @return [type] [description] */ function create($data = array(), &$errorMessage) { // require password hashing library require_once ROOT . '/lib/passwordHash.php'; $bungieData = file_get_contents('http://www.bungie.net/Platform/User/SearchUsersPaged/' . $data['gamerid'] . '/1/'); $bungie = json_decode($bungieData, true); // provided we get results if ($bungie['Response']['totalResults'] > 0) { // get user from bungie $buser = $bungie['Response']['results'][0]; // create user in ocd $user = R::dispense('users'); // collate data $user['bungie'] = $buser['membershipId']; $user['gamerid'] = $data['gamerid']; $user['platform'] = $data['platform']; $user['email'] = $data['email']; $user['password'] = lib\PasswordHash::create_hash($data['password']); $user['level'] = 100; $user['avatar'] = 'https://www.bungie.net' . $buser['profilePicturePath']; $uid = R::store($user); if ($uid != null) { return true; } } else { $errorMessage = "We couldn't find you in Bungie's Destiny DB - there may be an update to the DB in progress, please try again later!"; } return false; }
/** * Test foreign keys with SQLite. * * @return void */ public function testForeignKeysWithSQLite() { $book = R::dispense('book'); $page = R::dispense('page'); $cover = R::dispense('cover'); list($g1, $g2) = R::dispense('genre', 2); $g1->name = '1'; $g2->name = '2'; $book->ownPage = array($page); $book->cover = $cover; $book->sharedGenre = array($g1, $g2); R::store($book); $fkbook = R::getAll('pragma foreign_key_list(book)'); $fkgenre = R::getAll('pragma foreign_key_list(book_genre)'); $fkpage = R::getAll('pragma foreign_key_list(page)'); asrt($fkpage[0]['from'], 'book_id'); asrt($fkpage[0]['to'], 'id'); asrt($fkpage[0]['table'], 'book'); asrt(count($fkgenre), 2); if ($fkgenre[0]['from'] == 'book') { asrt($fkgenre[0]['to'], 'id'); asrt($fkgenre[0]['table'], 'book'); } if ($fkgenre[0]['from'] == 'genre') { asrt($fkgenre[0]['to'], 'id'); asrt($fkgenre[0]['table'], 'genre'); } asrt($fkbook[0]['from'], 'cover_id'); asrt($fkbook[0]['to'], 'id'); asrt($fkbook[0]['table'], 'cover'); }
public static function create($name) { $item = R::dispense('position'); $item->name = $name; $id = R::store($item); return $id; }
public function userprofile() { $allPostVars = $app->request->post(); $profile = R::dispense('user_profile'); $profile->title = $allPostVars['title']; $profile->firstname = $allPostVars['firstname']; $profile->middlename = $allPostVars['middlename']; $profile->lastname = $allPostVars['lastname']; $profile->dob = $allPostVars['dob']; $profile->numdependents = $allPostVars['numdependents']; $profile->ausdrivlicnum = $allPostVars['ausdrivlicnum']; $profile->email_primary = $allPostVars['email_primary']; $profile->mobile = $allPostVars['mobile']; $profile->home_ph = $allPostVars['home_ph']; $profile->work_ph = $allPostVars['work_ph']; $profile->unit_num = $allPostVars['unit_num']; $profile->street = $allPostVars['street']; $profile->suburb = $allPostVars['suburb']; $profile->postcode = $allPostVars['postcode']; $profile->state = $allPostVars['state']; $profile->gender = $allPostVars['gender']; $datetime = date_create()->format('Y-m-d'); $profile->date_joined = $datetime; //echo ($profile->test()); //print_r($allPostVars); //$profile = R::dispense('tasks'); //$profile->task = $allPostVars['task']; //$profile->user_id = $allPostVars['user_id']; $id = R::store($profile); }
/** * Test SQLite table rebuilding. * * @return void */ public function testRebuilder() { $toolbox = R::$toolbox; $adapter = $toolbox->getDatabaseAdapter(); $writer = $toolbox->getWriter(); $redbean = $toolbox->getRedBean(); $pdo = $adapter->getDatabase(); R::dependencies(array('page' => array('book'))); $book = R::dispense('book'); $page = R::dispense('page'); $book->ownPage[] = $page; $id = R::store($book); $book = R::load('book', $id); asrt(count($book->ownPage), 1); asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1); R::trash($book); asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0); $book = R::dispense('book'); $page = R::dispense('page'); $book->ownPage[] = $page; $id = R::store($book); $book = R::load('book', $id); asrt(count($book->ownPage), 1); asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1); $book->added = 2; R::store($book); $book->added = 'added'; R::store($book); R::trash($book); asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0); }
public function loginUser($username, $password) { //Check if username already exists $user = R::findOne('user', ' username = ? ', [strtolower($username)]); if ($user == NULL) { $error = new ErrorMessage("The username or the password is wrong!"); return json_encode($error); } if (hash('sha512', $password . $user->salt) != $user->password) { $error = new ErrorMessage("The username or the password is wrong!"); return json_encode($error); } //createSession $session_key = $this->random_string(128); $session = R::findOne('session', ' id = ? ', [$user->id]); if ($session == NULL) { $session = R::dispense('session'); $session->token = $session_key; $session->user_id = $user->id; $id = R::store($session); $data = array("token" => $session_key, "public_key" => $user->public_key, "private_key" => $user->private_key); return json_encode($data); } else { $session->token = $session_key; $session->user_id = $user->id; $id = R::store($session); $data = array("token" => $session_key, "public_key" => $user->public_key, "private_key" => $user->private_key); return json_encode($data); } }
public function save() { if ($this->is_validated()) { if ($this->isDublicateUser($this->validated_data['user_name'])) { $this->setError('Duplicate username,Please choose another'); } elseif ($this->isNotStrongPassword($this->validated_data['user_password'])) { $this->setError('Please choose strong password'); } else { print_r($this->validated_data); $message = R::dispense("messageinfo"); echo $this->validated_data['user_full_name']; exit; $message->fullname = $this->validated_data['user_full_name']; $message->username = $this->validated_data['user_name']; $message->password = md5(SALT . $this->validated_data['user_password']); $message->accesslevel = $this->validated_data['user_permission']; $message->currency = $this->validated_data['user_currency']; $message->email = $this->validated_data['user_email']; $message->phone = $this->validated_data['user_mobile']; $message->note = $this->validated_data['user_notes']; $message->createdate = CURRENT_DTT; $message->updatedate = CURRENT_DTT; $message->createby = 1001; $message->isactive = 0; $id = R::store($message); echo $id; } } if ($this->getError() == "") { $this->fails = FALSE; } else { $this->fails = TRUE; } }
/** * Test types. * Test how RedBeanPHP OODB and OODBBean handle type and type casts. * * Rules: * * 1. before storing a bean all types are preserved except booleans (they are converted to STRINGS '0' or '1') * 2. after store-reload all bean property values are STRINGS or NULL * (or ARRAYS but that's only from a user perspective because these are lazy loaded) * 3. the ID returned by store() is an INTEGER (if possible; on 32 bit systems overflowing values will be cast to STRINGS!) * * After loading: * ALL VALUES EXCEPT NULL -> STRING * NULL -> NULL * * @note Why not simply return bean->id in store()? Because not every driver returns the same type: * databases without insert_id support require a separate query or a suffix returning STRINGS, not INTEGERS. * * @note Why not preserve types? I.e. I store integer, why do I get back a string? * Answer: types are handled different across database platforms, would cause overhead to inspect every value for type, * also PHP is a dynamically typed language so types should not matter that much. Another reason: due to the nature * of RB columns in the database might change (INT -> STRING) this would cause return types to change as well which would * cause 'cascading errors', i.e. a column gets widened and suddenly your code would break. * * @note Unfortunately the 32/64-bit issue cannot be tested fully. Return-strategy store() is probably the safest * solution. * * @return void */ public function testTypes() { testpack('Beans can only contain STRING and NULL after reload'); R::nuke(); $bean = R::dispense('bean'); $bean->number = 123; $bean->float = 12.3; $bean->bool = false; $bean->bool2 = true; $bean->text = 'abc'; $bean->null = null; $bean->datetime = new DateTime('NOW', new DateTimeZone('Europe/Amsterdam')); $id = R::store($bean); asrt(is_int($id), TRUE); asrt(is_float($bean->float), TRUE); asrt(is_integer($bean->number), TRUE); asrt(is_string($bean->bool), TRUE); asrt(is_string($bean->bool2), TRUE); asrt(is_string($bean->datetime), TRUE); asrt(is_string($bean->text), TRUE); asrt(is_null($bean->null), TRUE); $bean = R::load('bean', $id); asrt(is_string($bean->id), TRUE); asrt(is_string($bean->float), TRUE); asrt(is_string($bean->number), TRUE); asrt(is_string($bean->bool), TRUE); asrt(is_string($bean->bool2), TRUE); asrt(is_string($bean->datetime), TRUE); asrt(is_string($bean->text), TRUE); asrt(is_null($bean->null), TRUE); asrt($bean->bool, '0'); asrt($bean->bool2, '1'); }
function store_file() { $value = $this->value; //Save the file inside the database $file = R::dispense('file'); $filename = $value[G2_FormMagic::FILE_NAME]; $filename = preg_replace("([^\\w\\s\\d\\-_~,;:\\[\\]\\(\\).])", '', $filename); // Remove any runs of periods (thanks falstro!) $filename = preg_replace("([\\.]{2,})", '', $filename); //Move the file to an upload directory; $directory = "uploads/"; //check if the current file exist. If it does update the name $count = 1; $start_looking = $filename; while (file_exists($directory . $start_looking)) { $start_looking = str_replace('.' . Mvc_Functions::get_extension($filename), '', $filename) . "_{$count}" . '.' . Mvc_Functions::get_extension($filename); $count++; } $filename = $start_looking; $full_uri = $directory . $start_looking; if (!is_dir(dirname($full_uri))) { mkdir(dirname($full_uri), 0777, true); } if (!file_exists($value[G2_FormMagic::FILE_URI])) { return; } move_uploaded_file($value[G2_FormMagic::FILE_URI], $full_uri); //Save the file to database $file->name = $filename; $file->uri = $full_uri; R::store($file); $this->area->file = $file; }
function douban_callback() { OAuthRequester::requestAccessToken(DOUBAN_KEY, $_SESSION['oauth_token'], 0, 'POST', $options = array('oauth_verifier' => $_SESSION['oauth_token'])); $req = new OAuthRequester('http://api.douban.com/people/' . urlencode('@me'), 'get'); $res = $req->doRequest(); $user_data = new SimpleXMLElement($res['body']); $uid = array_pop(explode('/', $user_data->id)); $auth_type = 'douban'; $auth = R::findOne('oauth', "uid=? AND type=?", array($uid, $auth_type)); if (!$auth) { $auth = R::dispense('oauth'); $auth->uid = $uid; $auth->type = $auth_type; $encrypt_key = rand(100000, 999999); $auth->secret = $encrypt_key; } else { $encrypt_key = $auth->secret; } $cookie_str = sha1(implode('', array($uid, $auth_type, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $encrypt_key))); $expire = time() + 3600 * 24 * 365; setcookie('s', $cookie_str, $expire); setcookie('auth_type', $auth_type, $expire); setcookie('uid', $uid, $expire); $auth->setMeta('buildcommand.unique', array(array('uid', 'type'))); $auth->setMeta('buildcommand.indexes', array('uid' => 'uid')); R::store($auth); }
function saveControle($data) { $success = false; R::setup('mysql:host=' . Database::HOST . ';dbname=' . Database::NAME, Database::USERNAME, Database::PASSWORD); $controle = R::dispense('controle'); $controle->date = $data['date']; $controle->traitement = $data['traitement'] == "true" ? 1 : 0; if ($controle->traitement) { $controle->traitement_type = $data['traitement_type']; } $controle->nourrissement = $data['nourrissement'] == "true" ? 1 : 0; if ($controle->nourrissement) { $controle->nourrissement_quantite = $data['nourrissement_quantite']; } $controle->nombre_cadres_couvains = $data['nombre_cadres_couvains']; $controle_id = R::store($controle); $ruche = R::load('ruche', $data['ruche_id']); if ($ruche->id) { $ruche->ownControle[] = $controle; $saved_ruche_id = R::store($ruche); if (isset($controle_id) && isset($saved_ruche_id)) { $success = true; } } return $success; }
public function show_ChatMessage() { $msg = trim($_POST["message"]); if (empty($msg) || strlen($msg) > 255) { $this->error('Die Chat Nachricht darf nicht leer und nicht länger als 255 Zeichen sein!'); } $message = R::dispense('chat_message'); if (preg_match('#^/private "([^"]*)" (.*)$#i', $msg, $m)) { $msg = $m[2]; $usr = R::findOne('user', ' username = ?', array($m[1])); if (!$usr) { $this->error('Der angegebene Benutzer konnte nicht gefunden werden.'); } $targetPos = R::findOne('map_position', ' user_id = ?', array($usr->getID())); if ($targetPos[$usr->getID()]->map != $this->mapPosition->map) { $this->error('Der angegebene Benutzer ist nicht in deiner Nähe! '); } $message->type = 'private'; $message->visible_for = $usr; } else { $message->type = 'public'; } $message->map = $this->mapPosition->map; $message->time = time(); $message->author = $this->user->username; $message->player = $this->user; $message->text = $msg; R::store($message); }
/** * Test Chill mode. * * @return void */ public function testChill() { $bean = R::dispense('bean'); $bean->col1 = '1'; $bean->col2 = '2'; R::store($bean); asrt(count(R::$writer->getColumns('bean')), 3); $bean->col3 = '3'; R::store($bean); asrt(count(R::$writer->getColumns('bean')), 4); R::freeze(array('umbrella')); $bean->col4 = '4'; R::store($bean); asrt(count(R::$writer->getColumns('bean')), 5); R::freeze(array('bean')); $bean->col5 = '5'; try { R::store($bean); fail(); } catch (Exception $e) { pass(); } asrt(count(R::$writer->getColumns('bean')), 5); R::freeze(array()); $bean->col5 = '5'; R::store($bean); asrt(count(R::$writer->getColumns('bean')), 6); }
/** * Test tainted. * * @return void */ public function testTainted() { testpack('Original Tainted Tests'); $redbean = R::$redbean; $spoon = $redbean->dispense("spoon"); asrt($spoon->getMeta("tainted"), TRUE); $spoon->dirty = "yes"; asrt($spoon->getMeta("tainted"), TRUE); testpack('Tainted List test'); $note = R::dispense('note'); $note->text = 'abc'; $note->ownNote[] = R::dispense('note')->setAttr('text', 'def'); $id = R::store($note); $note = R::load('note', $id); asrt($note->isTainted(), FALSE); // Shouldn't affect tainted $note->text; asrt($note->isTainted(), FALSE); $note->ownNote; asrt($note->isTainted(), TRUE); testpack('Tainted Test Old Value'); $text = $note->old('text'); asrt($text, 'abc'); asrt($note->hasChanged('text'), FALSE); $note->text = 'xxx'; asrt($note->hasChanged('text'), TRUE); $text = $note->old('text'); asrt($text, 'abc'); testpack('Tainted Non-exist'); asrt($note->hasChanged('text2'), FALSE); testpack('Misc Tainted Tests'); $bean = R::dispense('bean'); $bean->hasChanged('prop'); $bean->old('prop'); }
private function __probe($filename, $prettify) { // Start time $init = microtime(true); // Default options $options = '-loglevel quiet -show_format -show_streams -print_format json'; if ($prettify) { $options .= ' -pretty'; } // Avoid escapeshellarg() issues with UTF-8 filenames setlocale(LC_CTYPE, 'en_US.UTF-8'); //$command = sprintf('ffprobe %s %s ', $options, escapeshellarg($filename)); $command = sprintf('./ffprobe %s "%s" ', $options, $filename); // Run the ffprobe, save the JSON output then decode $json = json_decode(shell_exec($command), true); //if (!isset($json->format)) if (!isset($json['format'])) { //throw new Exception('Unsupported file type: '.$filename."\r\nCommand:\r\n".$command."\r\n"); $output = 'ffprobe: Unsupported file type: ' . $filename . "\r\nCommand:\r\n" . $command . "\r\n"; $colors = new Colors(); $colors->getColoredString($output, 'black', 'red'); //The command finished with an error. $error = R::dispense('error'); //$video->ownError = array($error); $error->raw_output = $output; $error->repaired = false; $id = R::store($error); } // Save parse time (milliseconds) $this->parse_time = round((microtime(true) - $init) * 1000); return $json; }
/** * @return int|string * @throws \RedBeanPHP\RedException */ function insertUser() { $users = R::dispense('users'); $users->fname = 'Abhishek'; $users->lname = 'Saha'; return R::store($users); }
public function dologinAction() { Db::connect(); $bean = R::dispense('user'); // the redbean model $required = ['Name' => 'name', 'Email' => 'email', 'User_Name' => ['rmnl', 'az_lower'], 'Password' => 'password_hash']; \RedBeanFVM\RedBeanFVM::registerAutoloader(); // for future use $fvm = \RedBeanFVM\RedBeanFVM::getInstance(); $fvm->generate_model($bean, $required); //the magic R::store($bean); $val = new validation(); $val->addSource($_POST)->addRule('email', 'email', true, 1, 255, true)->addRule('password', 'string', true, 10, 150, false); $val->run(); if (count($val->errors)) { Debug::r($val->errors); foreach ($val->errors as $error) { Notification::setMessage($error, Notification::TYPE_ERROR); } $this->redirect(Request::createUrl('login', 'login')); } else { Notification::setMessage("Welcome back !", Notification::TYPE_SUCCESS); Debug::r($val->sanitized); session::set('user', ['sanil']); $this->redirect(Request::createUrl('index', 'index')); } }
public function save() { if ($this->is_validated()) { if ($this->isDublicateBillingUser($this->validated_data['user_name'])) { $this->setError('Duplicate Username, Please choose another'); } elseif ($this->isNotStrongPassword($this->validated_data['user_password'])) { $this->setError('Please choose strong password'); } else { if ($this->validated_data['user_password'] != $this->validated_data['user_confirm_password']) { $this->setError('Confirm password is not matched'); } else { $client = R::dispense("user"); $client->fullname = $this->validated_data['user_full_name']; $client->username = $this->validated_data['user_name']; $client->password = md5(SALT . $this->validated_data['user_password']); $client->duelimit = $this->validated_data['user_credit_limit']; $client->extralimit = $this->validated_data['user_extra_credit']; $client->type = 'client'; $client->email = $this->validated_data['user_email']; $client->mobile = $this->validated_data['user_mobile']; $client->note = $this->validated_data['user_notes']; $client->createdate = CURRENT_DTT; $client->updatedate = CURRENT_DTT; $client->createby = 1001; $client->isactive = 1; $clientid = R::store($client); } } if ($this->getError() == "") { $this->fails = FALSE; } else { $this->fails = TRUE; } } }
function newarticles() { global $app; try { $request = $app->request(); $mediaType = $request->getMediaType(); $body = $request->getBody(); $input = json_decode($body); if ($input) { $article = R::dispense('articles'); $article->title = (string) $input->title; $article->url = (string) $input->url; $article->date = (string) $input->date; $id = R::store($article); $app->response()->header('Content-Type', 'application/json'); 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 save() { GUMP::add_validator("unique", function ($field, $input, $param = NULL) { $checkExistingUser = R::findOne('user', 'user=?', array($input)); if ($checkExistingUser == NULL) { return FALSE; } else { return TRUE; } }); GUMP::add_validator("strong", function ($field, $input, $param = NULL) { return checkPasswordStrength($input); }); $rules = array('reseller_username' => 'required|alpha_numeric|max_len,10|min_len,6|unique', 'reseller_password' => 'required|max_len,10|min_len,7|strong'); $filters = array('reseller_username' => 'trim|sanitize_string', 'reseller_password' => 'trim|sanitize_string|md5'); $app = Slim::getInstance(); $post = $app->request()->post(); // $app - Slim main app instance $postValues = $gump->filter($post, $filters); $validated = $gump->validate($gump->filter($postValues, $filters), $rules); if ($validated === TRUE) { $createUser = R::dispense('user'); $createUser->user = $postValues['reseller_username']; $createUser->user = $postValues['reseller_password']; } else { $this->setError($gump->get_readable_errors(true)); } if ($this->getError() == "") { $this->fails = FALSE; } else { $this->fails = TRUE; } }
public function save() { if ($this->is_validated()) { if ($this->isDublicateVendor($this->validated_data['user_name'])) { $this->setError('Duplicate vendor username, Please choose another'); } elseif ($this->isNotStrongPassword($this->validated_data['user_password'])) { $this->setError('Please choose strong password'); } elseif ($this->validated_data['user_password'] != $this->validated_data['user_confirm_password']) { $this->setError('Password is not matched'); } else { $vendor = R::dispense("user"); $vendor->fullname = $this->validated_data['vendor_title']; $vendor->basecurrency = $this->validated_data['user_currency']; $vendor->username = $this->validated_data['user_name']; $vendor->password = md5(SALT . $this->validated_data['user_password']); $vendor->contactperson = $this->validated_data['vendor_contact_person']; $vendor->mobile = $this->validated_data['user_mobile']; $vendor->email = $this->validated_data['user_email']; $vendor->vendorwebsite = $this->validated_data['vendor_website']; $vendor->note = $this->validated_data['user_notes']; $vendor->type = 2; $vendor->createdate = CURRENT_DTT; $vendor->updatedate = CURRENT_DTT; $vendor->createby = 1001; $vendor->isactive = 1; $id = R::store($vendor); } } if ($this->getError() == "") { $this->fails = FALSE; } else { $this->fails = TRUE; } }
function do_stuff() { /* 26.9|0.0|0.0|31.4|0.00|0.00|0.00|0.00 */ $result = file_get_contents('http://ourproject.dyndns-server.com:8099/&'); echo $result; $rs = explode('|', $result); echo "\n"; $now = new DateTime(); $b = R::dispense('timedate'); $b->time = $now->format('Y-m-d H:i:s'); $b->T1 = $rs[0]; $b->T2 = $rs[1]; $b->T3 = $rs[2]; $b->T4 = $rs[3]; $b->V1 = $rs[4]; $b->V2 = $rs[5]; $b->V3 = $rs[6]; $b->V4 = $rs[7]; R::store($b); echo $b->time; echo "\n"; // MySQL datetime format sleep(10); // wait 20 seconds do_stuff(); // call this function again }
/** get user from session */ protected static function getUser() { $user = R::dispense('user'); $user->import(@$_SESSION['user']); return $user; // $user->id ? $user : null; }
function nav_save() { G2_User::init(); if (G()->logged_in() && !empty($_POST)) { if (!empty($_POST['items']) && !empty($_POST['identity'])) { // Delete all current navigation details $navitems = R::findAll('navitem', 'identity=:id', ['id' => $_POST['identity']]); R::trashAll($navitems); foreach ($_POST['items'] as $new_item) { $nav = R::dispense('navitem'); $nav->identity = $_POST['identity']; $nav->label = $new_item['label']; $nav->href = !$new_item['href'] ? null : $new_item['href']; $nav->order = $new_item['order']; //@todo parent node support R::store($nav); } echo json_encode(['success' => true, 'message' => 'Content Saved Successfully']); } else { echo json_encode(['success' => false, 'message' => 'Data sent not correct']); } } else { echo json_encode(['success' => false, 'message' => 'Not Logged in']); } die; }
/** * 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; }