[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/core/ -> last_visited_api.php (source)

   1  <?php
   2  # MantisBT - A PHP based bugtracking system
   3  
   4  # MantisBT is free software: you can redistribute it and/or modify
   5  # it under the terms of the GNU General Public License as published by
   6  # the Free Software Foundation, either version 2 of the License, or
   7  # (at your option) any later version.
   8  #
   9  # MantisBT is distributed in the hope that it will be useful,
  10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  # GNU General Public License for more details.
  13  #
  14  # You should have received a copy of the GNU General Public License
  15  # along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Last Visited API
  19   *
  20   * @package CoreAPI
  21   * @subpackage LastVisitedAPI
  22   * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
  23   * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  24   * @link http://www.mantisbt.org
  25   *
  26   * @uses bug_api.php
  27   * @uses config_api.php
  28   * @uses constant_inc.php
  29   * @uses current_user_api.php
  30   * @uses database_api.php
  31   * @uses tokens_api.php
  32   */
  33  
  34  require_api( 'bug_api.php' );
  35  require_api( 'config_api.php' );
  36  require_api( 'constant_inc.php' );
  37  require_api( 'current_user_api.php' );
  38  require_api( 'database_api.php' );
  39  require_api( 'tokens_api.php' );
  40  
  41  /**
  42   * Determine if last visited feature is enabled
  43   *
  44   * @return true: enabled; false: otherwise.
  45   * @access public
  46   */
  47  function last_visited_enabled() {
  48      return !( OFF == config_get( 'recently_visited' ) || current_user_is_anonymous() );
  49  }
  50  
  51  /**
  52   * This method should be called from view, update, print pages for issues,
  53   * mantisconnect.
  54   *
  55   * @param issue_id    The issue id that was justed visited.
  56   * @param user_id    The user id that visited the issue, or null for current
  57   *                 logged in user.
  58   * @access public
  59   */
  60  function last_visited_issue( $p_issue_id, $p_user_id = null ) {
  61      if( !last_visited_enabled() ) {
  62          return;
  63      }
  64  
  65      $c_issue_id = db_prepare_int( $p_issue_id );
  66  
  67      $t_value = token_get_value( TOKEN_LAST_VISITED, $p_user_id );
  68      if( is_null( $t_value ) ) {
  69          $t_value = $c_issue_id;
  70      } else {
  71          $t_ids = explode( ',', $p_issue_id . ',' . $t_value );
  72          $t_ids = array_unique( $t_ids );
  73          $t_ids = array_slice( $t_ids, 0, config_get( 'recently_visited_count' ) );
  74          $t_value = implode( ',', $t_ids );
  75      }
  76  
  77      token_set( TOKEN_LAST_VISITED, $t_value, TOKEN_EXPIRY_LAST_VISITED, $p_user_id );
  78  }
  79  
  80  /**
  81   * Get an array of the last visited bug ids.  We intentionally don't check
  82   * if the ids still exists to avoid performance degradation.
  83   *
  84   * @param user_id    The user id to get the last visited issues for,
  85   *                 or null for current logged in user.
  86   * @return An array of issue ids or an empty array if none found.
  87   * @access public
  88   */
  89  function last_visited_get_array( $p_user_id = null ) {
  90      $t_value = token_get_value( TOKEN_LAST_VISITED, $p_user_id );
  91  
  92      if( is_null( $t_value ) ) {
  93          return array();
  94      }
  95  
  96      # we don't slice the array here to optimise for performance.  If the user reduces the number of recently
  97      # visited to track, then he/she will get the extra entries until visiting an issue.
  98      $t_ids = explode( ',', $t_value );
  99  
 100      bug_cache_array_rows( $t_ids );
 101      return $t_ids;
 102  }


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7