public function __invoke(Request $req, Response $res, callable $next) { $res = $next($req, $res); $identity = $this->authService->getIdentity(); if (!$identity) { return $res; } try { $user = R::findOne('user', 'mail = ?', [$identity->mail]); if (!$user) { $user = R::dispense('user'); $user->uid = $identity->uid; $user->mail = $identity->mail; $user->display_name = $identity->displayName; $user->office_name = $identity->officeName; $user->authentication_source = $identity->authenticationSource; $user->password = ''; $user->created = time(); $user->role = 'school'; $this->logger->info(sprintf('User %s imported from sso.sch.gr to database', $identity->mail)); } $user->last_login = time(); $user_id = R::store($user); $identityClass = get_class($identity); $newIdentity = new $identityClass($user_id, $user->uid, $user->mail, $user->display_name, $user->office_name, $user->authentication_source); $this->authService->getStorage()->write($newIdentity); } catch (\Exception $e) { $this->authService->clearIdentity(); $this->flash->addMessage('danger', 'A problem occured storing user in database. <a href="%s" title="SSO logout">SSO Logout</a>'); $this->logger->error('Problem inserting user form CAS in database', $identity->toArray()); $this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]); return $res->withRedirect($this->userErrorRedirectUrl); } return $res; }
public function save() { if (!$this->emptyAttr('id')) { $menu = R::findOne('menu', 'id=?', [$this->getAttr('id')]); } else { $menu = R::dispense('menu'); } $menu->name = $this->getAttr('name'); $oldPicture = null; if (!$this->emptyAttr('picture') && $this->attr['picture']->uploaded) { $picture = $this->getAttr('picture'); $picture->file_new_name_body = $this->generateName("menu_picture_"); // $picture->image_resize = true; $picture->image_convert = 'jpeg'; // $picture->image_x = 964; // $picture->image_y = 1024; // $picture->image_ratio_y = true; $picture->process('upload/'); $oldPicture = $menu->picture; $menu->picture = $picture->file_dst_name; } $success = R::store($menu); if ($success) { if (!is_null($oldPicture)) { @unlink('upload/' . $oldPicture); } } return $success; }
public function crawlUrl() { $currentUrl = ['url' => $this->currentUrl, 'depth' => $this->currentDepth]; do { $this->setCurrentUrl($currentUrl); if (!($doc = parent::crawlUrl())) { continue; } $username = $doc['.vcard-username']->text(); $user = R::findOne('github', ' username = ? ', [$username]); //$user = R::find('github', " username=$username "); if (empty($user)) { $user = R::dispense('github'); $now = time(); $user->avatar = $doc['.vcard-avatar .avatar']->attr('src'); $user->fullname = $doc['.vcard-fullname']->text(); $user->username = $username; $user->email = $doc['.email']->text(); $user->worksFor = $doc['.vcard-detail[itemprop=worksFor]']->text(); $user->homeLocation = $doc['.vcard-detail[itemprop=homeLocation]']->text(); $user->blogUrl = $doc['.vcard-detail[itemprop=url]']->text(); $user->joinDate = $doc['.join-date']->attr('datetime'); $user->url = $this->currentUrl; $user->createdAt = $now; $user->updatedAt = $now; if (R::store($user)) { echo '存储用户', $username, '成功', PHP_EOL; } else { echo '存储用户', $username, '失败', PHP_EOL; } } else { echo '用户', $username, '已经被存储过了', PHP_EOL; } } while ($currentUrl = $this->nextUrl()); }
public function createSchool(array $data) { $school = $this->importSchool(R::dispense('school'), $data); $school->created = time(); R::store($school); return $this->exportSchool($school); }
public function add_view() { $id = $this->slim->request->post()['id']; $item = R::load('ecatalog', $id); $item->view_count += 1; R::store($item); echo '555'; exit; }
/** * @param Set $linkedSet * @returns $this */ public function link(Set $linkedSet) { $bean = $this->getBean(); if ($bean === null) { $bean = $this->newBean(); } $bean->{$this->_('linkedSetId')} = $linkedSet->getBean()->getID(); R::store($bean); return $this; }
public function setOptions($options) { $bean = $this->getBean(); if ($bean === null) { $bean = $this->newBean(); } $bean->{$this->_('options')} = implode(',', $options); R::store($bean); return $this; }
function store() { $email = R::dispense('email'); foreach (\app\run('input', 'keys', 'post') as $key) { $element = str_replace('-', '_', $key); $email->{$element} = \app\run('input', 'post', $key); } R::store($email); return null; }
public function updateAssetForSchool($school_id, array $assetData, $assetId) { $asset = R::findOne('schoolasset', ' id = ? AND school_id = ? ', [$assetId, $school_id]); if (!$asset) { throw new InvalidArgumentException('No school asset found'); } $asset = $this->importSchoolAsset($asset, $assetData, $school_id); R::store($asset); return $this->exportSchoolAsset($asset); }
public function makeUnique() { $items = R::find($this->table, 'ORDER BY sort_order'); // $items = R::exportAll($items); $i = 0; foreach ($items as $key => $item) { $i++; $item->sort_order = $i; R::store($item); } }
public function testGetDetailsCustom() { $details = R::dispense('detail'); $details->desc = 'A test blog.'; $details->image = 'some url'; R::store($details); $response = $this->details->getDetails(new RequestMock(), new ResponseMock(), null); $this->assertEquals('success', $response->status); $this->assertEquals('SMPLog', $response->data[0]['name']); $this->assertEquals('A test blog.', $response->data[0]['desc']); }
public static function storeForm($form) { $data = DataBase::processForm($form); foreach ($data as $table => $value) { try { $saved = parent::store($value); } catch (\Exception $e) { return $e; } } }
private function persist($teacher, array $data) { $teacher->school_id = $data['school_id']; $teacher->name = $data['name']; $teacher->surname = $data['surname']; $teacher->telephone = $data['telephone']; $teacher->email = $data['email']; $teacher->branch_id = $data['branch_id']; $teacher->is_principle = isset($data['is_principle']); $teacher->is_responsible = isset($data['is_responsible']); R::store($teacher); }
public function save() { $account = R::dispense('account'); $account->created_at = date('Y-m-d H:i:s'); $account->email = empty($this->attr['email']) ? null : $this->attr['email']; $account->token = bin2hex(openssl_random_pseudo_bytes(16)); if (R::store($account)) { return $account; } else { return false; } }
public static function checkIn($number) { $bean = R::findOne('record', ' number = :number AND isnull(`in`) ', ['number' => $number]); if ($bean === null) { return null; } $bean->in = time(); $bean->checkInBy = App::user()->id; $record = new Record($number, $bean); R::store($bean); return $record; }
private function persistSoftware($software, array $data) { if (!isset($data['lab_id']) || empty($data['lab_id'])) { $data['lab_id'] = null; } $software->softwarecategory_id = $data['softwarecategory_id']; $software->school_id = $data['school_id']; $software->lab_id = $data['lab_id']; $software->title = $data['title']; $software->vendor = $data['vendor']; $software->url = $data['url']; R::store($software); }
/** * Update a user. * @param Array $data * ['name','fullname','password'] * @return string * @throws \Exception */ public function updateUser($data) { if (empty($data['name'])) { throw new \Exception('need a user name to update'); } $user = R::findOne('user', ' name = ? ', [$data['name']]); if (!empty($user)) { $user->name = $data['name']; $user->fullname = $data['fullname']; if (!empty($data['password'])) { $user->hash = password_hash($data['password'], PASSWORD_DEFAULT); } R::store($user); } }
public function edit(Request $request, Response $response, array $args) { $uid = $args['uid']; if (empty($uid)) { $this->flash->addMessage('flash', 'No record specified'); return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('accounts')); } $id = $this->authenticator->getIdentity(); $user = R::load('users', $id['id']); if ($uid != 'new') { $account = R::load('accounts', $uid); if ($account->id == 0) { $this->flash->addMessage('flash', 'No record found'); return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('accounts')); } // restrict access to own profile or Admin role if ($account->users->id != $id['id']) { if (strtolower($id['role']) != 'admin') { $this->flash->addMessage('flash', 'Access Denied'); return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('accounts')); } } } else { $account = R::dispense('accounts'); } if ($request->isPost()) { $data = $request->getParams(); $account->import($data, 'apikey,accountid,servertype'); $account->users = $user; $account->lasttid = 0; $oandaInfo = FALSE; // verify and get account balance try { $oandaInfo = new Broker_Oanda($account['servertype'], $account['apikey'], $account['accountid'], 0); } catch (\Exception $e) { $viewData['flash'] = 'Account Details Invalid'; } if ($oandaInfo != FALSE) { $aid = R::store($account); $oandaInfo->updateAccount(); $this->flash->addMessage('flash', "account updated"); return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('editaccount', ['uid' => $aid])); } } $viewData['account'] = $account; $this->view->render($response, 'account.twig', $viewData); return $response; }
public function save($employerId) { if (!$this->emptyAttr('id')) { $item = R::findOne('employer_history', 'id=?', [$this->getAttr('id')]); } else { $item = R::dispense('employer_history'); $item->employer_id = $employerId; } $item->term_at = $this->getAttr('term_at', ''); $item->contract_no = $this->getAttr('contract_no', ''); $item->contract_description = $this->getAttr('contract_description', ''); $item->repair_1 = $this->getAttr('repair_1', ''); $item->repair_2 = $this->getAttr('repair_2', ''); $item->repair_3 = $this->getAttr('repair_3', ''); return R::store($item); }
public function testDB() { $app = new Application(); $app->register(new RedBeanServiceProvider(), array('db.options' => array('dsn' => 'sqlite:' . __DIR__ . '/test.sqlite'))); $app['db']; //db init $post = R::dispense('post'); $post->text = 'Hello World'; $id = R::store($post); //Create or Update $fetchedPost = R::load('post', $id); //Retrieve $this->assertSame($post->text, $fetchedPost->text); $this->assertTrue(file_exists(__DIR__ . '/test.sqlite')); unlink(__DIR__ . '/test.sqlite'); }
public function testGetPost() { $request = new RequestMock(); $response = $this->posts->getPost($request, new ResponseMock(), null); $this->assertEquals('failure', $response->status); $this->assertEquals('No post found for slug .', $response->alerts[0]['text']); $post = R::dispense('post'); $post->title = 'test'; $post->slug = 'test'; R::store($post); $request = new RequestMock('test'); $this->posts = new Posts(new ContainerMock()); $response = $this->posts->getPost($request, new ResponseMock(), null); $this->assertEquals('success', $response->status); $this->assertEquals('test', $response->data[0]['title']); }
public function save() { if (!$this->emptyAttr('id')) { $item = R::findOne('room_pattern', 'id=?', [$this->getAttr('id')]); $item->updated_at = date('Y-m-d H:i:s'); } else { $item = R::xdispense('room_pattern'); $item->created_at = date('Y-m-d H:i:s'); $item->updated_at = date('Y-m-d H:i:s'); } $item->room_id = $this->getAttr('room_id'); $item->name = $this->getAttr('name'); $item->width = $this->getAttr('width'); $item->height = $this->getAttr('height'); $item->tileWidth = $this->getAttr('tile_width'); $item->tileHeight = $this->getAttr('tile_height'); $item->tileSizeUnit = $this->getAttr('tile_size_unit'); $item->product_use = ',' . implode(',', $this->getAttr('product_use')) . ','; if (!$this->emptyAttr('picture') && $this->attr['picture']->uploaded) { $picture = $this->getAttr('picture'); $picture->file_new_name_body = $this->generateName("pattern_picture_"); $picture->image_convert = 'jpeg'; $picture->process('upload/'); $this->pushDeleteWhenSuccess('upload/' . $item->picture); $this->pushDeleteWhenFailed('upload/' . $picture->file_dst_name); $item->picture = $picture->file_dst_name; } if (!$this->emptyAttr('thumb') && $this->attr['thumb']->uploaded) { $thumb = $this->getAttr('thumb'); $thumb->file_new_name_body = $this->generateName("pattern_thumb_"); $thumb->image_convert = 'jpeg'; $thumb->image_resize = true; $thumb->image_x = 150; $thumb->image_y = 150; $thumb->process('upload/'); $this->pushDeleteWhenSuccess('upload/' . $item->thumb); $this->pushDeleteWhenFailed('upload/' . $thumb->file_dst_name); $item->thumb = $thumb->file_dst_name; } $success = R::store($item); if ($success) { $this->handlerSuccess(); } else { $this->handlerFailed(); } return $success; }
public function getDetails($request, $response, $args) { $details = R::load('detail', 1); if (!$details->id) { $details->name = 'SMPLog'; $details->description = 'A blog published by SMPLog.'; $details->image = ''; R::store($details); } if (empty($details->name)) { $details->name = 'SMPLog'; R::store($details); } $this->apiJson->setSuccess(); $this->apiJson->addData($details->export()); return $this->jsonResponse($response); }
public function save() { if (!$this->emptyAttr('id')) { $user = R::findOne('user', 'id=?', [$this->getAttr('id')]); } else { $user = R::dispense('user'); $user->level = 2; } $user->username = $this->getAttr('username'); $user->password = $this->getAttr('password'); $user->email = $this->getAttr('email', ''); $user->first_name = $this->getAttr('first_name', ''); $user->last_name = $this->getAttr('last_name', ''); $user->tel_number = $this->getAttr('tel_number', ''); $user->branch = $this->getAttr('branch', ''); return R::store($user); }
public function save() { if (!$this->emptyAttr('id')) { $ecatalog = R::findOne('ecatalog', 'id=?', [$this->getAttr('id')]); $ecatalog->updated_at = date('Y-m-d H:i:s'); } else { $ecatalog = R::dispense('ecatalog'); $ecatalog->created_at = date('Y-m-d H:i:s'); $ecatalog->updated_at = date('Y-m-d H:i:s'); $ecatalog->sort_order = (int) R::getCell("SELECT MAX(sort_order) FROM ecatalog") + 1; } $ecatalog->name = $this->getAttr('name'); $ecatalog->is_new = $this->getAttr('is_new'); if (!$this->emptyAttr('pdf') && is_uploaded_file($this->attr['pdf']['tmp_name'])) { $pdf = $this->getAttr('pdf'); $pdf_path = $this->generateName('ecatalog_pdf_') . '.pdf'; $cover_path = $this->generateName('ecatalog_cover_') . '.jpeg'; $im = new \Imagick($pdf['tmp_name'] . '[0]'); $im->setImageBackgroundColor('white'); // $im = $im->flattenImages(); $im = $im->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN); $im->setImageFormat('jpeg'); if ($im->getImageColorspace() == \Imagick::COLORSPACE_CMYK) { $im->setImageColorspace(\Imagick::COLORSPACE_SRGB); } $im->thumbnailImage(512, 0); $im->writeImage('upload/' . $cover_path); $im->clear(); $im->destroy(); move_uploaded_file($pdf['tmp_name'], 'upload/' . $pdf_path); $this->pushDeleteWhenSuccess('upload/' . $ecatalog->pdf_path); $this->pushDeleteWhenSuccess('upload/' . $ecatalog->cover_path); $this->pushDeleteWhenFailed('upload/' . $pdf_path); $this->pushDeleteWhenFailed('upload/' . $cover_path); $ecatalog->pdf_path = $pdf_path; $ecatalog->cover_path = $cover_path; } $success = R::store($ecatalog); if ($success) { $this->handlerSuccess(); } else { $this->handlerFailed(); } return $success; }
public function save($userId) { if (!$this->emptyAttr('id')) { $item = R::findOne('employee', 'id=?', [$this->getAttr('id')]); } else { $item = R::dispense('employee'); $item->user_id = $userId; } $item->first_name = $this->getAttr('first_name', ''); $item->last_name = $this->getAttr('last_name', ''); $item->tel_number = $this->getAttr('tel_number', ''); $item->passport_id = $this->getAttr('passport_id'); $item->passport_expiry = $this->getAttr('passport_expiry'); $item->visa_expiry = $this->getAttr('visa_expiry'); $item->report_expiry = $this->getAttr('report_expiry'); $item->update_time = date("Y-m-d H:i:s"); return R::store($item); }
public function save() { foreach ($this->_bean->getProperties() as $prop => &$propValue) { if (substr($prop, 0, 3) === 'own') { $propsToUpdate = []; foreach ($propValue as $subValue) { if ($subValue instanceof BaseModel) { $subValue = $subValue->getBean(); $propsToUpdate[] = $subValue; } } $this->__set($prop, $propsToUpdate); } } if ($this->_timestamps) { $this->_bean->{'updated_at'} = Carbon::now(); } R::store($this->_bean); }
public function save() { if (!$this->emptyAttr('id')) { $item = R::findOne('room', 'id=?', [$this->getAttr('id')]); $item->updated_at = date('Y-m-d H:i:s'); } else { $item = R::dispense('room'); $item->created_at = date('Y-m-d H:i:s'); $item->updated_at = date('Y-m-d H:i:s'); } $item->name = $this->getAttr('name'); $success = R::store($item); if ($success) { $this->handlerSuccess(); } else { $this->handlerFailed(); } return $success; }
public function editRota(Request $request, Response $response, array $args) { $id = $this->authenticator->getIdentity(); if (strtolower($id['name']) != 'admin') { $this->flash->addMessage('flash', 'Access Denied'); return $response->withRedirect($this->router->pathFor('homepage')); } $name = $args['name']; if (empty($name)) { $this->flash->addMessage('flash', 'No rota specified'); return $response->withRedirect($this->router->pathFor('rotas')); } if ($name != 'new') { $rota = R::findOrCreate('rotas', ['name' => $name]); } else { $rota = R::dispense('rotas'); } if ($request->isPost()) { $data = $request->getParams(); //$username = $request->getParam('username'); $rota->import($data, 'name,fullname,title,comment'); $rota->sharedUsersList = []; foreach ($data['users'] as $checkUserID) { $rotaUser = R::load('users', $checkUserID); $rota->sharedUsersList[] = $rotaUser; } $id = R::store($rota); try { $fieldtest = R::inspect($rota->name); } catch (\Exception $e) { //thaw for creation R::freeze(['users']); $rotaUser = R::load('users', 1); $rotaDay = R::findOrCreate($rota->name, ['day' => 29, 'month' => 2, 'year' => 2015]); $rotaUser = R::load('users', 1); $rotaDay->name = $rotaUser; $rotaDay->who = $rotaUser; $rotaDay->stamp = date("Y-m-d H:i:s"); R::store($rotaDay); R::freeze(true); } $this->flash->addMessage('flash', "{$rota->name} updated"); return $response->withRedirect($this->router->pathFor('rotas')); } $userList = R::findAll('users'); $data = $rota->export(); $data['userList'] = $userList; $users = []; $userRota = $rota->sharedUsersList; foreach ($userRota as $userCheck) { $users[$userCheck->id] = 'checked'; } $data['userCheck'] = $users; $this->view->render($response, 'rota.twig', $data); return $response; }
public function setCheckedValue($checkedValue) { if ($this->bean === null) { $this->newBean(); } $bean = $this->bean; $bean->{$this->_('checkedValue')} = $checkedValue; R::store($bean); return $this; }