|
From: <gem...@li...> - 2012-11-22 11:17:40
|
Revision: 1029
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1029&view=rev
Author: mennodekker
Date: 2012-11-22 11:17:29 +0000 (Thu, 22 Nov 2012)
Log Message:
-----------
initial setup
Modified Paths:
--------------
branches/receptioncodes/library/classes/Gems/Events.php
Added Paths:
-----------
branches/receptioncodes/library/classes/Gems/Event/ReceptionCode/
branches/receptioncodes/library/classes/Gems/Event/ReceptionCodeEventInterface.php
Added: branches/receptioncodes/library/classes/Gems/Event/ReceptionCodeEventInterface.php
===================================================================
--- branches/receptioncodes/library/classes/Gems/Event/ReceptionCodeEventInterface.php (rev 0)
+++ branches/receptioncodes/library/classes/Gems/Event/ReceptionCodeEventInterface.php 2012-11-22 11:17:29 UTC (rev 1029)
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package Gems
+ * @subpackage Event
+ * @author Menno Dekker <men...@er...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: RoundChangedEventInterface.php 59 2011-09-22 07:23:44Z mennodekker $
+ */
+
+/**
+ * When settings a receptioncode this code runs
+ *
+ * The code should take care of delegation to other objects
+ *
+ * @package Gems
+ * @subpackage Event
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.6
+ */
+class Gems_Event_ReceptionCodeEventInterface extends Gems_Event_EventInterface
+{
+ public function setReceptionCode($object, $receptionCode, $comment, $userId);
+}
\ No newline at end of file
Modified: branches/receptioncodes/library/classes/Gems/Events.php
===================================================================
--- branches/receptioncodes/library/classes/Gems/Events.php 2012-11-22 11:11:40 UTC (rev 1028)
+++ branches/receptioncodes/library/classes/Gems/Events.php 2012-11-22 11:17:29 UTC (rev 1029)
@@ -48,11 +48,12 @@
{
const EVENTS_DIR = 'Event';
- const TRACK_COMPLETION_EVENT = 'Track/Completed';
+ const RECEPTIONCODE_EVENT = 'ReceptionCode';
const ROUND_CHANGED_EVENT = 'Round/Changed';
const SURVEY_BEFORE_ANSWERING_EVENT = 'Survey/BeforeAnswering';
const SURVEY_COMPLETION_EVENT = 'Survey/Completed';
const SURVEY_DISPLAY_EVENT = 'Survey/Display';
+ const TRACK_COMPLETION_EVENT = 'Track/Completed';
/**
* Each event type must implement an event class or interface derived
@@ -63,11 +64,12 @@
* @var array containing eventType => eventClass for all event classes
*/
protected $_eventClasses = array(
- self::TRACK_COMPLETION_EVENT => 'Gems_Event_TrackCompletedEventInterface',
+ self::RECEPTIONCODE_EVENT => 'Gems_Event_ReceptionCodeEventInterface',
self::ROUND_CHANGED_EVENT => 'Gems_Event_RoundChangedEventInterface',
self::SURVEY_BEFORE_ANSWERING_EVENT => 'Gems_Event_SurveyBeforeAnsweringEventInterface',
self::SURVEY_COMPLETION_EVENT => 'Gems_Event_SurveyCompletedEventInterface',
self::SURVEY_DISPLAY_EVENT => 'Gems_Event_SurveyDisplayEventInterface',
+ self::TRACK_COMPLETION_EVENT => 'Gems_Event_TrackCompletedEventInterface'
);
/**
@@ -204,6 +206,15 @@
return $event;
}
+
+ /**
+ *
+ * @return array eventname => string
+ */
+ public function listReceptionCodeEvents()
+ {
+ return $this->_listEvents(self::RECEPTIONCODE_EVENT);
+ }
/**
*
@@ -249,10 +260,20 @@
{
return $this->_listEvents(self::TRACK_COMPLETION_EVENT);
}
-
+
/**
*
* @param string $eventName
+ * @return Gems_Event_ReceptionCodeEventInterface
+ */
+ public function loadReceptionCodeEvent($eventName)
+ {
+ return $this->_loadEvent($eventName, self::RECEPTIONCODE_EVENT);
+ }
+
+ /**
+ *
+ * @param string $eventName
* @return Gems_Event_RoundChangedEventInterface
*/
public function loadRoundChangedEvent($eventName)
@@ -300,4 +321,4 @@
{
return $this->_loadEvent($eventName, self::TRACK_COMPLETION_EVENT);
}
-}
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2012-11-22 11:40:00
|
Revision: 1031
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1031&view=rev
Author: mennodekker
Date: 2012-11-22 11:39:50 +0000 (Thu, 22 Nov 2012)
Log Message:
-----------
Moved receptioncode from util to tracker
Modified Paths:
--------------
branches/receptioncodes/library/classes/Gems/Tracker/RespondentTrack.php
branches/receptioncodes/library/classes/Gems/Tracker/Token.php
branches/receptioncodes/library/classes/Gems/Tracker.php
branches/receptioncodes/library/classes/Gems/Util.php
Added Paths:
-----------
branches/receptioncodes/library/classes/Gems/Tracker/ReceptionCode.php
Removed Paths:
-------------
branches/receptioncodes/library/classes/Gems/Util/ReceptionCode.php
Copied: branches/receptioncodes/library/classes/Gems/Tracker/ReceptionCode.php (from rev 1030, branches/receptioncodes/library/classes/Gems/Util/ReceptionCode.php)
===================================================================
--- branches/receptioncodes/library/classes/Gems/Tracker/ReceptionCode.php (rev 0)
+++ branches/receptioncodes/library/classes/Gems/Tracker/ReceptionCode.php 2012-11-22 11:39:50 UTC (rev 1031)
@@ -0,0 +1,202 @@
+<?php
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package Gems
+ * @subpackage Util
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ * Utility function for the user of reception codes.
+ *
+ * @package Gems
+ * @subpackage Util
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_Tracker_ReceptionCode extends Gems_Registry_CachedArrayTargetAbstract
+{
+ /**
+ * Variable to add tags to the cache for cleanup.
+ *
+ * @var array
+ */
+ protected $_cacheTags = array('reception_code');
+
+ /**
+ *
+ * @var Zend_Db_Adapter_Abstract
+ */
+ protected $db;
+
+ /**
+ * Compatibility mode, for use with logical operators returns this->getCode()
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->getCode();
+ }
+
+ /**
+ * Returns the complete record.
+ *
+ * @return array
+ */
+ public function getAllData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * The reception code.
+ *
+ * @return string
+ */
+ public function getCode()
+ {
+ return $this->_id;
+ }
+
+ /**
+ *
+ * @return boolean
+ */
+ public function getDescription()
+ {
+ return $this->_get('grc_description');
+ }
+
+ /**
+ *
+ * @return boolean
+ */
+ public function hasDescription()
+ {
+ return (boolean) $this->_get('grc_description');
+ }
+
+ /**
+ *
+ * @return boolean
+ */
+ public function hasRedoCode()
+ {
+ return (boolean) $this->_get('grc_redo_survey');
+ }
+
+ /**
+ * True if the reception code is a redo survey copy.
+ *
+ * @return boolean
+ */
+ public function hasRedoCopyCode()
+ {
+ return Gems_Util_ReceptionCodeLibrary::REDO_COPY == $this->_get('grc_redo_survey');
+ }
+
+ /**
+ * Is this code for respondent use?
+ *
+ * @return boolean
+ */
+ public function isForRespondents()
+ {
+ return (boolean) $this->_get('grc_for_respondents');
+ }
+
+ /**
+ * Is this code for track use?
+ *
+ * @return boolean
+ */
+ public function isForTracks()
+ {
+ return (boolean) $this->_get('grc_for_tracks');
+ }
+
+ /**
+ * Is this code for survey use?
+ *
+ * @return boolean
+ */
+ public function isForSurveys()
+ {
+ return $this->_get('grc_for_surveys') > Gems_Util_ReceptionCodeLibrary::APPLY_NOT;
+ }
+
+ /**
+ * Does this code overwrite set values?
+ *
+ * @return boolean
+ */
+ public function isOverwriter()
+ {
+ return (boolean) $this->_get('grc_overwrite_answers');
+ }
+
+ /**
+ * Is this code a survey stop code.
+ *
+ * Then do not apply it to the track or respondent, but do apply it to the tokens.
+ *
+ * @return boolean
+ */
+ public function isStopCode()
+ {
+ // MUtil_Echo::track($this->_data);
+ return $this->_get('grc_for_surveys') === Gems_Util_ReceptionCodeLibrary::APPLY_STOP;
+ }
+
+ /**
+ * Is this code a success code.
+ *
+ * @return boolean
+ */
+ public function isSuccess()
+ {
+ return (boolean) $this->_get('grc_success');
+ }
+
+ /**
+ * Load the data when the cache is empty.
+ *
+ * @param mixed $id
+ * @return array The array of data values
+ */
+ protected function loadData($id)
+ {
+ $sql = "SELECT * FROM gems__reception_codes WHERE grc_id_reception_code = ? LIMIT 1";
+ return $this->db->fetchRow($sql, $id);
+ }
+}
Modified: branches/receptioncodes/library/classes/Gems/Tracker/RespondentTrack.php
===================================================================
--- branches/receptioncodes/library/classes/Gems/Tracker/RespondentTrack.php 2012-11-22 11:19:31 UTC (rev 1030)
+++ branches/receptioncodes/library/classes/Gems/Tracker/RespondentTrack.php 2012-11-22 11:39:50 UTC (rev 1031)
@@ -732,15 +732,15 @@
* Set the reception code for this respondent track and make sure the
* necessary cascade to the tokens and thus the source takes place.
*
- * @param string $code The new (non-success) reception code or a Gems_Util_ReceptionCode object
+ * @param string $code The new (non-success) reception code or a Gems_Tracker_ReceptionCode object
* @param string $comment Comment for tokens. False values leave value unchanged
* @param int $userId The current user
* @return int 1 if the token has changed, 0 otherwise
*/
public function setReceptionCode($code, $comment, $userId)
{
- // Make sure it is a Gems_Util_ReceptionCode object
- if (! $code instanceof Gems_Util_ReceptionCode) {
+ // Make sure it is a Gems_Tracker_ReceptionCode object
+ if (! $code instanceof Gems_Tracker_ReceptionCode) {
$code = $this->util->getReceptionCode($code);
}
$changed = 0;
Modified: branches/receptioncodes/library/classes/Gems/Tracker/Token.php
===================================================================
--- branches/receptioncodes/library/classes/Gems/Tracker/Token.php 2012-11-22 11:19:31 UTC (rev 1030)
+++ branches/receptioncodes/library/classes/Gems/Tracker/Token.php 2012-11-22 11:39:50 UTC (rev 1031)
@@ -842,13 +842,13 @@
}
/**
- * Return the Gems_Util_ReceptionCode object
+ * Return the Gems_Tracker_ReceptionCode object
*
- * @return Gems_Util_ReceptionCode reception code
+ * @return Gems_Tracker_ReceptionCode reception code
*/
public function getReceptionCode()
{
- return $this->util->getReceptionCode($this->_gemsData['gto_reception_code']);
+ return $this->tracker->getReceptionCode($this->_gemsData['gto_reception_code']);
}
/**
@@ -1402,15 +1402,15 @@
* Set the reception code for this token and make sure the necessary
* cascade to the source takes place.
*
- * @param string $code The new (non-success) reception code or a Gems_Util_ReceptionCode object
+ * @param string $code The new (non-success) reception code or a Gems_Tracker_ReceptionCode object
* @param string $comment Comment False values leave value unchanged
* @param int $userId The current user
* @return int 1 if the token has changed, 0 otherwise
*/
public function setReceptionCode($code, $comment, $userId)
{
- // Make sure it is a Gems_Util_ReceptionCode object
- if (! $code instanceof Gems_Util_ReceptionCode) {
+ // Make sure it is a Gems_Tracker_ReceptionCode object
+ if (! $code instanceof Gems_Tracker_ReceptionCode) {
$code = $this->util->getReceptionCode($code);
}
Modified: branches/receptioncodes/library/classes/Gems/Tracker.php
===================================================================
--- branches/receptioncodes/library/classes/Gems/Tracker.php 2012-11-22 11:19:31 UTC (rev 1030)
+++ branches/receptioncodes/library/classes/Gems/Tracker.php 2012-11-22 11:39:50 UTC (rev 1031)
@@ -339,7 +339,24 @@
}
/**
+ * Returns a single reception code object.
*
+ * @param string $code
+ * @return Gems_Tracker_ReceptionCode
+ */
+ public function getReceptionCode($code)
+ {
+ static $codes = array();
+
+ if (! isset($codes[$code])) {
+ $codes[$code] = $this->_loadClass('receptionCode', true, array($code));
+ }
+
+ return $codes[$code];
+ }
+
+ /**
+ *
* @param mixed $respTrackData Track id or array containing trackdata
* @return Gems_Tracker_RespondentTrack
*/
Deleted: branches/receptioncodes/library/classes/Gems/Util/ReceptionCode.php
===================================================================
--- branches/receptioncodes/library/classes/Gems/Util/ReceptionCode.php 2012-11-22 11:19:31 UTC (rev 1030)
+++ branches/receptioncodes/library/classes/Gems/Util/ReceptionCode.php 2012-11-22 11:39:50 UTC (rev 1031)
@@ -1,202 +0,0 @@
-<?php
-/**
- * Copyright (c) 2011, Erasmus MC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Erasmus MC nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *
- * @package Gems
- * @subpackage Util
- * @author Matijs de Jong <mj...@ma...>
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @version $Id$
- */
-
-/**
- * Utility function for the user of reception codes.
- *
- * @package Gems
- * @subpackage Util
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @since Class available since version 1.5
- */
-class Gems_Util_ReceptionCode extends Gems_Registry_CachedArrayTargetAbstract
-{
- /**
- * Variable to add tags to the cache for cleanup.
- *
- * @var array
- */
- protected $_cacheTags = array('reception_code');
-
- /**
- *
- * @var Zend_Db_Adapter_Abstract
- */
- protected $db;
-
- /**
- * Compatibility mode, for use with logical operators returns this->getCode()
- *
- * @return string
- */
- public function __toString()
- {
- return $this->getCode();
- }
-
- /**
- * Returns the complete record.
- *
- * @return array
- */
- public function getAllData()
- {
- return $this->_data;
- }
-
- /**
- * The reception code.
- *
- * @return string
- */
- public function getCode()
- {
- return $this->_id;
- }
-
- /**
- *
- * @return boolean
- */
- public function getDescription()
- {
- return $this->_get('grc_description');
- }
-
- /**
- *
- * @return boolean
- */
- public function hasDescription()
- {
- return (boolean) $this->_get('grc_description');
- }
-
- /**
- *
- * @return boolean
- */
- public function hasRedoCode()
- {
- return (boolean) $this->_get('grc_redo_survey');
- }
-
- /**
- * True if the reception code is a redo survey copy.
- *
- * @return boolean
- */
- public function hasRedoCopyCode()
- {
- return Gems_Util_ReceptionCodeLibrary::REDO_COPY == $this->_get('grc_redo_survey');
- }
-
- /**
- * Is this code for respondent use?
- *
- * @return boolean
- */
- public function isForRespondents()
- {
- return (boolean) $this->_get('grc_for_respondents');
- }
-
- /**
- * Is this code for track use?
- *
- * @return boolean
- */
- public function isForTracks()
- {
- return (boolean) $this->_get('grc_for_tracks');
- }
-
- /**
- * Is this code for survey use?
- *
- * @return boolean
- */
- public function isForSurveys()
- {
- return $this->_get('grc_for_surveys') > Gems_Util_ReceptionCodeLibrary::APPLY_NOT;
- }
-
- /**
- * Does this code overwrite set values?
- *
- * @return boolean
- */
- public function isOverwriter()
- {
- return (boolean) $this->_get('grc_overwrite_answers');
- }
-
- /**
- * Is this code a survey stop code.
- *
- * Then do not apply it to the track or respondent, but do apply it to the tokens.
- *
- * @return boolean
- */
- public function isStopCode()
- {
- // MUtil_Echo::track($this->_data);
- return $this->_get('grc_for_surveys') === Gems_Util_ReceptionCodeLibrary::APPLY_STOP;
- }
-
- /**
- * Is this code a success code.
- *
- * @return boolean
- */
- public function isSuccess()
- {
- return (boolean) $this->_get('grc_success');
- }
-
- /**
- * Load the data when the cache is empty.
- *
- * @param mixed $id
- * @return array The array of data values
- */
- protected function loadData($id)
- {
- $sql = "SELECT * FROM gems__reception_codes WHERE grc_id_reception_code = ? LIMIT 1";
- return $this->db->fetchRow($sql, $id);
- }
-}
Modified: branches/receptioncodes/library/classes/Gems/Util.php
===================================================================
--- branches/receptioncodes/library/classes/Gems/Util.php 2012-11-22 11:19:31 UTC (rev 1030)
+++ branches/receptioncodes/library/classes/Gems/Util.php 2012-11-22 11:39:50 UTC (rev 1031)
@@ -239,17 +239,15 @@
* Returns a single reception code object.
*
* @param string $code
- * @return Gems_Util_ReceptionCode
+ * @deprecated since 1.6
+ * @return Gems_Tracker_ReceptionCode
*/
public function getReceptionCode($code)
{
- static $codes = array();
-
- if (! isset($codes[$code])) {
- $codes[$code] = $this->_loadClass('receptionCode', true, array($code));
- }
-
- return $codes[$code];
+ MUtil_Echo::track('Using util->getReceptionCode please update to tracker->getReceptionCode');
+
+ // Forward to the right place
+ return GemsEscort::getInstance()->getLoader()->getTracker()->getReceptionCode($code);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2012-11-27 09:50:52
|
Revision: 1042
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1042&view=rev
Author: mennodekker
Date: 2012-11-27 09:50:46 +0000 (Tue, 27 Nov 2012)
Log Message:
-----------
Some unfinished work...
Modified Paths:
--------------
branches/receptioncodes/library/classes/Gems/Tracker/ReceptionCode.php
Added Paths:
-----------
branches/receptioncodes/library/classes/Gems/Event/ReceptionCode/ReceptionCodeEventAbstract.php
branches/receptioncodes/library/classes/Gems/Tracker/Respondent.php
Added: branches/receptioncodes/library/classes/Gems/Event/ReceptionCode/ReceptionCodeEventAbstract.php
===================================================================
--- branches/receptioncodes/library/classes/Gems/Event/ReceptionCode/ReceptionCodeEventAbstract.php (rev 0)
+++ branches/receptioncodes/library/classes/Gems/Event/ReceptionCode/ReceptionCodeEventAbstract.php 2012-11-27 09:50:46 UTC (rev 1042)
@@ -0,0 +1,45 @@
+<?php
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ * Description of ReceptionCodeEventAbstract
+ *
+ * @author 175780
+ */
+class Gems_Event_ReceptionCode_ReceptionCodeEventAbstract implements Gems_Event_ReceptionCodeEventInterface {
+
+ public function setReceptionCode($object, $receptionCode, $comment, $userId)
+ {
+ // Perform your own logic here
+ }
+
+ protected function cascade($object, $receptionCode, $comment, $userId) {
+ if ($object instanceof Gems_Tracker_Token) {
+ $this->cascadeToken($object, $receptionCode, $comment, $userId);
+ }
+ }
+
+ /**
+ * Handles cascading FROM a respondent object down
+ *
+ * @param type $object
+ * @param type $receptionCode
+ * @param type $comment
+ * @param type $userId
+ */
+ protected function cascadeRespondent($object, $receptionCode, $comment, $userId) {
+
+ }
+
+ protected function cascadeToken($object, $receptionCode, $comment, $userId) {
+
+ }
+
+ protected function cascadeTrack($object, $receptionCode, $comment, $userId) {
+
+ }
+}
\ No newline at end of file
Modified: branches/receptioncodes/library/classes/Gems/Tracker/ReceptionCode.php
===================================================================
--- branches/receptioncodes/library/classes/Gems/Tracker/ReceptionCode.php 2012-11-26 13:30:22 UTC (rev 1041)
+++ branches/receptioncodes/library/classes/Gems/Tracker/ReceptionCode.php 2012-11-27 09:50:46 UTC (rev 1042)
@@ -57,6 +57,12 @@
* @var Zend_Db_Adapter_Abstract
*/
protected $db;
+
+ /**
+ *
+ * @var Gems_Loader
+ */
+ protected $loader;
/**
* Compatibility mode, for use with logical operators returns this->getCode()
@@ -96,6 +102,31 @@
{
return $this->_get('grc_description');
}
+
+ /**
+ *
+ * @return Gems_Event_ReceptionCodeEventInterface
+ */
+ public function getEvent()
+ {
+ return $this->loader->getEvents()->loadReceptionCodeEvent($this->_get('grc_event'));
+ }
+
+ /**
+ * Handle the set receptioncode event
+ *
+ * This code is executed by the object where the reception code is set. Further
+ * cascading to other objects should be handled by the event.
+ *
+ * @param type $object The object that initially gets the receptioncode
+ * @param Gems_Tracker_ReceptionCode $receptionCode
+ * @param string $comment
+ * @param int $userId
+ * @return int 0 for no change 1 for any number of changes
+ */
+ public function handleEvent($object, $receptionCode, $comment, $userId) {
+ return $this->getEvent()->setReceptionCode($object, $receptionCode, $comment, $userId);
+ }
/**
*
Added: branches/receptioncodes/library/classes/Gems/Tracker/Respondent.php
===================================================================
--- branches/receptioncodes/library/classes/Gems/Tracker/Respondent.php (rev 0)
+++ branches/receptioncodes/library/classes/Gems/Tracker/Respondent.php 2012-11-27 09:50:46 UTC (rev 1042)
@@ -0,0 +1,241 @@
+<?php
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package Gems
+ * @subpackage Tracker
+ * @author Menno Dekker <men...@er...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: RespondentTrack.php 1033 2012-11-22 12:13:08Z mennodekker $
+ */
+
+/**
+ *
+ * @package Gems
+ * @subpackage Tracker
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.6
+ */
+class Gems_Tracker_Respondent extends Gems_Registry_TargetAbstract
+{
+ /**
+ *
+ * @var array The gems__respondents data
+ */
+ protected $_respondentData;
+
+ /**
+ *
+ * @var int The gems__respondents id
+ */
+ protected $_respondentId;
+
+ /**
+ *
+ * @var int The gems__respondent2org id
+ */
+ protected $_respondentOrgId;
+
+ /**
+ *
+ * @var Gems_Tracker
+ */
+ protected $tracker;
+
+ /**
+ *
+ * @var Gems_Loader
+ */
+ protected $loader;
+
+ /**
+ *
+ * @var Gems_Model_RespondentModel
+ */
+ protected $model;
+
+ /**
+ * @param mixed $respondentData RespondentId or array containing respondent & respondent2org record
+ * @param int $respondentOrgId Organization this respondent belongs to
+ */
+ public function __construct($respondentData, $respondentOrgId = null)
+ {
+ if (is_array($respondentData)) {
+ $this->_respondentData = $respondentData;
+ $this->init();
+ } else {
+ $this->_respondentId = $respondentData;
+ $this->_respondentOrgId = $respondentOrgId;
+ }
+ }
+
+
+ /**
+ * 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->_respondentData) {
+ $this->refresh();
+ }
+
+ return (boolean) $this->_respondentData;
+ }
+
+ /**
+ *
+ * @return string The respondents patient number
+ */
+ public function getPatientNumber()
+ {
+ if (! isset($this->_respTrackData['gr2o_patient_nr'])) {
+ $this->refresh();
+ }
+
+ return $this->_respTrackData['gr2o_patient_nr'];
+ }
+
+ /**
+ *
+ * @return int The organization id
+ */
+ public function getOrganizationId()
+ {
+ return $this->_respondentOrgId;
+ }
+
+ public function getReceptionCode()
+ {
+ return $this->tracker->getReceptionCode($this->_respondentData['gr2o_reception_code']);
+ }
+
+ /**
+ *
+ * @return int The respondent id
+ */
+ public function getRespondentId()
+ {
+ return $this->_respondentId;
+ }
+
+ /**
+ * Get the respondentmodel for this respondent
+ *
+ * Used internally for retrieving and storing respondents
+ *
+ * @return Gems_Model_RespondentModel
+ */
+ public function getRespondentModel()
+ {
+ if (! $this->_model instanceof Gems_Model_RespondentModel) {
+ $this->_model = $this->loader->getModels()->getRespondentModel(true);
+ }
+
+ return $this->_model;
+ }
+
+ /**
+ * Handles setting or resetting respondentId and RespondentOrgId
+ */
+ public function init() {
+ $this->_respondentId = isset($this->_respondentData['grs_id_user']) ? $this->_respondentData['grs_id_user'] : null;
+ $this->_respondentOrgId = isset($this->_respondentData['gr2o_id_organization']) ? $this->_respondentData['gr2o_id_organization'] : null;
+ }
+
+
+ /**
+ *
+ * @param array $respondentData Optional, the data refresh with, otherwise refresh from database.
+ * @return Gems_Tracker_RespondentTrack (continuation pattern)
+ */
+ public function refresh(array $respondentData = null)
+ {
+ if (is_array($respondentData)) {
+ $this->_respondentData = $respondentData + $this->_respondentData;
+ $this->init();
+
+ } elseif (!is_null($this->_respondentId)) {
+ $respondentData = $this->getRespondentModel()->loadFirst(array(
+ 'grs_id_user' => $this->_respondentId,
+ 'gr2o_id_organization' => $this->_respondentOrgId
+ ));
+ if ($respondentData) {
+ $this->_respondentData = $respondentData;
+ $this->init();
+ } else {
+ $this->_respondentData = array();
+ $this->init();
+ }
+
+ }
+
+ return $this;
+ }
+
+ /**
+ * Set the reception code for this respondent track and make sure the
+ * necessary cascade to the tokens and thus the source takes place.
+ *
+ * @param string $code The new (non-success) reception code or a Gems_Tracker_ReceptionCode object
+ * @param string $comment Comment for tokens. False values leave value unchanged
+ * @param int $userId The current user
+ * @return int 1 if the token has changed, 0 otherwise
+ */
+ public function setReceptionCode($code, $comment, $userId)
+ {
+ // Make sure it is a Gems_Tracker_ReceptionCode object
+ if (! $code instanceof Gems_Tracker_ReceptionCode) {
+ $code = $this->tracker->getReceptionCode($code);
+ }
+ $changed = 0;
+
+ $values = array(
+ 'grs_id_user'=>$this->_respondentId,
+ 'gr2o_id_organization'=>$this->_respondentId,
+ );
+ // We can not handle saving a comment for this code, so just enter the code
+ // $values['gr2t_comment'] = $comment;
+ $values['gr2o_reception_code'] = $code->getCode();
+
+ $model = $this->getRespondentModel();
+ $newValues = $model->save($values);
+ $changed = (bool) $model->getChanged();
+ if ($changed) {
+ $this->refresh();
+ }
+
+ $eventChanged = $code->handleEvent($this, $code, $comment, $userId);
+ $changed = ($changed || $eventChanged);
+
+ return $changed;
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|