php RedBeanPHP-R类(方法)实例源码

下面列出了php RedBeanPHP-R 类(方法)源码代码实例,从而了解它的用法。

作者:nui    项目:duragre   
public function delete($id)
 {
     $item = R::findOne('ecatalog', 'id=?', [$id]);
     R::trash($item);
     @unlink('upload/' . $item['pdf_path']);
     @unlink('upload/' . $item['cover_path']);
     $this->slim->redirect($this->slim->request()->getRootUri() . '/ecatalog');
 }

作者:eella    项目:gredu_lab   
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;
 }

作者:nui    项目:duragre   
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;
 }

作者:rx-project    项目:ss   
/**
  * @RequestMapping(url="oauth/getdata",method="POST",type="json")
  * @RequestParams(true)
  */
 public function oauthGetData($model)
 {
     $this::setupDB();
     \Parichya\OAuthServer::init();
     if (\Parichya\OAuthServer::$PHASE_SERVICE_VERIFICATION) {
         \Parichya\Service::verifyService(function ($publicKey, $privateKey, $authToken) {
             //Verify $publicKey, $privateKey, $authToken and if all valid send requested data
             //R::debug( TRUE );
             $authdata = R::findOne('authtoken', ' authtoken = ? AND publickey = ?', array($authToken, $publicKey));
             if (is_null($authdata)) {
                 return array("success" => false);
             } else {
                 $privateKeyData = R::findOne('subscriber', ' subscriber_privatekey = ? AND subscriber_publickey = ?', array($privateKey, $publicKey));
                 if (is_null($privateKeyData)) {
                     return array("success" => false);
                 } else {
                     $user = R::findOne('users', 'id = ? ', array($authdata->user_id));
                     if (is_null($user)) {
                         return false;
                     } else {
                         return array("success" => true, "otp:authToken" => $authToken, "otp:mobileNumber" => $user->phone, "otp:name" => $user->name, "otp:email" => $user->email);
                     }
                 }
             }
         });
     }
     return "login";
 }

作者:CraryPrimitiveMa    项目:php-spide   
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());
 }

作者:neilmillar    项目:fxtrade   
public function test(Request $request, Response $response, array $args)
 {
     $uid = $args['uid'];
     $myaccount = R::load('accounts', $uid);
     $accountId = $myaccount->accountid;
     $account = R::findOne('accounts', ' accountid = ?', [$accountId]);
     if (!empty($account)) {
         $apiKey = $account['apikey'];
         $type = $account['servertype'];
         $oandaInfo = new Broker_Oanda($type, $apiKey, $accountId);
     } else {
         $this->flash->addMessage('flash', "Oanda AccountId not found");
         return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('homepage'));
     }
     $side = 'buy';
     $pair = 'EUR_USD';
     $price = '1.1400';
     $expiry = time() + 60;
     $stopLoss = '1.1300';
     $takeProfit = NULL;
     $risk = 1;
     //        $side='buy';
     //        $pair='GBP_CHF';
     //        $price='2.1443';
     //        $expiry = $oandaInfo->getExpiry(time()+60);
     //        $stopLoss='2.1452';
     //        $takeProfit=NULL;
     //        $risk=1;
     //$oandaInfo->placeLimitOrder($side,$pair,$price,$expiry,$stopLoss,$takeProfit,$risk);
     $oandaInfo->processTransactions();
 }

作者:nui    项目:duragre   
public function delete($roomId, $id)
 {
     $item = R::findOne('room_pattern', 'id=?', [$id]);
     @unlink('upload/' . $item->picture);
     @unlink('upload/' . $item->thumb);
     R::trash($item);
     $this->slim->redirect($this->slim->request()->getRootUri() . '/room/' . $roomId . '/pattern');
 }

作者:kanello    项目:gredu_lab   
public function findSchoolApplicationForm($schoolId)
 {
     $appForm = R::findOne('applicationform', ' school_id = ? ORDER BY id DESC', [$schoolId]);
     if (null === $appForm) {
         return;
     }
     return $this->exportApplicationForm($appForm);
 }

作者:eella    项目:gredu_lab   
public function findSchoolByRegistryNo($registryNo)
 {
     $school = R::findOne('school', ' registry_no = ? ', [$registryNo]);
     if (null === $school) {
         return;
     }
     return $this->exportSchool($school);
 }

作者:Koohiisa    项目:Enpow   
public function setupMySql($host, $name, $user, $password)
 {
     $this->dbHost = $host;
     $this->dbName = $name;
     $this->dbUser = $user;
     $this->dbPassword = $password;
     R::setup('mysql:host=' . $host . ';dbname=' . $name, $user, $password);
     return $this;
 }

