Merge pull request #3835 from colemanw/groupCount
[civicrm-core.git] / CRM / Core / Session.php
index bebced13bc6c2f01e85f0b5eb785ff6841d1175b..24f53be63f093c779df17d17550c100963b7a090 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
 
 
 require_once "PEAR.php";
+
+/**
+ * Class CRM_Core_Session
+ */
 class CRM_Core_Session {
 
   /**
@@ -79,7 +83,7 @@ class CRM_Core_Session {
    * This constructor is invoked whenever any module requests an instance of
    * the session and one is not available.
    *
-   * @return void
+   * @return \CRM_Core_Session
    */
   function __construct() {
     $this->_session = null;
@@ -149,6 +153,8 @@ class CRM_Core_Session {
    *
    * @access public
    *
+   * @param int $all
+   *
    * @return void
    */
   function reset($all = 1) {
@@ -183,7 +189,7 @@ class CRM_Core_Session {
       return;
     }
 
-    if (!CRM_Utils_Array::value($prefix, $this->_session[$this->_key])) {
+    if (empty($this->_session[$this->_key][$prefix])) {
       $this->_session[$this->_key][$prefix] = array();
     }
   }
@@ -513,11 +519,14 @@ class CRM_Core_Session {
         'text' => $text,
         'title' => $title,
         'type' => $type,
-        'options' => $options ? json_encode($options) : NULL,
+        'options' => $options ? $options : NULL,
       );
     }
   }
 
+  /**
+   * @param $names
+   */
   static function registerAndRetrieveSessionObjects($names) {
     if (!is_array($names)) {
       $names = array($names);
@@ -533,6 +542,9 @@ class CRM_Core_Session {
     CRM_Core_BAO_Cache::restoreSessionFromCache($names);
   }
 
+  /**
+   * @param bool $reset
+   */
   static function storeSessionObjects($reset = TRUE) {
     if (empty(self::$_managedNames)) {
       return;
@@ -545,6 +557,21 @@ class CRM_Core_Session {
     self::$_managedNames = NULL;
   }
 
+  /**
+   * Retrieve contact id of the logged in user
+   * @return integer | NULL contact ID of logged in user
+   */
+  static function getLoggedInContactID() {
+    $session = CRM_Core_Session::singleton();
+    if (!is_numeric($session->get('userID'))) {
+      return NULL;
+    }
+    return $session->get('userID');
+  }
+
+  /**
+   * @return bool
+   */
   function isEmpty() {
     // check if session is empty, if so we dont cache
     // stuff that we can get away with