function likeEvent($like = 1) { global $current_user; $current_user = new CurrentUser(); if (!$current_user->id) { return; } $id = $_POST['id']; if ($like) { $res = MongoDatabase::eventLike($id, $current_user->id); } else { $res = MongoDatabase::eventUnlike($id, $current_user->id); } $this->data['result'] = $res; $event_owner = $res['event_owner']; if ($res && $like && $id && $event_owner != $current_user->id) { // перетаскиваем запись к себе на стену $followerIds = $current_user->getFollowers(); $followerIds[$current_user->id] = $current_user->id; MongoDatabase::pushEvents($current_user->id, $followerIds, $id, time(), $event_owner); } if (!$like && $id && $event_owner != $current_user->id) { // разонравилась. удаляем эту запись с моей стены $followerIds = $current_user->getFollowers(); $followerIds[$current_user->id] = $current_user->id; MongoDatabase::removeWallItem(array_keys($followerIds), $id, $event_owner); } }
function addComment() { global $current_user; if (!$current_user->id) { return; } $comment = isset(Request::$post['comment']) ? Request::$post['comment'] : false; $comment = trim(prepare_review($comment, '')); if (!$comment) { throw new Exception('comment body expected'); } $id = (int) Request::$post['id']; if (!$id) { throw new Exception('target id missed'); } switch (Request::$post['type']) { case 'serie': $type = BiberLog::TargetType_serie; break; case 'author': $type = BiberLog::TargetType_person; break; case 'book': $type = BiberLog::TargetType_book; break; } if ($id) { MongoDatabase::addSimpleComment($type, $id, $current_user->id, $comment); } }
public static function getInstance() { if (!self::$instance) { $s = new Mongo(Config::need('mongohost')); self::$instance = $s->ls2; //self::getInstance()->events->remove(); //self::getInstance()->walls->remove(); } return self::$instance; }
/** * search all booking with datetime, customer name or customer id. * @param string $date * @param string $cusName * @param string $cusID * @return array booking info. */ public function search($from, $to, $cusName, $cusID) { $condition = $this->createConditionToSearch($from, $to, $cusName, $cusID); $data = MongoDatabase::getAllDataFrom("PhieuDatCho", $condition); $result = array(); foreach ($data as $booking) { $booking["NgayLap"] = date('Y-M-d h:i:s', $booking["NgayLap"]->sec); $result[] = $booking; } return $result; }
public static function htmlShowSupplierSelect() { $suppliers = MongoDatabase::getAllDataFrom("NhaCungCap"); $html = '<select id="selectSupplier" onchange="javascript:supplierSelectOnChange(this)">'; $html .= '<option value="-1">' . "Chọn nhà cung cấp" . '</option>'; foreach ($suppliers as $supplier) { $html .= '<option value="' . $supplier["MaNCC"] . '">' . $supplier["TenNCC"] . '</option>'; } $html .= '</select>'; return $html; }
function addComment() { global $current_user; if (!$current_user->id) return; $comment = isset(Request::$post['comment']) ? Request::$post['comment'] : false; $comment = trim(prepare_review($comment, '')); if (!$comment) throw new Exception('comment body expected'); $post_id = Request::$post['id']; if ($post_id) { MongoDatabase::addEventComment($post_id, $current_user->id, $comment); } }
function addComment() { global $current_user; $subscribe = false; if (isset(Request::$post['subscribe'])) { if (Request::$post['subscribe']) { $subscribe = true; } } if (!$current_user->id) { return; } $comment = isset(Request::$post['comment']) ? Request::$post['comment'] : false; $comment = trim(prepare_review($comment, '<em><i><strong><b><u><s>')); if (!$comment) { throw new Exception('comment body expected'); } $post_id = Request::$post['id']; $data = array(); if ($post_id) { if (isset(Request::$post['comment_id']) && ($comment_id = Request::$post['comment_id'])) { $data = MongoDatabase::addEventComment($post_id, $current_user->id, $comment, $comment_id); if ($data) { Notify::notifyEventCommentAnswer($data['commenter_id'], $post_id, $data['comment_id']); } } else { $data = MongoDatabase::addEventComment($post_id, $current_user->id, $comment); if ($data) { Notify::notifyEventComment($data['user_id'], $post_id, $data['comment_id']); } } } if ($data) { if ($subscribe) { // на своё и так и так подписаны if ($data['post']['user_id'] != $current_user->id) { $query = 'SELECT `id` FROM `events` WHERE `mongoid`=' . Database::escape($post_id); $intid = Database::sql2single($query); if ($intid) { /* @var $current_user User */ $current_user->setNotifyRule(UserNotify::UN_COMMENT_ANSWER, UserNotify::UNT_NOTIFY); $current_user->save(); Notify::notifySubscribe($current_user->id, $intid); } } } } }
public static function setStatus($id_user, $id_book, $status, $state) { global $current_user; $book = Books::getInstance()->getByIdLoaded($id_book); /* @var $book Book */ if ($book->getQuality() >= BOOK::BOOK_QUALITY_BEST) { throw new Exception('book quality is best, you cant fix states'); } if (!isset(self::$statuses[$status])) { throw new Exception('no status #' . $status); } if (!isset(self::$states[$state])) { throw new Exception('no status #' . $state); } $can_comment = false; if ($state > 0) { $query = 'SELECT `time` FROM `ocr` WHERE `id_book`=' . $id_book . ' AND `id_user`=' . $id_user . ' AND `status`=' . $status . ' AND `state`=' . $state; $last_time = Database::sql2single($query); if (time() - $last_time > 24 * 60 * 60) { $can_comment = true; } } if ($state == 0 && $status !== 0) { // delete $query = 'DELETE FROM `ocr` WHERE `id_book`=' . $id_book . ' AND `id_user`=' . $id_user . ' AND `status`=' . $status . ''; } else { // upsert $query = 'INSERT INTO `ocr` SET `id_book`=' . $id_book . ', `id_user`=' . $id_user . ', `status`=' . $status . ',`state`=' . $state . ',`time`=' . time() . ' ON DUPLICATE KEY UPDATE `time`=' . time() . ', `state`=' . $state; } if (!Database::query($query, false)) { throw new Exception('Duplicating #book ' . $id_book . ' #status' . $status . ' #state' . $state); } if ($state == 0) { $comment = 'User ' . $current_user->id . ' drop status ' . $status . ' state ' . $state . ' user_id ' . $id_user; } else { $comment = 'User ' . $current_user->id . ' set status ' . $status . ' state ' . $state . ' user_id ' . $id_user; } $comUser = Users::getById($id_user); /* @var $comUser User */ if ($can_comment && ($part = self::getMessagePart($status, $state))) { $comment = mb_strtolower($part, 'UTF-8') . ' книгу'; MongoDatabase::addSimpleComment(BiberLog::TargetType_book, $id_book, $id_user, $comment); } }
public function getFoodAmout($MaCTThucDon_MonAn) { $food = MongoDatabase::getOneDataFrom("ChiTietHoaDon", "MaCTTD_MA=" . $MaCTThucDon_MonAn); return $food["SoLuong"]; }
/** * modify staff info * @param array $data * @return boolean true if success */ public function modify($data) { return MongoDatabase::modifyDataFrom($this::CollectionName, $data, $this::CollectionID, $data[$this::CollectionID]); }
/** * @param string $bill_food_id bill food id */ private function getMenuFoodsByBill_Food_ID($bill_food_id) { $condition = array('MaChiTiet' => $bill_food_id); $keys = array('_id' => 0); $foods = MongoDatabase::getAllDataFrom("ChiTietThucDon_MonAn", $condition, $keys); return $foods == null ? null : $foods[0]; }
public function push($walls_disabled = array()) { global $current_user; if (!$this->canPushed) { return; } $eventId = false; // ревью обновляем if ($this->data['type'] == self::EVENT_BOOKS_REVIEW_ADD || $this->data['type'] == self::EVENT_BOOKS_RATE_ADD) { // ищем старую $eventId = MongoDatabase::findReviewEvent($current_user->id, $this->data['bid']); if ($eventId) { // есть старая? нужно удалить запись на стене со ссылкой на старую запись со всех стен MongoDatabase::deleteWallItemsByEventId($eventId); MongoDatabase::updateEvent($eventId, $this->data); } } // а если был такой эвент недавно, с тем же типом // то обновляем эфент, добавляя туда объекты if (in_array($this->data['type'], self::$eventsMultTypes)) { // находим эвент с таким типом $additionalCriteria = array(); if ($this->data['type'] == self::EVENT_BOOKS_ADD_SHELF) { $additionalCriteria['shelf_id'] = $this->data['shelf_id']; } list($eventId, $data) = MongoDatabase::findLastEventByType($this->data['user_id'], $this->data['type'], $additionalCriteria); if ($eventId) { // нашли эвент! $old_time = isset($data['time']) ? $data['time'] : time(); foreach ($this->data as $field => $value) { if (!isset($data[$field])) { $data[$field] = $value; } if (is_array($value)) { foreach ($value as $val) { if (is_array($data[$field])) { $data[$field][$val] = $val; } } } } $data['time'] = $old_time; MongoDatabase::deleteWallItemsByEventId($eventId); MongoDatabase::updateEvent($eventId, $data); } } $eventDbId = 0; if (!$eventId) { $eventId = MongoDatabase::addEvent($this->data); $query = 'INSERT INTO `events` SET `mongoid`=' . Database::escape($eventId); Database::query($query, false); $eventDbId = Database::lastInsertId(); if (!$eventDbId) { throw new Exception('cant push event id to database'); } } if ($eventId) { $user = Users::getById($this->data['user_id']); /* @var $user User */ $followerIds = $user->getFollowers(); $followerIds[$user->id] = $user->id; foreach ($walls_disabled as $id) { if (isset($followerIds[$id])) { unset($followerIds[$id]); } } MongoDatabase::pushEvents($this->data['user_id'], $followerIds, $eventId, $this->data['time']); } return $eventDbId; }
function getBookContributionComments() { global $current_user; /* @var $current_user CurrentUser */ $id_book = isset($this->params['book_id']) ? (int) $this->params['book_id'] : false; if (!$id_book) { return; } $book = Books::getInstance()->getByIdLoaded($id_book); /* @var $book Book */ if (!$book->exists) { throw new Exception('book #' . $book->id . ' not exists'); } $cond = new Conditions(); $per_page = 0; if (isset($this->params['per_page'])) { $per_page = (int) $this->params['per_page']; } $per_page = $per_page > 0 ? $per_page : 20; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; $cond->setPaging(1000, $per_page, $pagingName); $limit = $cond->getMongoLimit(); list($comments, $count) = MongoDatabase::getBookComments($id_book, $per_page, $limit); $uids = array(); $comments['comments'] = isset($comments['comments']) ? $comments['comments'] : array(); foreach ($comments['comments'] as &$comment) { $comment['commenter_id'] = $comment['user_id']; $comment['type'] = 'book'; $comment['time'] = date('Y/m/d H:i:s', $comment['time']); $uids[$comment['user_id']] = $comment['user_id']; } $cond = new Conditions(); $cond->setPaging($count, $per_page, $pagingName); $this->data['conditions'] = $cond->getConditions(); $this->data['comments'] = isset($comments['comments']) ? $comments['comments'] : array(); $this->data['comments']['title'] = 'Обсуждение книги «' . $book->getTitle(true) . '»'; $this->data['comments']['count'] = $count; $this->data['users'] = $this->getCommentsUsers($uids); }
function getReviews() { $res = MongoDatabase::findReviewEvents($this->target_id); $this->data = $this->_list($res, $uids = array()); $this->data['reviews']['target_id'] = $this->target_id; $this->data['reviews']['target_type'] = $this->target_type; }
/** * get all ingredient info * @param null * @return ingredient array include "MaNL, TenNL, TenLoaiNL, SoLuong, SoLuongToiThieu, SoLuongToiDa" * @author hathao298@gmail.com */ public function getAllIngredient() { return MongoDatabase::getAllDataFrom("NguyenLieu"); }
/** * get all restaurant in system. * @return array */ public function getAllRestaurant() { return MongoDatabase::getAllDataFrom($this::CollectionName); }
function save() { // дополнительные поля if (count($this->changedAdditional) && $this->id) { MongoDatabase::setUserAttributes($this->id, $this->changedAdditional); } // основные поля if (count($this->changed) && $this->id) { $this->changed['lastSave'] = time(); foreach ($this->changed as $f => $v) { $sqlparts[] = '`' . $f . '`=\'' . mysql_escape_string($v) . '\''; } $sqlparts = implode(',', $sqlparts); $query = 'INSERT INTO `users` SET `id`=' . $this->id . ',' . $sqlparts . ' ON DUPLICATE KEY UPDATE ' . $sqlparts; Database::query($query); } Users::dropCache($this->id); }
/** * save bill detail * @param array $data * @return boolean */ public function saveBillDetail($data) { return MongoDatabase::addDataTo("ChiTietHoaDon", $data); }
function getUserEvents($all = false) { $cond = new Conditions(); $per_page = 0; if (isset($this->params['per_page'])) { $per_page = (int) $this->params['per_page']; } $per_page = $per_page > 0 ? $per_page : self::PER_PAGE; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; $cond->setPaging(self::MAX_EVENTS_ON_WALL, $per_page, $pagingName); $limit = $cond->getMongoLimit(); // показываем просто последнюю активность $events = MongoDatabase::findReviewEvents(false, $this->user_id, $per_page, $limit); $this->_list($events); }
public function modifyStaff(StaffDTO $info) { MongoDatabase::modifyDataFrom("nhanvien", $info->convert_to_array(), "MaNV", $info->_maNV); }
/** * Connect to the Mongo database. */ function connect() { /* Parse config->mongo for connection params. example yml: mongo: [{database}:] user: {username} pass: {password} [database: {database}] [host: {host}] [debug: {true|false|1|2}] [log: {true|false}] ... */ if (!self::$db_params) { self::$db_params = array(); $default_params = array(); foreach ((array) Request::$config->mongo as $key => $value) { if (is_array($value) && $value['user'] && $value['pass'] && $value['database']) { self::$db_params[$key] = $value; } else { $default_params[$key] = $value; } } if (!empty($default_params)) { self::$db_params['default'] = $default_params; } } // Select connection params by 'database' key. $this->params = array_merge((array) $this->params, (array) ($this->database ? self::$db_params[$this->database] : self::$db_params['default'])); // Remember chosen database. $this->database = $this->params['database']; // Re-usable database handle. $this->dbh =& self::$mongo[$this->database]; // Need to setup mongo instance? if ($this->dbh instanceof MongoDB == false) { // Default params. $host = $this->params['host'] ?: 'localhost'; $port = $this->params['port'] ?: 27017; $options = $this->params['options'] ?: array(); // Default database name. $this->database = $this->database ?: 'default'; // Username and password? if ($this->params['user'] && $this->params['pass']) { $userpass = "******"; // Hide password. unset($this->params['pass']); } // Connect to Mongo. $mongo_class = class_exists('MongoClient') ? 'MongoClient' : 'Mongo'; $mongo = new $mongo_class("mongodb://{$userpass}{$host}:{$port}/{$this->database}", $options); // Get the database handle. $this->dbh = $mongo->selectDB($this->database); } // Shortcut to the mongo collection. $this->dbc = $this->dbh->{$this->collection}; // Ensure indexes. $this->ensure_indexes($this->indexes); }
/** * я удалил из друзей * @param type $id_deleted_friend */ public function onDeleteFriend($id_deleted_friend) { // и удаляю все записи этого друга у себя со стены MongoDatabase::deleteWallItemsByOwnerId($this->id, $id_deleted_friend); }
public function saveIngredientImportingInfo($data) { return MongoDatabase::addDataTo("PhieuNhapHang", $data); }
/** * get all ingredientType * @param null * @return ingredientType array * @author hathao298@gmail.com */ public function getAllIngredientType() { $key = array("_id" => 0, "MaLoaiNL" => 1, "TenLoaiNL" => 1); return MongoDatabase::getAllDataFrom("LoaiNguyenLieu", null, $key); }
/** * get supplier info by contract detail id * @param unknown_type $conDetailID * @return Ambigous <$arr, NULL, multitype:unknown > */ public function getSupplierByContractDetailID($conDetailID) { $contractDetail = MongoDatabase::getOneDataFrom("ChiTietHopDong", "MaCTHD=" . $conDetailID); $contract = MongoDatabase::getOneDataFrom("HopDong", "MaHopDong=" . $contractDetail["MaHopDong"]); return MongoDatabase::getOneDataFrom("NhaCungCap", "MaNCC=" . $contract["MaNCC"]); }
function getEvents($all = false) { if (!$all) { if (isset($this->params['select']) && $this->params['select'] == 'self') { // выбрали "только свои записи" на "моей стене" $wall = MongoDatabase::getUserWall((int) $this->user_id, 0, 10, 'self'); }else $wall = MongoDatabase::getUserWall((int) $this->user_id, 0, 10, $this->type); }else { // показываем просто последнюю активность $wall = MongoDatabase::getLastWall(); } $events = MongoDatabase::getWallEvents($wall); $this->data = $this->_list($events); }
/** * get table informations * @param string $tableID */ public function getTableInfo($tableID) { $condition = 'MaBanAn=' . $tableID; return MongoDatabase::getOneDataFrom("BanAn", $condition); }
public function getAllMenu() { return MongoDatabase::getAllDataFrom("ThucDon"); }