Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Yii' into Yii
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed May 2, 2012
2 parents 6f1d969 + 6686fcd commit fd6c832
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 137 deletions.
11 changes: 7 additions & 4 deletions application/controllers/admin/browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ public function view($iSurveyId, $iId, $sBrowseLang = '')
//SHOW INDIVIDUAL RECORD
$oCriteria = new CDbCriteria();
if ($aData['surveyinfo']['anonymized'] == 'N' && tableExists("{{tokens_$iSurveyId}}}"))
$oCriteria->join = "LEFT JOIN '{{tokens_{$iSurveyId}}}' ON {{surveys_{$iSurveyId}}}.token = {{tokens_{$iSurveyId}}}.token";
{
$oCriteria = Survey_dynamic::model($iSurveyId)->addTokenCriteria($oCriteria);
}
if (incompleteAnsFilterState() == 'inc')
$oCriteria->addCondition('submitdate = ' . mktime(0, 0, 0, 1, 1, 1980) . ' OR submitdate IS NULL');
elseif (incompleteAnsFilterState() == 'filter')
Expand All @@ -194,7 +196,7 @@ public function view($iSurveyId, $iId, $sBrowseLang = '')
}
$oCriteria->addCondition("id = {$iId}");

$iIdresult = Survey_dynamic::model($iSurveyId)->findAll($oCriteria) or die("Couldn't get entry");
$iIdresult = Survey_dynamic::model($iSurveyId)->findAllAsArray($oCriteria) or die("Couldn't get entry");
foreach ($iIdresult as $iIdrow)
{
$iId = $iIdrow['id'];
Expand Down Expand Up @@ -490,7 +492,7 @@ public function index($iSurveyId)
//Create the query
if ($aData['surveyinfo']['anonymized'] == "N" && tableExists("{{tokens_{$iSurveyId}}}"))
{
$oCriteria->join = "LEFT JOIN {{tokens_{$iSurveyId}}} ON t.token = {{tokens_{$iSurveyId}}}.token";
$oCriteria = Survey_dynamic::model($iSurveyId)->addTokenCriteria($oCriteria);
}

if (incompleteAnsFilterState() == "inc")
Expand All @@ -517,7 +519,8 @@ public function index($iSurveyId)
$oCriteria->offset = $start;
$oCriteria->limit = $limit;

$dtresult = Survey_dynamic::model($iSurveyId)->findAll($oCriteria);
$dtresult = Survey_dynamic::model($iSurveyId)->findAllAsArray($oCriteria);

$dtcount2 = count($dtresult);
$cells = $fncount + 1;

Expand Down
39 changes: 23 additions & 16 deletions application/helpers/admin/activate_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function activateSurvey($surveyid, $simulate = false)
}

//Get list of questions for the base language
$fieldmap = createFieldMap($surveyid,'full',false,false,getBaseLanguageFromSurveyID($surveyid));
$fieldmap = createFieldMap($surveyid,'full',true,false,getBaseLanguageFromSurveyID($surveyid));

$createsurvey = array();
foreach ($fieldmap as $j=>$arow) //With each question, create the appropriate field(s)
Expand All @@ -299,7 +299,6 @@ function activateSurvey($surveyid, $simulate = false)
break;
case 'id':
$createsurvey[$arow['fieldname']] = "INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY";
$createsurveytimings .= " `{$arow['fieldname']}` INT NOT NULL PRIMARY,\n";
break;
case "startdate":
case "datestamp":
Expand Down Expand Up @@ -456,24 +455,32 @@ function activateSurvey($surveyid, $simulate = false)
}
}
}
}

