public function editUser(Request $request, Response $response, array $args) { $username = strtolower($args['username']); if (empty($username)) { $this->flash->addMessage('flash', 'No user specified'); return $response->withRedirect($this->router->pathFor('profile')); } $id = $this->authenticator->getIdentity(); // restrict access to own profile or Admin user if ($username != strtolower($id['name'])) { if (strtolower($id['name']) != 'admin') { $this->flash->addMessage('flash', 'Access Denied'); return $response->withRedirect($this->router->pathFor('profile')); } } if ($username != 'new') { $user = R::findOrCreate('users', ['name' => $username]); } else { $user = R::dispense('users'); } if ($request->isPost()) { $data = $request->getParams(); //$username = $request->getParam('username'); $user->import($data, 'fullname,shortdial,longdial,colour,mobile,home'); $user->name = $request->getParam('username'); $password = $request->getParam('password'); if (!empty($password)) { $pass = password_hash($password, PASSWORD_DEFAULT); $user->hash = $pass; } $id = R::store($user); $this->flash->addMessage('flash', "{$user->name} updated"); return $response->withRedirect($this->router->pathFor('edituser', ['username' => $username])); // $member = 'INSERT INTO `users` (`name`, `fullname`, `password`, `hash`, `colour`, `shortdial`, `longdial`, `mobile`, `home`, `ins_mf`, `ins_win`, `health_mf`, `health_win`, `life_mf`, `life_win`, `wealth_mf`, `wealth_win`, `uk_shift`, `atss`) VALUES ' // . "($username, $fullname, :pass, '', 'FAD2F5', $shortdial, $longdial, '', '', '1', '0', '0', '1', '0', '0', '0', '1', '0', '0'); // "; } $this->view->render($response, 'user.twig', $user->export()); return $response; }
public function editUser(Request $request, Response $response, array $args) { $username = strtolower($args['username']); if (empty($username)) { $this->flash->addMessage('flash', 'No user specified'); return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('profile')); } $id = $this->authenticator->getIdentity(); // restrict access to own profile or Admin user if ($username != strtolower($id['name'])) { if (strtolower($id['name']) != 'admin') { $this->flash->addMessage('flash', 'Access Denied'); return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('profile')); } } if ($username != 'new') { $user = R::findOrCreate('users', ['name' => $username]); } else { $user = R::dispense('users'); } if ($request->isPost()) { $data = $request->getParams(); //$username = $request->getParam('username'); $user->import($data, 'fullname,colour,mobile,home'); $user->name = $request->getParam('username'); $password = $request->getParam('password'); if (!empty($password)) { $pass = password_hash($password, PASSWORD_DEFAULT); $user->hash = $pass; } $id = R::store($user); $this->flash->addMessage('flash', "{$user->name} updated"); return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('edituser', ['username' => $username])); } $this->view->render($response, 'user.twig', $user->export()); return $response; }
/** * find or create new pair * * @param \RedBeanPHP\OODBBean $currencyFrom * @param \RedBeanPHP\OODBBean $currencyTo * * @return \RedBeanPHP\OODBBean */ protected static function getPairFromDb($currencyFrom, $currencyTo) { return RedBean::findOrCreate('pair', ['currency_from_id' => $currencyFrom->id, 'currency_to_id' => $currencyTo->id]); }
public function change(Request $request, Response $response, array $args) { $this->logger->info("Oncall Change page action dispatched"); $rota = strtolower($args['rota']); $display = 6; $name = $request->getParam('name', ''); $prev = $request->getParam('prev', 0); $day = $request->getParam('day'); $month = $request->getParam('month'); $monthObj = \DateTime::createFromFormat('!m', $month); $monthName = $monthObj->format('F'); $year = $request->getParam('year'); $title = "Please select who is oncall for - {$day} {$monthName} {$year}"; if (!empty($name)) { $rotaUser = R::findOne('users', ' name = :username ', ['username' => $name]); if (empty($rotaUser)) { $this->flash->addMessage('flash', "{$name} not found"); return $response->withRedirect($this->router->pathFor('oncall', ['rota' => $rota])); } $oldDay = (int) $day; $oldMonth = (int) $month; $oldYear = (int) $year; $whatDay = 8 - date('w', mktime(0, 0, 0, $oldMonth, $oldDay, $oldYear)); if ($whatDay == 8 || $request->getParam('allweek') == null) { $whatDay = 1; } for ($x = 0; $x < $whatDay; $x++) { $day = date('j', mktime(0, 0, 0, $oldMonth, $oldDay + $x, $oldYear)); $month = date('n', mktime(0, 0, 0, $oldMonth, $oldDay + $x, $oldYear)); $year = date('Y', mktime(0, 0, 0, $oldMonth, $oldDay + $x, $oldYear)); $rotaDay = R::findOrCreate($rota, ['day' => $day, 'month' => $month, 'year' => $year]); $rotaDay->name = $rotaUser; $id = $this->authenticator->getIdentity(); $whoUser = R::load('users', $id['id']); $rotaDay->who = $whoUser; $rotaDay->stamp = date("Y-m-d H:i:s"); R::store($rotaDay); } $this->flash->addMessage('flash', "Rota updated"); return $response->withRedirect($this->router->pathFor('oncall', ['rota' => $rota])); } $rotaBean = R::findOne('rotas', ' name = :name ', [':name' => $rota]); if (empty($rotaBean)) { $this->flash->addMessage('flash', "sorry {$rota} not found"); return $response->withRedirect($this->router->pathFor('homepage')); } $userlist = []; $users = $rotaBean->sharedUsersList; foreach ($users as $user) { $userlist[] = ['colour' => $user['colour'], 'linkday' => '<a href="?name=' . $user['name'] . "&day={$day}&month={$month}&year={$year}\">" . $user['fullname'] . "</a>", 'linkweek' => '<a href="?name=' . $user['name'] . "&day={$day}&month={$month}&year={$year}&allweek=Y\">" . $user['fullname'] . "</a>"]; } $this->view->render($response, 'change.twig', ['rota' => $rota, 'title' => $title, 'userlist' => $userlist]); return $response; }
public function saveToRepo($download, $sha256) { if (!isset($download['package'])) { print_r($download); print_r($sha256); exit; } $package = $download['package']; $data = R::findOrCreate("repo", array("name" => $package['name'], "project" => substr($package['name'], 0, strpos($package['name'], '/')))); $versions = array_values($package['versions']); $version = $versions[0]; $table_package = R::dispense("repo"); $table_package->id = $data->id; $table_package->description = $package['description']; $table_package->type = $package['type']; $table_package->time = strtotime($package['time']); // $table_package->keywords = implode(',',$version['keywords']); $table_package->download_total = $package['downloads']['total']; $table_package->download_monthly = $package['downloads']['monthly']; $table_package->favers = $package['favers']; $table_package->sha256 = $sha256; R::store($table_package); }
public function doDownLoad($limit_array) { $output = new ConsoleOutput(); // $bar = new ProgressBar($output,count($limit_array)); // $bar->start(); // $bar->setBarWidth(100); $i = 0; $count = count($limit_array); // $bar->setFormat('debug'); foreach ($limit_array as $file => $data) { // $package = $this->repository_path."/packages/".$file.".json"; $versions = $this->repository_path . "/download/" . $file . ".json"; // $package = json_decode(file_get_contents($package),true); $download = json_decode(file_get_contents($download), true); if (!$download) { $i++; $output->writeln($i . '/' . $count . ' skip'); continue; // $bar->advance(); } $i++; $versions = array_values($download['package']['versions']); if (!isset($versions[0]['require'])) { $output->writeln($i . '/' . $count . ' skip'); continue; } $output->writeln($i . '/' . $count); $package_name = strtolower($download['package']['name']); $project_name = substr($package_name, 0, strpos($package_name, '/')); // echo strpos($package_name,'/').' '.$package_name."\r\n";exit; if (isset($versions[0]['require'])) { foreach ($versions[0]['require'] as $k => $v) { R::findOrCreate("CpmRequire", array("package" => $package_name, "project" => $project_name, "require" => strtolower($k), "version" => strtolower($v))); } } if (isset($versions[0]['require-dev'])) { foreach ($versions[0]['require-dev'] as $k => $v) { R::findOrCreate("CpmRequireDev", array("package" => $package_name, "project" => $project_name, "require" => strtolower($k), "version" => strtolower($v))); } } if (isset($versions[0]['keywords'])) { foreach ($versions[0]['keywords'] as $v) { R::findOrCreate("CpmKeyword", array("package" => $package_name, "project" => $project_name, "keyword" => strtolower($v))); } } } // $bar->finish(); $output->writeln(''); }
/** * @param string $side 'buy' or 'sell' * @param string $pair Name of Instrument * @param float $price execution price * @param int $expiry UTC timestamp format of order expiry e.g. now()+3600 (for 1 hour) * @param float $stopLoss Price of stopLoss * @param float $takeProfit Price of takeProfit * @param int $risk Risk percent of account 1 = 1% */ public function placeLimitOrder($side, $pair, $price, $expiry, $stopLoss, $takeProfit = NULL, $risk = 1) { //order options? $orderOptions = FALSE; //TODO calculate units based on risk // find how many pips risked //$stopSize = (abs($price-$stopLoss))/$this->oandaWrap->instrument_pip($pair); // $stopSize = abs($this->oandaWrap->calc_pips($pair,$price,$stopLoss)); // find risk amount of account //$size = $this->oandaWrap->nav_size_percent($pair,$risk); //$units = $size / $stopSize; //$units = $this->oandaWrap->nav_size_percent_per_pip($pair,$risk/$stopSize); $data = $this->oandaWrap->account($this->accountId); $accountBalance = $data->balance; $accountCurrency = $data->accountCurrency; $loss = $accountBalance * ($risk / 100); // the quote is 2nd half of pair vs home price // if they are the same, conversion = 1 $split = $this->oandaWrap->instrument_split($pair); if ($split[1] == $accountCurrency) { $quotePrice = 1; } else { // get valid pair string and get price $conPair = $this->oandaWrap->instrument_name($accountCurrency, $split[1]); $quote = $this->oandaWrap->price($conPair); $reverse = strpos($conPair, $accountCurrency) > strpos($conPair, '_') ? FALSE : TRUE; $quotePrice = $reverse ? $quote->ask : 1 / $quote->ask; } $units = round($loss / (abs($price - $stopLoss) * $quotePrice)); /* @var \StdClass Oanda Order Object*/ $order = $this->oandaWrap->order_open($side, $units, $pair, 'marketIfTouched', $price, $expiry, $orderOptions); if (isset($order->code)) { echo $order->message; return $order->message; } // create and save order $currOrder = R::findOrCreate('orders', ['oandaoid' => $order->orderOpened->id, 'instrument' => $order->instrument]); $currOrder->units = $order->orderOpened->units; $currOrder->side = $order->orderOpened->side; //$currOrder->type = $order->type; $currOrder->time = $order->time; $currOrder->expiry = $order->orderOpened->expiry; $currOrder->price = $order->price; if (empty($currOrder->account)) { $account = R::findOne('accounts', ' accountid = ?', [$this->accountId]); if (!empty($account)) { $currOrder->account = $account; } } // apply stop loss $sOrder = $this->oandaWrap->order_set_stop($currOrder['oandaoid'], $stopLoss); $currOrder->stopLoss = $stopLoss; // apply takeprofit if set if (!empty($takeProfit)) { $tOrder = $this->oandaWrap->order_set_tp($currOrder['oandaoid'], $takeProfit); $currOrder->takeProfit = $order->takeProfit; } R::store($currOrder); }
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; }