Skip to content

Commit

Permalink
New Feature : Remotecontrol Export_timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Apr 19, 2013
1 parent bacaf5f commit 679829c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
28 changes: 28 additions & 0 deletions application/controllers/admin/remotecontrol.php
Expand Up @@ -686,6 +686,34 @@ public function export_statistics($sSessionKey, $iSurveyID, $docType='pdf', $sL

}

/**
* RPC Routine to export submission timeline.
* Returns an array of values (count and period)
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID Id of the Survey
* @param string $sType (day|hour)
* @param string $dStart
* @param string $dEnd
* @return array On success: The timeline. On failure array with error information
* */
public function export_timeline($sSessionKey, $iSurveyID, $sType, $dStart, $dEnd)
{
if (!$this->_checkSessionKey($sSessionKey)) return array('status' => 'Invalid session key');
if (!in_array($sType, array('day','hour'))) return array('status' => 'Invalid Period');
if (!hasSurveyPermission($iSurveyID, 'responses', 'read')) return array('status' => 'No permission');
$oSurvey=Survey::model()->findByPk($iSurveyID);
if (is_null($oSurvey)) return array('status' => 'Error: Invalid survey ID');
if (!tableExists('{{survey_' . $iSurveyID . '}}')) return array('status' => 'No available data');

$oResponses = SurveyDynamic::model($iSurveyID)->timeline($sType, $dStart, $dEnd);
if (empty($oResponses)) return array('status' => 'No valid Data');

return $oResponses;

}

/**
* RPC routine to get survey summary, regarding token usage and survey participation.
* Returns the requested value as string.
Expand Down
44 changes: 44 additions & 0 deletions application/models/SurveyDynamic.php
Expand Up @@ -327,5 +327,49 @@ public function previous($srid,$usefilterstate=false)
}
return $previous;
}

/**
* Function that returns a timeline of the surveys submissions
*
* @param string sType
* @param string dStart
* @param string dEnd
*
* @access public
* @return array
*/
public function timeline($sType, $dStart, $dEnd)
{

$sid = self::$sid;
$oSurvey=Survey::model()->findByPk($sid);
if ($oSurvey['datestamp']!='Y') {
return false;
}
else
{
$criteria=new CDbCriteria;
$criteria->select = 'submitdate';
$criteria->addCondition('submitdate >= :dstart');
$criteria->addCondition('submitdate <= :dend');
$criteria->order="submitdate";

$criteria->params[':dstart'] = $dStart;
$criteria->params[':dend'] = $dEnd;
$oResult = $this->findAll($criteria);

if($sType=="hour")
$dFormat = "Y-m-d_G";
else
$dFormat = "Y-m-d";

foreach($oResult as $sResult)
{
$aRes[] = date($dFormat,strtotime($sResult['submitdate']));
}

return array_count_values($aRes);
}

}
?>

0 comments on commit 679829c

Please sign in to comment.