if (isset($savetimings) && $savetimings=="TRUE")
{
$timingsfieldmap = createTimingsFieldMap($surveyid,"full",false,false,getBaseLanguageFromSurveyID($surveyid));
$createsurveytimings .= '`'.implode("` F DEFAULT '0',\n`",array_keys($timingsfieldmap)) . "` F DEFAULT '0'";

if (isset($savetimings) && $savetimings=="TRUE")
{
$timingsfieldmap = createTimingsFieldMap($surveyid,"full",false,false,getBaseLanguageFromSurveyID($surveyid));

$column = array();
$column['id'] = $createsurvey['id'];
foreach ($timingsfieldmap as $field=>$fielddata)
{
$column[$field] = 'FLOAT';
}

foreach ($timingsfieldmap as $field=>$fielddata)
{
$column[$field] = 'FLOAT';
}
$command = new CDbCommand(Yii::app()->db);
foreach($column as $name => $type)
{
$command->addColumn($tabname,$name,$type);
}
$command = new CDbCommand(Yii::app()->db);
$tabname = "{{survey_{$surveyid}}}_timings";
try
{
$execresult = $command->createTable($tabname,$column);
$execresult = true;
}
catch (CDbException $e)
{
echo $e->getMessage();
$execresult = false;
}

}

$activateoutput .= "<br />\n<div class='messagebox ui-corner-all'>\n";
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/expressions/em_manager_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
case 'U': //HUGE FREE TEXT
if ($this->sgqaNaming)
{
$sq_name = '!(' . preg_replace('/\bthis\b/',substr($sq['jsVarName'],4), $em_validation_sq) . ')';
$subqValidEqn = '!(' . preg_replace('/\bthis\b/',substr($sq['jsVarName'],4), $em_validation_sq) . ')';
}
else
{
Expand Down
265 changes: 169 additions & 96 deletions application/models/Survey_dynamic.php
Original file line number Diff line number Diff line change
@@ -1,118 +1,191 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
* Files Purpose: lots of common functions
*/

class Survey_dynamic extends CActiveRecord
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
* Files Purpose: lots of common functions
*/

class Survey_dynamic extends CActiveRecord
{
protected static $sid = 0;

/**
* Returns the static model of Settings table
*
* @static
* @access public
* @param int $surveyid
* @return Survey_dynamic
*/
public static function model($sid = NULL)
{
protected static $sid = 0;

/**
* Returns the static model of Settings table
*
* @static
* @access public
* @param int $surveyid
* @return CActiveRecord
*/
public static function model($sid = NULL)
{
if (!is_null($sid))
self::sid($sid);
if (!is_null($sid))
self::sid($sid);

return parent::model(__CLASS__);
}
return parent::model(__CLASS__);
}

/**
* Sets the survey ID for the next model
*
* @static
* @access public
* @param int $sid
* @return void
*/
public static function sid($sid)
{
self::$sid = (int) $sid;
}
/**
* Sets the survey ID for the next model
*
* @static
* @access public
* @param int $sid
* @return void
*/
public static function sid($sid)
{
self::$sid = (int) $sid;
}

/**
* Returns the setting's table name to be used by the model
*
* @access public
* @return string
*/
public function tableName()
{
return '{{survey_' . self::$sid . '}}';
}
/**
* Returns the setting's table name to be used by the model
*
* @access public
* @return string
*/
public function tableName()
{
return '{{survey_' . self::$sid . '}}';
}

/**
* Returns the primary key of this table
*
* @access public
* @return string
*/
public function primaryKey()
/**
* Returns the primary key of this table
*
* @access public
* @return string
*/
public function primaryKey()
{
return 'sid';
}

/**
* Insert records from $data array
*
* @access public
* @param array $data
* @return boolean
*/
public function insertRecords($data)
{
$record = new self;
foreach ($data as $k => $v)
{
return 'sid';
$search = array('`', "'");
$k = str_replace($search, '', $k);
$v = str_replace($search, '', $v);
$record->$k = $v;
}
return $record->save();
}

/**
* Insert records from $data array
*
* @access public
* @param array $data
* @return boolean
*/
public function insertRecords($data)
/**
* Deletes some records from survey's table
* according to specific condition
*
* @static
* @access public
* @param array $condition
* @return int
*/
public static function deleteSomeRecords($condition = FALSE)
{
$survey = new Survey_dynamic;
$criteria = new CDbCriteria;

if ($condition != FALSE)
{
$record = new self;
foreach ($data as $k => $v)
foreach ($condition as $column => $value)
{
$search = array('`', "'");
$k = str_replace($search, '', $k);
$v = str_replace($search, '', $v);
$record->$k = $v;
return $criteria->addCondition($column . "=`" . $value . "`");
}
return $record->save();
}

/**
* Deletes some records from survey's table
* according to specific condition
*
* @static
* @access public
* @param array $condition
* @return int
*/
public static function deleteSomeRecords($condition=FALSE)
{
$survey = new Survey_dynamic;
$criteria = new CDbCriteria;
return $survey->deleteAll($criteria);
}

if( $condition != FALSE )
/**
* Modified version that default to do the same as the original, but allows via a
* third parameter to retrieve the result as array instead of active records. This
* solves a joining problem. Usage via findAllAsArray method
*
* Performs the actual DB query and populates the AR objects with the query result.
* This method is mainly internally used by other AR query methods.
* @param CDbCriteria $criteria the query criteria
* @param boolean $all whether to return all data
* @return mixed the AR objects populated with the query result
* @since 1.1.7
*/
protected function query($criteria, $all = false, $asAR = true)
{
if ($asAR === true)
{
return parent::query($criteria, $all);
} else
{
$this->beforeFind();
$this->applyScopes($criteria);
if (!$all)
{
foreach ($condition as $column => $value)
{
return $criteria->addCondition($column."=`".$value."`");
}
$criteria->limit = 1;
}

return $survey->deleteAll($criteria);
$command = $this->getCommandBuilder()->createFindCommand($this->getTableSchema(), $criteria);
//For debug, this command will get you the generated sql:
//echo $command->getText();

return $all ? $command->queryAll() : $command->queryRow();
}
}

/**
* Finds all active records satisfying the specified condition but returns them as array
*
* See {@link find()} for detailed explanation about $condition and $params.
* @param mixed $condition query condition or criteria.
* @param array $params parameters to be bound to an SQL statement.
* @return array list of active records satisfying the specified condition. An empty array is returned if none is found.
*/
public function findAllAsArray($condition = '', $params = array())
{
Yii::trace(get_class($this) . '.findAll()', 'system.db.ar.CActiveRecord');
$criteria = $this->getCommandBuilder()->createCriteria($condition, $params);
return $this->query($criteria, true, false); //Notice the third parameter 'false'
}

/**
* Return criteria updated with the ones needed for including results from the token table
*
* @param CDbCriteria|string $criteria
*
* @return CDbCriteria
*/
public function addTokenCriteria($condition)
{
$newCriteria = new CDbCriteria();
$criteria = $this->getCommandBuilder()->createCriteria($condition);

if ($criteria->select == '*')
{
$criteria->select = 't.*';
}

$newCriteria->join = "LEFT JOIN {{tokens_" . self::$sid . "}} tokens ON t.token = tokens.token";
$newCriteria->select = 'tokens.*'; // Otherwise we don't get records from the token table
$newCriteria->mergeWith($criteria);

return $newCriteria;
}

}
?>

0 comments on commit fd6c832

Please sign in to comment.