Skip to content

Commit

Permalink
New Feature : Remotecontrol Export_timeline - refactored - fix for ms…
Browse files Browse the repository at this point in the history
…sql and postgres
  • Loading branch information
trougakoss committed Apr 16, 2013
1 parent 64399ca commit 7c4b5a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
10 changes: 1 addition & 9 deletions application/controllers/admin/remotecontrol.php
Expand Up @@ -703,15 +703,7 @@ public function export_timeline($sSessionKey, $iSurveyID, $sType, $dStart, $dEnd
$oResponses = Survey_dynamic::model($iSurveyID)->timeline($sType, $dStart, $dEnd);
if (empty($oResponses)) return array('status' => 'No valid Data');

foreach($oResponses as $aResponse){
$timeSlot = $aResponse['sDate'];

if($aResponse['sHour']!=null)
$timeSlot =$timeSlot."::". $aResponse['sHour'];

$aResult[$timeSlot] = $aResponse['sCount'];
}
return $aResult;
return $oResponses;

}

Expand Down
36 changes: 15 additions & 21 deletions application/models/Survey_dynamic.php
Expand Up @@ -17,10 +17,6 @@
class Survey_dynamic extends LSActiveRecord
{
protected static $sid = 0;
protected $sHour;
protected $sDay;
protected $sCount;
protected $sDate;

/**
* Returns the static model of Settings table
Expand Down Expand Up @@ -346,37 +342,35 @@ public function previous($srid,$usefilterstate=false)
*/
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 = 'date(submitdate) as sDate , COUNT(*) as sCount';
$criteria->select = 'submitdate';
$criteria->addCondition('submitdate >= :dstart');
$criteria->addCondition('submitdate <= :dend');
$criteria->order="sDate";
switch ($sType)
{
case 'hour':
$criteria->select .= ', HOUR(submitdate) as sHour';
$criteria->group = 'DATE(submitdate) , HOUR(submitdate)';
break;
case 'day':
default:
$criteria->select .= ', DAY(submitdate) as sDay';
$criteria->group = 'DATE(submitdate) ';
break;
}
$criteria->order="submitdate";

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

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);
}

}
Expand Down

0 comments on commit 7c4b5a1

Please sign in to comment.