当前位置: 首页>>代码示例>>PHP>>正文


PHP IManager::getQueryForFilter方法代码示例

本文整理汇总了PHP中OCP\Activity\IManager::getQueryForFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP IManager::getQueryForFilter方法的具体用法?PHP IManager::getQueryForFilter怎么用?PHP IManager::getQueryForFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OCP\Activity\IManager的用法示例。


在下文中一共展示了IManager::getQueryForFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: read

 /**
  * @brief Read a list of events from the activity stream
  * @param GroupHelper $groupHelper Allows activities to be grouped
  * @param UserSettings $userSettings Gets the settings of the user
  * @param int $start The start entry
  * @param int $count The number of statements to read
  * @param string $filter Filter the activities
  * @param string $user User for whom we display the stream
  * @param string $objectType
  * @param int $objectId
  * @return array
  */
 public function read(GroupHelper $groupHelper, UserSettings $userSettings, $start, $count, $filter = 'all', $user = '', $objectType = '', $objectId = 0)
 {
     // get current user
     if ($user === '') {
         $user = $this->userSession->getUser();
         if ($user instanceof IUser) {
             $user = $user->getUID();
         } else {
             // No user given and not logged in => no activities
             return [];
         }
     }
     $groupHelper->setUser($user);
     $enabledNotifications = $userSettings->getNotificationTypes($user, 'stream');
     $enabledNotifications = $this->activityManager->filterNotificationTypes($enabledNotifications, $filter);
     $parameters = array_unique($enabledNotifications);
     // We don't want to display any activities
     if (empty($parameters)) {
         return array();
     }
     $placeholders = implode(',', array_fill(0, sizeof($parameters), '?'));
     $limitActivities = " AND `type` IN (" . $placeholders . ")";
     array_unshift($parameters, $user);
     if ($filter === 'self') {
         $limitActivities .= ' AND `user` = ?';
         $parameters[] = $user;
     } else {
         if ($filter === 'by' || $filter === 'all' && !$userSettings->getUserSetting($user, 'setting', 'self')) {
             $limitActivities .= ' AND `user` <> ?';
             $parameters[] = $user;
         } else {
             if ($filter === 'filter') {
                 if (!$userSettings->getUserSetting($user, 'setting', 'self')) {
                     $limitActivities .= ' AND `user` <> ?';
                     $parameters[] = $user;
                 }
                 $limitActivities .= ' AND `object_type` = ?';
                 $parameters[] = $objectType;
                 $limitActivities .= ' AND `object_id` = ?';
                 $parameters[] = $objectId;
             }
         }
     }
     list($condition, $params) = $this->activityManager->getQueryForFilter($filter);
     if (!is_null($condition)) {
         $limitActivities .= ' ';
         $limitActivities .= $condition;
         if (is_array($params)) {
             $parameters = array_merge($parameters, $params);
         }
     }
     return $this->getActivities($count, $start, $limitActivities, $parameters, $groupHelper);
 }
开发者ID:enoch85,项目名称:owncloud-testserver,代码行数:65,代码来源:data.php

示例2: read

 /**
  * @brief Read a list of events from the activity stream
  * @param GroupHelper $groupHelper Allows activities to be grouped
  * @param UserSettings $userSettings Gets the settings of the user
  * @param int $start The start entry
  * @param int $count The number of statements to read
  * @param string $filter Filter the activities
  * @return array
  */
 public function read(GroupHelper $groupHelper, UserSettings $userSettings, $start, $count, $filter = 'all')
 {
     // get current user
     $user = User::getUser();
     $enabledNotifications = $userSettings->getNotificationTypes($user, 'stream');
     $enabledNotifications = $this->filterNotificationTypes($enabledNotifications, $filter);
     // We don't want to display any activities
     if (empty($enabledNotifications)) {
         return array();
     }
     $parameters = array($user);
     $limitActivities = " AND `type` IN ('" . implode("','", $enabledNotifications) . "')";
     if ($filter === 'self') {
         $limitActivities .= ' AND `user` = ?';
         $parameters[] = $user;
     } else {
         if ($filter === 'by' || $filter === 'all' && !$userSettings->getUserSetting($user, 'setting', 'self')) {
             $limitActivities .= ' AND `user` <> ?';
             $parameters[] = $user;
         } else {
             if ($filter !== 'all') {
                 switch ($filter) {
                     case 'files':
                         $limitActivities .= ' AND `app` = ?';
                         $parameters[] = 'files';
                         break;
                     default:
                         list($condition, $params) = $this->activityManager->getQueryForFilter($filter);
                         if (!is_null($condition)) {
                             $limitActivities .= ' ';
                             $limitActivities .= $condition;
                             if (is_array($params)) {
                                 $parameters = array_merge($parameters, $params);
                             }
                         }
                 }
             }
         }
     }
     // fetch from DB
     $query = DB::prepare('SELECT * ' . ' FROM `*PREFIX*activity` ' . ' WHERE `affecteduser` = ? ' . $limitActivities . ' ORDER BY `timestamp` DESC', $count, $start);
     $result = $query->execute($parameters);
     return $this->getActivitiesFromQueryResult($result, $groupHelper);
 }
