|
From: <gem...@li...> - 2011-11-15 12:38:30
|
Revision: 219
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=219&view=rev
Author: matijsdejong
Date: 2011-11-15 12:38:23 +0000 (Tue, 15 Nov 2011)
Log Message:
-----------
Organizations are now stored in cache
Modified Paths:
--------------
trunk/library/classes/Gems/Loader.php
trunk/library/classes/Gems/User/Organization.php
trunk/library/classes/Gems/User/UserLoader.php
Modified: trunk/library/classes/Gems/Loader.php
===================================================================
--- trunk/library/classes/Gems/Loader.php 2011-11-15 11:05:57 UTC (rev 218)
+++ trunk/library/classes/Gems/Loader.php 2011-11-15 12:38:23 UTC (rev 219)
@@ -1,4 +1,5 @@
<?php
+
/**
* Copyright (c) 2011, Erasmus MC
* All rights reserved.
Modified: trunk/library/classes/Gems/User/Organization.php
===================================================================
--- trunk/library/classes/Gems/User/Organization.php 2011-11-15 11:05:57 UTC (rev 218)
+++ trunk/library/classes/Gems/User/Organization.php 2011-11-15 12:38:23 UTC (rev 219)
@@ -46,27 +46,90 @@
* @license New BSD License
* @since Class available since version 1.5
*/
-class Gems_User_Organization
+class Gems_User_Organization extends Gems_Registry_TargetAbstract
{
/**
+ * The default organization data for 'no organization'.
*
* @var array
*/
+ protected $_noOrganization = array(
+ 'gor_id_organization' => 1,
+ 'gor_name' => 'NO ORGANIZATION',
+ 'gor_code' => null,
+ 'gor_style' => null,
+ 'gor_iso_lang' => 'en',
+ 'gor_active' => 0,
+ );
+
+ /**
+ *
+ * @var array
+ */
protected $_organizationData;
/**
+ *
+ * @var int
+ */
+ protected $_organizationId;
+
+ /**
+ *
+ * @var Zend_Cache_Core
+ */
+ protected $cache;
+
+ /**
+ *
+ * @var Zend_Db_Adapter_Abstract
+ */
+ protected $db;
+
+ /**
* Creates the organization object.
*
- * @param array $organizationData
+ * @param int $organizationId
*/
- public function __construct(array $organizationData)
+ public function __construct($organizationId)
{
- $this->_organizationData = $organizationData;
+ $this->_organizationId = $organizationId;
}
/**
+ * Should be called after answering the request to allow the Target
+ * to check if all required registry values have been set correctly.
+ *
+ * @return boolean False if required are missing.
+ */
+ public function checkRegistryRequestsAnswers()
+ {
+ if ($this->cache) {
+ $cacheId = GEMS_PROJECT_NAME . '__' . __CLASS__ . '__' . $this->_organizationId;
+ $this->_organizationData = $this->cache->load($cacheId);
+ } else {
+ $cacheId = false;
+ }
+
+ if (! $this->_organizationData) {
+ $this->_organizationData = $this->db->fetchRow('SELECT * FROM gems__organizations WHERE gor_id_organization = ? LIMIT 1', $this->_organizationId);
+
+ if (! $this->_organizationData) {
+ $this->_organizationData = $this->_noOrganization;
+ }
+
+ if ($cacheId) {
+ $this->cache->save($this->_organizationData, $cacheId);
+ }
+ }
+
+ return is_array($this->_organizationData) && parent::checkRegistryRequestsAnswers();
+ }
+
+
+ /**
* Get the style attribute.
- *
+ *
* @return string
*/
public function getStyle()
Modified: trunk/library/classes/Gems/User/UserLoader.php
===================================================================
--- trunk/library/classes/Gems/User/UserLoader.php 2011-11-15 11:05:57 UTC (rev 218)
+++ trunk/library/classes/Gems/User/UserLoader.php 2011-11-15 12:38:23 UTC (rev 219)
@@ -55,20 +55,6 @@
const USER_STAFF = 'StaffUser';
/**
- * The default organization data for 'no organization'.
- *
- * @var array
- */
- protected static $_noOrganization = array(
- 'gor_id_organization' => 1,
- 'gor_name' => 'NO ORGANIZATION',
- 'gor_code' => null,
- 'gor_style' => null,
- 'gor_iso_lang' => 'en',
- 'gor_active' => 0,
- );
-
- /**
* Allows sub classes of Gems_Loader_LoaderAbstract to specify the subdirectory where to look for.
*
* @var string $cascade An optional subdirectory where this subclass always loads from.
@@ -174,38 +160,17 @@
*/
public function getOrganization($organizationId = null)
{
- if (! self::$organizationStore) {
- self::$organizationStore = new Zend_Session_Namespace('gems.' . GEMS_PROJECT_NAME . '.organizations');
- }
+ static $organizations = array();
if (null === $organizationId) {
$organizationId = intval(self::$currentUser->getOrganizationId());
}
- if (! self::$organizationStore->__isset($organizationId)) {
-
- // We are not sure the is a database at this moment
- try {
- $data = $this->db->fetchRow('SELECT * FROM gems__organizations WHERE gor_id_organization = ? LIMIT 1', $organizationId);
- } catch (Zend_Db_Exception $e) {
- $data = false;
- }
- if (! $data) {
- // Use default
- $data = self::$_noOrganization;
-
- // But do attempt to get the last added organization.
- foreach (self::$organizationStore->getIterator() as $key => $value) {
- if ($key !== 0) {
- $organizationId = $key;
- $data = self::$organizationStore->__get($key);
- }
- }
- }
- self::$organizationStore->__set($organizationId, $data);
+ if (! isset($organizations[$organizationId])) {
+ $organizations[$organizationId] = $this->_loadClass('Organization', true, array($organizationId));
}
- return new Gems_User_Organization(self::$organizationStore->__get($organizationId));
+ return $organizations[$organizationId];
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|