作者:txthinkin    项目:bugg   
protected static function select($a)
 {
     self::init();
     if ($a === 'write') {
         if (self::$_writeConnected && self::$_last === 'write') {
             return;
         }
         foreach (self::$_mcs as $i => $c) {
             R::selectDatabase("write:{$i}");
             if (R::testConnection()) {
                 R::freeze(true);
                 self::$_writeConnected = true;
                 self::$_last = 'write';
                 return;
             }
         }
         throw new \Exception('Master DB have down');
     }
     if ($a === 'read') {
         if (self::$_readConnected && self::$_last === 'read') {
             return;
         }
         foreach (self::$_scs as $i => $c) {
             R::selectDatabase("read:{$i}");
             if (R::testConnection()) {
                 R::freeze(true);
                 self::$_readConnected = true;
                 self::$_last = 'read';
                 return;
             }
         }
         throw new \Exception('Slave and master DB have down');
     }
 }

作者:anchetaWer    项目:naughtyfir   
public function notifyAction()
 {
     $id = 1;
     $settings = R::load('settings', $id);
     $time_before = c::now()->modify('+' . $settings->time_before)->toDateString();
     $transport = \Swift_SmtpTransport::newInstance($settings->mail_host, $settings->mail_port)->setUsername($settings->mail_username)->setPassword($settings->mail_password);
     $mailer = \Swift_Mailer::newInstance($transport);
     $client = new \Services_Twilio($settings->twilio_sid, $settings->twilio_token);
     $recepients = R::findAll('recepients');
     $events = R::find("events", "is_enabled = 1 AND date = '{$time_before}'");
     foreach ($events as $event) {
         foreach ($recepients as $recepient) {
             $subject = preg_replace(array('/{title}/', '/{date}/'), array($event->title, $event->date), $settings->subject);
             $end_date = c::parse($event->date)->modify('+' . $event->days . ' days')->toDateString();
             $body_patterns = array('/{name}/', '/{title}/', '/{start_date}/', '/<!(\\w+) ({\\w+})>/');
             $body_replacements = array($settings->name, $event->title, $event->date, "\$1 {$end_date}");
             if ($event->days == 1) {
                 $body_replacements[3] = '';
             }
             $body = preg_replace($body_patterns, $body_replacements, $settings->msg_template);
             if ($recepient->email && $settings->mail_username && $settings->mail_password) {
                 $message = \Swift_Message::newInstance()->setSubject($subject)->setBody($body)->setFrom(array($settings->email => $settings->name))->setTo(array($recepient->email => $recepient->name));
                 try {
                     $response = $mailer->send($message);
                 } catch (\Exception $e) {
                     //todo: log error
                 }
             } else {
                 if ($recepient->phone_number && $settings->twilio_sid && $settings->twilio_token && $settings->twilio_phonenumber) {
                     $message = $client->account->messages->sendMessage($settings->twilio_phonenumber, $recepient->phone_number, $body);
                 }
             }
         }
     }
 }

作者:BIGGAN    项目:TaskBoar   
function addBeans($beans)
 {
     if (null == $beans) {
         return array();
     }
     $this->data = R::exportAll($beans);
 }

作者:skem    项目:skem   
public function getOptions()
 {
     $sets = [];
     foreach (R::findAll('skemaset') as $setBean) {
         $sets[$setBean->getID()] = $setBean->name;
     }
     return $sets;
 }

作者:rx-project    项目:comicas   
public static function DBSetup()
 {
     $config = \Config::getSection("DB1");
     if (!self::$CONNECTED) {
         R::setup('mysql:host=localhost;dbname=' . $config['dbname'], $config['username'], $config['password']);
         self::$CONNECTED = true;
     }
 }

作者:pixeledchim    项目:michin   
/**
  * This function validates the credentials
  * @return bool
  */
 function validate($signin)
 {
     $user = R::findOne('users', 'email = :email AND pass = :pass', [':email' => $signin['email'], ':pass' => md5($signin['pass'])]);
     if (empty($user)) {
         return false;
     }
     $this->getSession()->set('user', $user);
     return true;
 }

作者:draganesc    项目:sibi   
function connect()
{
    $config = \configuration\load();
    if (empty($config['dsn']) || empty($config['user']) || empty($config['password'])) {
        die("Please check the configuration\\database.php file");
    }
    R::addDatabase('db', $config['dsn'], $config['user'], $config['password'], $config['frozen']);
    R::selectDatabase('db');
}

作者:nui    项目:duragre   
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;
 }

作者:nui    项目:duragre   
public function get($id)
 {
     $item = R::findOne('room', 'id=?', [$id]);
     $itemExport = $item->getProperties();
     $this->build($itemExport);
     header('Content-Type: application/json');
     echo json_encode($itemExport, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     exit;
 }

作者:skem    项目:skem   
public function setOptions($options)
 {
     $bean = $this->getBean();
     if ($bean === null) {
         $bean = $this->newBean();
     }
     $bean->{$this->_('options')} = implode(',', $options);
     R::store($bean);
     return $this;
 }


问题


面经


文章

微信
公众号

扫码关注公众号