开发者ID:kebenxiaoming,项目名称:owncloudRedis,代码行数:53,代码来源:data.php

示例3: get

 /**
  * Read a list of events from the activity stream
  *
  * @param GroupHelper $groupHelper Allows activities to be grouped
  * @param UserSettings $userSettings Gets the settings of the user
  * @param string $user User for whom we display the stream
  *
  * @param int $since The integer ID of the last activity that has been seen.
  * @param int $limit How many activities should be returned
  * @param string $sort Should activities be given ascending or descending
  *
  * @param string $filter Filter the activities
  * @param string $objectType Allows to filter the activities to a given object. May only appear together with $objectId
  * @param int $objectId Allows to filter the activities to a given object. May only appear together with $objectType
  *
  * @return array
  *
  * @throws \OutOfBoundsException if the user (Code: 1) or the since (Code: 2) is invalid
  * @throws \BadMethodCallException if the user has selected to display no types for this filter (Code: 3)
  */
 public function get(GroupHelper $groupHelper, UserSettings $userSettings, $user, $since, $limit, $sort, $filter, $objectType = '', $objectId = 0)
 {
     // get current user
     if ($user === '') {
         throw new \OutOfBoundsException('Invalid user', 1);
     }
     $groupHelper->setUser($user);
     $enabledNotifications = $userSettings->getNotificationTypes($user, 'stream');
     $enabledNotifications = $this->activityManager->filterNotificationTypes($enabledNotifications, $filter);
     $enabledNotifications = array_unique($enabledNotifications);
     // We don't want to display any activities
     if (empty($enabledNotifications)) {
         throw new \BadMethodCallException('No settings enabled', 3);
     }
     $query = $this->connection->getQueryBuilder();
     $query->select('*')->from('activity');
     $query->where($query->expr()->eq('affecteduser', $query->createNamedParameter($user)))->andWhere($query->expr()->in('type', $query->createNamedParameter($enabledNotifications, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)));
     if ($filter === 'self') {
         $query->andWhere($query->expr()->eq('user', $query->createNamedParameter($user)));
     } else {
         if ($filter === 'by') {
             $query->andWhere($query->expr()->neq('user', $query->createNamedParameter($user)));
         } else {
             if ($filter === 'all' && !$userSettings->getUserSetting($user, 'setting', 'self')) {
                 $query->andWhere($query->expr()->orX($query->expr()->neq('user', $query->createNamedParameter($user)), $query->expr()->notIn('type', $query->createNamedParameter(['file_created', 'file_changed', 'file_deleted', 'file_restored'], IQueryBuilder::PARAM_STR_ARRAY))));
             } else {
                 if ($filter === 'filter') {
                     if (!$userSettings->getUserSetting($user, 'setting', 'self')) {
                         $query->andWhere($query->expr()->orX($query->expr()->neq('user', $query->createNamedParameter($user)), $query->expr()->notIn('type', $query->createNamedParameter(['file_created', 'file_changed', 'file_deleted', 'file_restored'], IQueryBuilder::PARAM_STR_ARRAY))));
                     }
                     $query->andWhere($query->expr()->eq('object_type', $query->createNamedParameter($objectType)));
                     $query->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId)));
                 }
             }
         }
     }
     list($condition, $params) = $this->activityManager->getQueryForFilter($filter);
     if (!is_null($condition)) {
         // Strip away ' and '
         $condition = substr($condition, 5);
         if (is_array($params)) {
             // Replace ? placeholders with named parameters
             foreach ($params as $param) {
                 $pos = strpos($condition, '?');
                 if ($pos !== false) {
                     $condition = substr($condition, 0, $pos) . $query->createNamedParameter($param) . substr($condition, $pos + 1);
                 }
             }
         }
         $query->andWhere($query->createFunction($condition));
     }
     /**
      * Order and specify the offset
      */
     $sqlSort = $sort === 'asc' ? 'ASC' : 'DESC';
     $headers = $this->setOffsetFromSince($query, $user, $since, $sqlSort);
     $query->orderBy('timestamp', $sqlSort)->addOrderBy('activity_id', $sqlSort);
     $query->setMaxResults($limit + 1);
     $result = $query->execute();
     $hasMore = false;
     while ($row = $result->fetch()) {
         if ($limit === 0) {
             $hasMore = true;
             break;
         }
         $headers['X-Activity-Last-Given'] = (int) $row['activity_id'];
         $groupHelper->addActivity($row);
         $limit--;
     }
     $result->closeCursor();
     return ['data' => $groupHelper->getActivities(), 'has_more' => $hasMore, 'headers' => $headers];
 }
开发者ID:drognisep,项目名称:Portfolio-Site,代码行数:92,代码来源:Data.php


注:本文中的OCP\Activity\IManager::getQueryForFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。