示例#1
0
文件: Handler.php 项目: visapi/amun
 public function getPublicResultSet($userId, array $fields, $startIndex = 0, $count = 16, $sortBy = null, $sortOrder = null, Condition $con = null, $mode = 0, $class = null, array $args = array())
 {
     $startIndex = $startIndex !== null ? (int) $startIndex : 0;
     $count = !empty($count) ? (int) $count : 16;
     $sortBy = $sortBy !== null ? $sortBy : 'date';
     $sortOrder = $sortOrder !== null ? (int) $sortOrder : Sql::SORT_DESC;
     $select = $this->hm->getTable('AmunService\\User\\Activity\\Receiver')->select(array('id', 'status', 'activityId', 'userId', 'date'), 'receiver')->join(Join::INNER, $this->hm->getTable('AmunService\\User\\Activity')->select(array('id', 'globalId', 'parentId', 'userId', 'refId', 'table', 'status', 'scope', 'verb', 'summary', 'date'))->join(Join::INNER, $this->hm->getTable('AmunService\\User\\Account')->select(array('globalId', 'name', 'profileUrl', 'thumbnailUrl'), 'author')))->where('receiverUserId', '=', $userId)->where('receiverStatus', '=', Receiver\Record::VISIBLE)->where('parentId', '=', 0)->where('scope', '=', 0)->where('userId', '=', $userId)->orderBy($sortBy, $sortOrder)->limit($startIndex, $count);
     if (!empty($fields)) {
         $select->setSelectedColumns($fields);
     }
     if ($con !== null && $con->hasCondition()) {
         $values = $con->toArray();
         foreach ($values as $row) {
             $select->where($row[0], $row[1], $row[2]);
         }
     }
     if ($mode == Sql::FETCH_OBJECT && $class === null) {
         $class = $this->getClassName();
     }
     if ($mode == Sql::FETCH_OBJECT && empty($args)) {
         $args = $this->getClassArgs();
     }
     $totalResults = $select->getTotalResults();
     $entries = $select->getAll($mode, $class, $args);
     $resultSet = new ResultSet($totalResults, $startIndex, $count, $entries);
     return $resultSet;
 }
示例#2
0
 public function getCount(Condition $condition = null)
 {
     $builder = $this->connection->createQueryBuilder()->select($this->connection->getDatabasePlatform()->getCountExpression($this->getPrimaryKey()))->from($this->getName(), null);
     if ($condition !== null && $condition->hasCondition()) {
         $builder->where(substr($condition->getStatment(), 5));
         $values = $condition->getValues();
         foreach ($values as $key => $value) {
             $builder->setParameter($key, $value);
         }
     }
     return (int) $this->connection->fetchColumn($builder->getSQL(), $builder->getParameters());
 }
示例#3
0
文件: Handler.php 项目: visapi/amun
 public function getPendingResultSet($userId, array $fields, $startIndex = 0, $count = 16, $sortBy = null, $sortOrder = null, Condition $con = null, $mode = 0, $class = null, array $args = array())
 {
     $startIndex = $startIndex !== null ? (int) $startIndex : 0;
     $count = !empty($count) ? (int) $count : 16;
     $sortBy = $sortBy !== null ? $sortBy : 'date';
     $sortOrder = $sortOrder !== null ? (int) $sortOrder : Sql::SORT_DESC;
     $select = $this->table->select(array('id', 'status', 'date'))->join(Join::INNER, $this->hm->getTable('AmunService\\User\\Account')->select(array('id', 'globalId', 'name', 'profileUrl', 'thumbnailUrl', 'updated', 'date'), 'author'), 'n:1', 'userId')->join(Join::INNER, $this->hm->getTable('AmunService\\User\\Account')->select(array('id', 'globalId', 'name', 'profileUrl', 'thumbnailUrl', 'updated', 'date'), 'friend'), 'n:1', 'friendId')->where('userId', '=', $userId)->where('status', '=', Record::REQUEST);
     if (!empty($fields)) {
         $select->select($fields);
     }
     if ($con !== null && $con->hasCondition()) {
         $values = $con->toArray();
         foreach ($values as $row) {
             $select->where($row[0], $row[1], $row[2]);
         }
     }
     if ($mode == Sql::FETCH_OBJECT && $class === null) {
         $class = $this->getClassName();
     }
     if ($mode == Sql::FETCH_OBJECT && empty($args)) {
         $args = $this->getClassArgs();
     }
     $totalResults = $select->getTotalResults();
     $entries = $select->getAll($mode, $class, $args);
     $resultSet = new ResultSet($totalResults, $startIndex, $count, $entries);
     return $resultSet;
 }
示例#4
0
文件: Request.php 项目: visapi/amun
 protected function getResponse(Provider\Consumer $consumer, Provider\Request $request)
 {
     // we check how often this ip has requested an token ... because
     // of security reasons each consumer can have max 5 request tokens
     $maxCount = 5;
     $ip = $_SERVER['REMOTE_ADDR'];
     $con = new Condition(array('ip', '=', $ip), array('status', '=', Oauth\Record::TEMPORARY));
     $count = $this->sql->count($this->registry['table.oauth_request'], $con);
     if ($count >= $maxCount) {
         $conDelete = new Condition();
         $result = $this->sql->select($this->registry['table.oauth_request'], array('id', 'expire', 'date'), $con, Sql::SELECT_ALL);
         foreach ($result as $row) {
             $now = new DateTime('NOW', $this->registry['core.default_timezone']);
             $date = new DateTime($row['date'], $this->registry['core.default_timezone']);
             $date->add(new DateInterval($row['expire']));
             if ($now > $date) {
                 $conDelete->add('id', '=', $row['id'], 'OR');
             }
         }
         if ($conDelete->hasCondition()) {
             $this->sql->delete($this->registry['table.oauth_request'], $conDelete);
         }
         throw new Exception('You can only have max. ' . $maxCount . ' active request tokens');
     }
     // get nonce
     $nonce = $request->getNonce();
     // assign callback
     $callback = $request->getCallback();
     // generate tokens
     $token = Security::generateToken();
     $tokenSecret = Security::generateToken();
     // we save the timestamp in the request but because it comes from
     // the user we doesnt use them to check the expire date
     $timestamp = $request->getTimestamp();
     // you have 30 minutes to authorize the request token and to exchange
     // them for an access token
     $expire = 'PT30M';
     $date = new DateTime('NOW', $this->registry['core.default_timezone']);
     $this->sql->insert($this->registry['table.oauth_request'], array('apiId' => $this->apiId, 'status' => Oauth\Record::TEMPORARY, 'ip' => $ip, 'nonce' => $nonce, 'callback' => $callback, 'token' => $token, 'tokenSecret' => $tokenSecret, 'timestamp' => $timestamp, 'expire' => $expire, 'date' => $date->format(DateTime::SQL)));
     $response = new Provider\Response();
     $response->setToken($token);
     $response->setTokenSecret($tokenSecret);
     return $response;
 }