コード例 #1
0
 /**
  * getUserRank - given user info return array of rank information for the user
  *
  * @param Response $response \Xoops\Core\Service\Response object
  * @param mixed    $userinfo Xoops\Core\Kernel\Handlers\XoopsUser object for user (preferred) or
  *                            array of user info,
  *                               'uid'   => (int) id of system user
  *                               'posts' => (int) contribution count associated with the user
  *                               'rank'  => (int) id of manually assigned rank, 0 if none assigned
  *
  * @return void - $response->value set to array of rank information
  *                    'title' => string that describes the rank
  *                    'image' => url of image associated with the rank
  */
 public function getUserRank(Response $response, $userinfo)
 {
     $uid = isset($userinfo['uid']) ? (int) $userinfo['uid'] : null;
     $posts = isset($userinfo['posts']) ? (int) $userinfo['posts'] : null;
     $rank = isset($userinfo['rank']) ? (int) $userinfo['rank'] : null;
     if ($uid === null || $posts === null || $rank === null) {
         $response->setSuccess(false)->addErrorMessage('User info is invalid');
         return;
     }
     $myts = \MyTextSanitizer::getInstance();
     $db = \Xoops::getInstance()->db();
     $qb = $db->createXoopsQueryBuilder();
     $eb = $qb->expr();
     $qb->select('r.rank_title AS title')->addSelect('r.rank_image AS image')->fromPrefix('userrank_rank', 'r');
     if ($rank != 0) {
         $qb->where($eb->eq('r.rank_id', ':rank'))->setParameter(':rank', $rank, \PDO::PARAM_INT);
     } else {
         $qb->where($eb->lte('r.rank_min', ':posts'))->andWhere($eb->gte('r.rank_max', ':posts'))->andWhere($eb->eq('r.rank_special', 0))->setParameter(':posts', $posts, \PDO::PARAM_INT);
     }
     $result = $qb->execute();
     $rank = $result->fetch(\PDO::FETCH_ASSOC);
     $rank['title'] = isset($rank['title']) ? $myts->htmlSpecialChars($rank['title']) : '';
     $rank['image'] = \XoopsBaseConfig::get('uploads-url') . (isset($rank['image']) ? '/' . $rank['image'] : '/blank.gif');
     $response->setValue($rank);
 }
コード例 #2
0
ファイル: ResponseTest.php プロジェクト: ming-hai/XoopsCore
 /**
  * @covers Xoops\Core\Service\Response::setSuccess
  */
 public function testSetSuccess()
 {
     $value = 'value';
     $instance = new Response($value, false);
     $result = $instance->isSuccess();
     $this->assertFalse($result);
     $result = $instance->setSuccess(true);
     $this->assertSame($instance, $result);
     $result = $instance->isSuccess();
     $this->assertTrue($result);
     $instance->setSuccess(false);
     $result = $instance->isSuccess();
     $this->assertFalse($result);
 }
コード例 #3
0
ファイル: NullProvider.php プロジェクト: RanLee/XoopsCore
 /**
  * All static methods go here and will return null response
  *
  * @param type $name      not used
  * @param type $arguments not used
  *
  * @return Response Response
  */
 public static function __callStatic($name, $arguments)
 {
     $response = new Response();
     $response->setSuccess(false)->addErrorMessage(sprintf("No provider installed for %s", get_called_class()));
     return $response;
 }