public function getNewPattern() { $jsonData = ["result" => "FAIL"]; try { $rs = $this->service->searchNew(""); $jsonData = ["result" => "OK", "data" => $rs]; } catch (Exception $ex) { PLog::log($ex); } return json_encode($jsonData); }
public function getRedisObj() { vendor('PhpRedis'); if ($this->_redis == null) { try { $this->_redis = new PhpRedis($this->_redis_config); if ($this->_redis->ping()) { return $this->_redis; } } catch (Exception $e) { PLog::write("redis 连接失败 :\n" . $e->getMessage() . "\n"); die(dump($e->getMessage())); return -1; } } else { return $this->_redis; } }
/** * Update pattern * @param PatternDto $ptn * @return Number: > 0 : ok, = 0 : fail, < 0 : data input is same current data */ public function update($ptn, $old) { $updated = 0; $isUpdPattern = false; $isUpdHeader = false; $isUpdDetail = false; $headerUpd = []; $detailIns = []; $detailUpd = []; $detailDel = []; // Compare title if (strcmp($ptn->info->title, $old->info->title) != 0) { $isUpdPattern = true; } // Compare header for ($i = 0; $i < $ptn->info->columnsize; $i++) { if (strcmp($ptn->header[$i]->header, $old->header[$i]->header) != 0) { $headerUpd[] = $i; $isUpdHeader = true; } } // Compare data if (count($ptn->data) > count($old->data)) { for ($i = 0; $i < count($ptn->data); $i++) { if ($i > count($old->data) - 1) { $detailIns[] = $i; $isUpdDetail = true; } else { if (strcmp($ptn->data[$i]->value, $old->data[$i]->value) != 0) { $detailUpd[] = $i; $isUpdDetail = true; } } } } else { for ($i = 0; $i < count($old->data); $i++) { if ($i > count($ptn->data) - 1) { $detailDel[] = $i; $isUpdDetail = true; } else { if (strcmp($ptn->data[$i]->value, $old->data[$i]->value) != 0) { $detailUpd[] = $i; $isUpdDetail = true; } } } } // Update database if ($isUpdPattern || $isUpdHeader || $isUpdDetail) { try { $this->dp->getDB()->beginTransaction(); // Update pattern $updated = $this->patternDao->update($ptn->info); if ($updated != 0) { // Update header for ($i = 0; $i < count($headerUpd); $i++) { $this->patternHeaderDao->update($ptn->header[$headerUpd[$i]]); } // Delete detail for ($i = 0; $i < count($detailDel); $i++) { $this->patternDetailDao->delete($old->data[$detailDel[$i]]->id); } // Update detail for ($i = 0; $i < count($detailUpd); $i++) { $old->data[$detailUpd[$i]]->value = $ptn->data[$detailUpd[$i]]->value; $this->patternDetailDao->update($old->data[$detailUpd[$i]]); } // Insert detail for ($i = 0; $i < count($detailIns); $i++) { $this->patternDetailDao->insert($ptn->data[$detailIns[$i]]); } } $this->dp->getDB()->commit(); $updated = 1; } catch (Exception $ex) { $this->dp->getDB()->rollBack(); $updated = 0; PLog::log($ex); } } else { $updated = -1; } return $updated; }
if ($totalPage > $page) { $nextPage = $page + 1; } Flight::render('./views/search.php', array('title' => Common::getTitle($param . " | Tìm kiếm"), 'searchResult' => $rs['data'], 'param' => $param, 'nextPage' => $nextPage, 'count' => $rs['count'])); }); // FB handler Flight::route('/fb/login', function () { //echo 'FB login'; FacebookSession::setDefaultApplication(FBID, FBS); $helper = new FacebookRedirectLoginHelper(REDIRECT_URL); $session = null; try { $session = $helper->getSessionFromRedirect(); } catch (Exception $ex) { // When validation fails or other local issues PLog::log($ex); } if (!is_null($session)) { // Get fb information $userProfile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className()); $fbName = $userProfile->getName(); $fbId = $userProfile->getId(); // Get account from database $db = DP::getInstant(); $accountSrv = new AccountService($db); $account = $accountSrv->getByFbId($fbId); // Insert into database If account not exist if (is_null($account)) { $account = new Account(); $account->fbId = $fbId; $account->fbName = $fbName;