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); } } } } }
public function index() { $perPage = 10; $page = @$_GET['page'] ? $_GET['page'] : 1; $start = ($page - 1) * $perPage; $items = R::find('user', 'level=2 LIMIT ?,?', [$start, $perPage]); $count = R::count('user'); $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1); $this->slim->render("user/list.php", ['items' => $items, 'page' => $page, 'maxPage' => $maxPage]); }
public function edit($roomId, $id) { $room = R::findOne('room', 'id = ?', [$roomId]); $item = R::findOne('room_pattern', 'id = ?', [$id]); $item = $item->getProperties(); $this->build($item); $products = R::find('product'); $form = new PatternForm($item); $form->error = FlashSession::getInstance()->get("edit_room_pattern_form_error", false); $this->slim->render("room/pattern/add.php", ['products' => $products, 'room' => $room, 'form' => $form]); }
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); } }
/** * @RequestMapping(url="account/chapter/{chapter_id}",type="template",auth=true) * @RequestParams(true) * @Role(USER) * @Role(ADMIN) */ function editChapter($model, $chapter_id = null, $action = null, $title = null) { Service::DBSetup(); $chapter = R::load("chapter", $chapter_id); $comic = R::load("comic", $chapter->comic_id); $pages = R::find("page", "chapter_id = :chapter_id ORDER BY inorder, time asc", array(":chapter_id" => $chapter_id)); $model->assign("pages", $pages); $model->assign("chapter", $chapter); $model->assign("comic", $comic); return "member/chapter"; }
public function index() { $perPage = 10; $page = @$_GET['page'] ? $_GET['page'] : 1; $start = ($page - 1) * $perPage; $items = R::find('news', ' ORDER BY sort_order LIMIT ?,?', [$start, $perPage]); $itemsAll = R::find('news', 'ORDER BY sort_order'); $itemsAll = R::exportAll($items); $count = R::count('news'); $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1); $this->slim->render("news/list.php", ['items' => $items, 'itemsAll' => $itemsAll, 'page' => $page, 'maxPage' => $maxPage]); }
public function index() { $perPage = 10; $page = @$_GET['page'] ? $_GET['page'] : 1; $start = ($page - 1) * $perPage; $items = R::find('room', 'LIMIT ?,?', [$start, $perPage]); $count = R::count('room'); $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1); $itemsExport = R::exportAll($items); $this->builds($itemsExport); $this->slim->render("room/list.php", ['items' => $itemsExport, 'page' => $page, 'maxPage' => $maxPage]); }
public function getPost($request, $response, $args) { $route = $request->getAttribute('route'); $slug = $route->getArgument('slug'); $post = array_shift(R::find('post', ' slug = ? ', [$slug])); if (!$post->id) { $this->apiJson->addAlert('error', 'No post found for slug ' . $slug . '.'); return $this->jsonResponse($response); } $this->apiJson->setSuccess(); $this->apiJson->addData($post->export()); return $this->jsonResponse($response); }
function status() { $sender = \app\run('input', 'post', 'sender'); $recipient = \app\run('input', 'post', 'recipient'); $emails = R::find('email', ' sender = ? or recipient = ? ', [$sender, $recipient]); $result = '<dl>'; foreach ($emails as $email) { $result .= '<dt>' . $email->subject . '</dt>'; $result .= '<dd>' . $email->body_plain . '</dd>'; } $result .= '</dl>'; return $result; }
public function index() { $perPage = 10; $page = @$_GET['page'] ? $_GET['page'] : 1; $start = ($page - 1) * $perPage; $items = R::find('room', 'LIMIT ?,?', [$start, $perPage]); $count = R::count('room'); $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1); $itemsExport = R::exportAll($items); $this->builds($itemsExport); header('Content-Type: application/json'); echo json_encode(['items' => $itemsExport, 'page' => $page, 'maxPage' => $maxPage, 'total' => $count], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; }
public function index() { $perPage = 10; $page = @$_GET['page'] ? $_GET['page'] : 1; $start = ($page - 1) * $perPage; $items = R::find('contactdealer', 'LIMIT ?,?', [$start, $perPage]); $count = R::count('contactdealer'); foreach ($items as &$item) { $item->ownProvince = R::getRow('SELECT * FROM provinces WHERE province_id=?', [$item->province_id]); $item->ownGeography = R::getRow('SELECT * FROM geography WHERE geo_id=?', [$item->geo_id]); // var_dump($item); exit(); } $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1); $this->slim->render("contactdealer/list.php", ['items' => $items, 'page' => $page, 'maxPage' => $maxPage]); }
/** * ManyToOne constructor. * @param string $tableName * @param string $clause * @param array $data * @param callable $nameClosure * @param string $valueField The field name that used to be value. The default field is "id". * @param bool $nullOption */ public function __construct($tableName, $clause = null, $data = [], $nameClosure = null, $valueField = "id", $nullOption = true) { $beans = R::find($tableName, $clause, $data); $options = []; if ($nullOption) { $options[LouisCRUD::NULL] = "--"; } foreach ($beans as $bean) { if ($nameClosure != null) { $options[$bean->{$valueField}] = $nameClosure($bean); } else { $options[$bean->{$valueField}] = $bean->name; } } parent::__construct($options); }
public function updateRss() { $blog = R::load('blog', 1); $posts = R::find('post', ' is_published = 1 ORDER BY publish_date DESC '); $xml = $this->getChannelXml($blog); $count = 1; foreach ($posts as $post) { if ($count == 10) { break; } $xml .= $this->getItemXml($post); $count++; } $xml .= "\n\t</channel>" . "\n</rss>"; try { file_put_contents('../rss/rss.xml', $xml); } catch (Exception $ex) { } }
public function index() { $perPage = 999999; $page = @$_GET['page'] ? $_GET['page'] : 1; $start = ($page - 1) * $perPage; $where = []; $whereParam = []; if (!empty($_GET['room_id'])) { $where[] = "room_id = ?"; $whereParam[] = $_GET['room_id']; } $whereString = implode("AND", $where); $items = R::find('room_pattern', $whereString . ' LIMIT ?,?', array_merge($whereParam, [$start, $perPage])); $count = R::count('room_pattern', $whereString, $whereParam); $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1); $itemsExport = R::exportAll($items); $this->builds($itemsExport); header('Content-Type: application/json'); echo json_encode(['items' => $itemsExport, 'page' => $page, 'maxPage' => $maxPage, 'total' => $count], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; }
public function search() { $page = $this->getAttr("page"); $perPage = $this->getAttr("perPage"); $start = ($page - 1) * $perPage; $query = ""; $bindParam = []; $keyword = $this->getAttr("keyword"); $keyword = trim($keyword); if (!empty($keyword)) { $query .= "first_name LIKE :keyword OR last_name LIKE :keyword"; $bindParam["keyword"] = '%' . $keyword . '%'; } $this->count = R::count('employee', $query, $bindParam); $page = floor($this->count / $perPage); $this->maxPage = $page + ($this->count % $perPage == 0 ? 0 : 1); $query .= " LIMIT :start,:perPage"; $bindParam["start"] = $start; $bindParam["perPage"] = $perPage; $this->items = R::find('employee', $query, $bindParam); $this->injectsUser($this->items); }
public function getOptionStatus() { $items = R::find('employer_status'); return $items; }
public function get($id) { $item = R::findOne('employer', 'id=?', [$id]); $item->histories = R::find('employer_history', 'employer_id=?', [$id]); $this->slim->render("employer/get.php", ["item" => $item]); }
private function createUniqueSlug($string) { $slug = $this->createSlug($string); $check = R::find('post', 'slug LIKE ?', [$slug . '%']); if (count($check)) { $slug = $slug . '-' . (count($check) + 1); } return $slug; }
public static function editableGroups($updatePerms = false, $excludeSuper = false, $pageNumber = 1) { $beans = null; $groups = []; if ($excludeSuper) { $beans = R::find('group', ' is_default_anonymous = 0 and is_default_registered = 0 and is_everyone = 0 and is_super = 0 order by name limit :offset, :count', ['offset' => App::pageOffset($pageNumber), 'count' => App::$pagingSize]); } else { $beans = R::find('group', ' is_default_anonymous = 0 and is_default_registered = 0 and is_everyone = 0 order by name limit :offset, :count', ['offset' => App::pageOffset($pageNumber), 'count' => App::$pagingSize]); } foreach ($beans as $groupBean) { $group = new Group($groupBean->name, $groupBean); $groups[] = $group; if ($updatePerms) { $group->updatePerms(); } } return $groups; }
public function build(&$item) { // $item["created_at"] = strtotime($item["created_at"]); $account_product = R::find('account_product', 'account_id = ?', [$item['id']]); $item["product_count"] = sizeof($account_product); }
/** */ function getResults() { return R::find(USER, "where email !='' "); }
public function getPackagesFromdb() { # R::dispense("repo") ; $retArray = array(); $datas = R::find("repo", ""); foreach ($datas as $data) { $retArray[strtolower($data->name)] = array(); } return $retArray; }
public function getLabTypes() { return array_map(function ($lab) { return $lab->export(); }, R::find('labtype')); }
public function getAllItemCategories($version) { return array_values(array_map([$this, 'exportItemCategory'], R::find('itemcategory', ' groupflag = ' . $version . ' ORDER BY sort ASC ', []))); }
public function search() { $page = $this->getAttr("page"); $perPage = $this->getAttr("perPage"); $start = ($page - 1) * $perPage; $query = ""; $bindParam = []; if (!empty($this->attr['passport_expiry_start']) || !empty($this->attr['passport_expiry_end'])) { $queryPassportExpire = ""; if (!empty($this->attr['passport_expiry_start'])) { $queryPassportExpire .= "passport_expiry >= :passport_expiry_start"; $bindParam['passport_expiry_start'] = $this->attr['passport_expiry_start']; } if (!empty($this->attr['passport_expiry_end'])) { if (!empty($queryPassportExpire)) { $queryPassportExpire .= " AND "; } $queryPassportExpire .= "passport_expiry <= :passport_expiry_end"; $bindParam['passport_expiry_end'] = $this->attr['passport_expiry_end']; } if (!empty($query)) { $query .= " OR "; } $query .= "({$queryPassportExpire})"; } if (!empty($this->attr['visa_expiry_start']) || !empty($this->attr['visa_expiry_end'])) { $queryVisaExpire = ""; if (!empty($this->attr['visa_expiry_start'])) { $queryVisaExpire .= "visa_expiry >= :visa_expiry_start"; $bindParam['visa_expiry_start'] = $this->attr['visa_expiry_start']; } if (!empty($this->attr['visa_expiry_end'])) { if (!empty($queryVisaExpire)) { $queryVisaExpire .= " AND "; } $queryVisaExpire .= "visa_expiry <= :visa_expiry_end"; $bindParam['visa_expiry_end'] = $this->attr['visa_expiry_end']; } if (!empty($query)) { $query .= " OR "; } $query .= "({$queryVisaExpire})"; } if (!empty($this->attr['report_expiry_start']) || !empty($this->attr['report_expiry_end'])) { $queryReportExpire = ""; if (!empty($this->attr['report_expiry_start'])) { $queryReportExpire .= "report_expiry >= :report_expiry_start"; $bindParam['report_expiry_start'] = $this->attr['report_expiry_start']; } if (!empty($this->attr['report_expiry_end'])) { if (!empty($queryReportExpire)) { $queryReportExpire .= " AND "; } $queryReportExpire .= "report_expiry <= :report_expiry_end"; $bindParam['report_expiry_end'] = $this->attr['report_expiry_end']; } if (!empty($query)) { $query .= " OR "; } $query .= "({$queryReportExpire})"; } $this->count = R::count('employee', $query, $bindParam); $page = floor($this->count / $perPage); $this->maxPage = $page + ($this->count % $perPage == 0 ? 0 : 1); $query .= " LIMIT :start,:perPage"; $bindParam["start"] = $start; $bindParam["perPage"] = $perPage; $this->items = R::find('employee', $query, $bindParam); // $this->injectsUser($this->items); }
* Fetch all posts * * @return Json array with all posts */ $router->route('posts-list', '/posts', function () { $result = []; $posts = R::find('post', ' isActive = 1 ORDER BY created DESC'); /* @var $post RedBeanPHP\OODBBean */ foreach ($posts as $post) { $result[] = $post->export(); } return new Json($result); })->route('drafts-list', '/posts/drafts', function () use($auth) { $auth->authenticate(); $result = []; $drafts = R::find('post', ' isActive != 1 ORDER BY created DESC'); /* @var $post RedBeanPHP\OODBBean */ foreach ($drafts as $draft) { $result[] = $draft->export(); } return new Json($result); })->route('post', '/posts/:slug', function ($slug) { // find a post by ID or slug $post = R::findOne('post', ' slug = ? OR id = ?', [$slug, $slug]); if ($post->id) { $next = R::findOne('post', ' id > ? AND isactive = 1 ORDER BY id ASC', [$post->id]); if ($next) { $post->next = $next->slug; } $previous = R::findOne('post', ' id < ? AND isactive = 1 ORDER BY id DESC', [$post->id]); if ($previous) {
public static function find($sql = null, $binding = []) { $model = new static(); $result = R::find($model->_table, $sql, $binding); $collection = new Collection(); for ($i = 0; $i < count($result) - 1; $i++) { $innerModel = new static(); $innerModel->_bean = $result[$i]; $collection->set($i, $innerModel); } return $collection; }
<?php use RedBeanPHP\R; use RedBeanPHP\OODBBean; use app\google\GoogleFile; use app\imgur\Imgur; use models\Images; defined('ROOT_DIR') || define('ROOT_DIR', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR); require_once 'main.php'; configuration(); setAutoloader(); dbconnect(); if (php_sapi_name() != 'cli') { throw new Exception('This application must be run on the command line.'); } $images = R::find(Images::tableName(), ' `imgur` IS NULL '); foreach ($images as $image) { R::begin(); try { $imgur = Imgur::facade(); $imgur->setCatalog(trim($image->type, '12')); $imgur->setFilename(ROOT_DIR . Images::IMAGE_DIRECTORY . DIRECTORY_SEPARATOR . $image->id . '.png'); $imgur->setDescription('R18'); $imgur->setName($image->units->name); $response = $imgur->uploadFile(); if (isset($response['data']['id']) && isset($response['data']['deletehash'])) { $image->imgur = $response['data']['id']; $image->delhash = $response['data']['deletehash']; R::store($image); R::commit(); }
function renumberItems($columnId, $itemPosition, $isRemoved = true) { $items = R::find('item', 'lane_id = ' . $columnId); foreach ($items as $item) { if ($item->position >= $itemPosition) { $item->position += $isRemoved ? -1 : 1; R::store($item); } } }
/** * Insert or Update a bean * * @param OODBBean $bean * @param $data array * @return Result */ private function saveBean($bean, $data) { // Handle File Field that may not in the $data, because Filename always go into $_FILES. foreach ($_FILES as $fieldName => $file) { $data[$fieldName] = $file["name"]; } // Store Showing fields only $fields = $this->getShowFields(); foreach ($fields as $field) { // Check is unique if ($field->isUnique()) { // Try to find duplicate beans $fieldName = $field->getName(); $duplicateBeans = R::find($bean->getMeta('type'), " {$fieldName} = ? ", [$data[$field->getName()]]); if (count($duplicateBeans) > 0) { $validateResult = "Email 已存在!"; } } if ($field->getFieldRelation() == Field::MANY_TO_MANY) { // 1. Many to many // http://www.redbeanphp.com/many_to_many $keyName = "shared" . ucfirst($field->getName()) . "List"; // Clear the current list (tableB_tableA) try { $tableName = $this->getTableName() . "_" . $field->getName(); $idName = $this->getTableName() . "_id"; R::exec("DELETE FROM {$tableName} WHERE {$idName} = ?", [$bean->id]); } catch (\Exception $ex) { } // Clear the current list (tableA_tableB) try { $tableName = $field->getName() . "_" . $this->getTableName(); $idName = $this->getTableName() . "_id"; R::exec("DELETE FROM {$tableName} WHERE {$idName} = ?", [$bean->id]); } catch (\Exception $ex) { } // If User have checked a value in checkbox if (isset($data[$field->getName()])) { $valueList = $data[$field->getName()]; $slots = R::genSlots($valueList); $relatedBeans = R::find($field->getName(), " id IN ({$slots})", $valueList); foreach ($relatedBeans as $relatedBean) { $bean->{$keyName}[] = $relatedBean; } } } else { if ($field->getFieldRelation() == Field::ONE_TO_MANY) { // TODO One to many } else { if (!$field->isStorable()) { // 2. If not storable, skip continue; } elseif ($field->getFieldRelation() == Field::NORMAL) { // 3.Normal data field $value = $field->getStoreValue($data); if ($value == LouisCRUD::NULL) { $value = null; } // Validate the value if ($field->isStorable()) { $validateResult = $field->validate($value, $data); } else { // TODO: check non-storable? $validateResult = true; } // If validate failed, return result object. if ($validateResult !== true) { $result = new Result(); $result->id = @$bean->id; $result->msg = $validateResult; $result->fieldName = $field->getName(); $result->class = "callout-danger"; return $result; } // Set the value to the current bean directly $bean->{$field->getName()} = $value; } } } } // Store // TODO: Return result object $id = R::store($bean); $result = new Result(); $result->id = $id; return $result; }