Skip to content

Commit

Permalink
PORT THE FUNCTIONALITY 'CREATE/EDIT/DELETE USER GROUPS' TO THE YII PH…
Browse files Browse the repository at this point in the history
…P FRAMEWORK : Done by GCI participant Ivan Penchev

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11563 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
sachdeva-shubham committed Dec 2, 2011
1 parent dc6f97d commit 9ca2973
Show file tree
Hide file tree
Showing 9 changed files with 502 additions and 190 deletions.
1 change: 1 addition & 0 deletions application/controllers/AdminController.php
Expand Up @@ -110,6 +110,7 @@ public function actions()
'index' => 'application.controllers.admin.index',
'globalsettings' => 'application.controllers.admin.globalsettings',
'quotas' => 'application.controllers.admin.quotas',
'usergroups' => 'application.controllers.admin.usergroups',
'export' => 'application.controllers.admin.export',
'assessments' =>'application.controllers.admin.assessments',
'checkintegrity' => 'application.controllers.admin.checkintegrity',
Expand Down
305 changes: 166 additions & 139 deletions application/controllers/admin/usergroups.php

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions application/helpers/common_helper.php
Expand Up @@ -237,6 +237,7 @@ function getqtypelist($SelectedCode = "T", $ReturnType = "selector")
'answerscales'=>0),
);
asort($qtypes);

if ($ReturnType == "array") {return $qtypes;}
if ($ReturnType == "group"){
foreach($qtypes as $qkey=>$qtype){
Expand Down Expand Up @@ -7773,17 +7774,18 @@ function getusergrouplist($ugid=NULL,$outputformat='optionlist')

function getgroupuserlist($ugid)
{
$CI =& get_instance();
$CI->load->helper('database');
$clang = $CI->limesurvey_lang;
$yii = Yii::app();

$yii->loadHelper('database');
$clang = $yii->lang;

$ugid=sanitize_int($ugid);
$surveyidquery = "SELECT a.uid, a.users_name FROM ".$CI->db->dbprefix."users AS a LEFT JOIN (SELECT uid AS id FROM ".$CI->db->dbprefix."user_in_groups WHERE ugid = {$ugid}) AS b ON a.uid = b.id WHERE id IS NULL ORDER BY a.users_name";
$surveyidquery = "SELECT a.uid, a.users_name FROM ".$yii->db->tablePrefix."users AS a LEFT JOIN (SELECT uid AS id FROM ".$yii->db->tablePrefix."user_in_groups WHERE ugid = {$ugid}) AS b ON a.uid = b.id WHERE id IS NULL ORDER BY a.users_name";

$surveyidresult = db_execute_assoc($surveyidquery); //Checked
if (!$surveyidresult) {return "Database Error";}
$surveyselecter = "";
foreach ($surveyidresult->result_array() as $row)
foreach ($surveyidresult->readAll() as $row)
{
$surveynames[] = $row;
}
Expand Down
63 changes: 43 additions & 20 deletions application/helpers/database_helper.php
Expand Up @@ -3,37 +3,37 @@
function &db_execute_assoc($sql,$inputarr=false,$silent=false)
{
//$connect->SetFetchMode(ADODB_FETCH_ASSOC);
try {
if($inputarr)
{
$dataset=Yii::app()->db->createCommand($sql)->bindValues($inputarr)->query(); //Checked
}
else
{
$dataset=Yii::app()->db->createCommand($sql)->query();
/*try { */
if($inputarr)
{
$dataset=Yii::app()->db->createCommand($sql)->bindValues($inputarr)->query(); //Checked
}
else
{
$dataset=Yii::app()->db->createCommand($sql)->query();

}
} catch(CDbException $e) {
}
/*} catch(CDbException $e) {
$dataset=false;
}
}*/

if (!$silent && !$dataset) { safe_die('Error executing query in db_execute_assoc:'.$sql); }
//if (!$silent && !$dataset) { safe_die('Error executing query in db_execute_assoc:'.$sql); }
return $dataset;
}

function &db_execute($sql,$inputarr=false,$silent=false)
{
//$connect->SetFetchMode(ADODB_FETCH_ASSOC);
try {
if($inputarr)
{
$affected=Yii::app()->db->createCommand($sql)->bindValues($inputarr)->execute(); //Checked
}
else
{
$affected=Yii::app()->db->createCommand($sql)->execute();
if($inputarr)
{
$affected=Yii::app()->db->createCommand($sql)->bindValues($inputarr)->execute(); //Checked
}
else
{
$affected=Yii::app()->db->createCommand($sql)->execute();

}
}
} catch(CDbException $e) {
$affected=false;
}
Expand All @@ -52,6 +52,29 @@ function &db_query_or_false($sql)
return $dataset;
}

/**
* Returns the number of records found in the database
*
* @param string $sql
* @return int
*/
function &db_records_count($sql)
{
$yii = Yii::app();
$count = 0;
try
{
$result = $yii->db->createCommand($sql)->query();
$count = $result->count();
}
catch(CDbException $e)
{
$count = FALSE;
}

return $count;
}

function &db_select_limit_assoc($sql,$numrows=0,$offset=0,$inputarr=false,$dieonerror=true)
{
//$connect->SetFetchMode(ADODB_FETCH_ASSOC);
Expand Down
159 changes: 159 additions & 0 deletions application/models/User_groups.php
@@ -0,0 +1,159 @@
<?php if ( ! defined('BASEPATH')) die('No direct script access allowed');

class User_groups extends CActiveRecord {

protected $connection;

/**
* Returns the static model of Settings table
*
* @static
* @access public
* @return CActiveRecord
*/
public static function model()
{
return parent::model(__CLASS__);
}

/**
* Returns the setting's table name to be used by the model
*
* @access public
* @return string
*/
public function tableName()
{
return '{{user_groups}}';
}

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

function getAllRecords($condition=FALSE)
{
$this->connection = Yii::app()->db;
if ($condition != FALSE)
{
$where_clause = array("WHERE");

foreach($condition as $key=>$val)
{
$where_clause[] = $key.'=\''.$val.'\'';
}

$where_string = implode(' AND ', $where_clause);
}

$query = 'SELECT * FROM '.$this->tableName().' '.$where_string;

$data = createCommand($query)->query()->resultAll();

return $data;
}

function getSomeRecords($fields,$condition=FALSE, $params=NULL)
{
$filter = new CDbCriteria;

foreach ($fields as $field)
{
$filter->select[] = $field;
}

if ($condition != FALSE)
{
$filter->condition = $condition;
$filter->params = $params;
}

$data = $this->findAll($filter);

return $data;
}

/*function insertRecords($data)
{
return $this->db->insert('user_groups',$data);
}
function join($fields, $from, $condition=FALSE, $join=FALSE, $order=FALSE)
{
foreach ($fields as $field)
{
$this->db->select($field);
}
$this->db->from($from);
if ($condition != FALSE)
{
$this->db->where($condition);
}
if ($order != FALSE)
{
$this->db->order_by($order);
}
if (isset($join['where'], $join['type'], $join['on']))
{
$this->db->join($condition);
}
$data = $this->db->get();
return $data;
}
function multi_select($fields, $from, $condition=FALSE)
{
foreach ($fields as $field)
{
$this->db->select($field);
}
foreach ($from AS $f)
{
$this->db->from($f);
}
if ($condition != FALSE)
{
$this->db->where($condition);
}
if ($order != FALSE)
{
$this->db->order_by($order);
}
if (isset($join['where'], $join['type'], $join['on']))
{
$this->db->join($condition);
}
$data = $this->db->get();
return $data;
}
function update($what, $where=FALSE)
{
if ($where != FALSE) $this->db->where($where);
return (bool) $this->db->update('user_groups', $what);
}
function delete($condition)
{
return (bool) $this->db->delete('user_groups', $condition);
}*/

}
100 changes: 100 additions & 0 deletions application/models/User_in_groups.php
@@ -0,0 +1,100 @@
<?php if ( ! defined('BASEPATH')) die('No direct script access allowed');

class User_in_groups extends CActiveRecord {

/**
* Returns the static model of Settings table
*
* @static
* @access public
* @return CActiveRecord
*/
public static function model()
{
return parent::model(__CLASS__);
}

/**
* Returns the setting's table name to be used by the model
*
* @access public
* @return string
*/
public function tableName()
{
return '{{user_in_groups}}';
}

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

/*function getAllRecords($condition=FALSE)
{
if ($condition != FALSE)
{
$this->db->where($condition);
}
$data = $this->db->get('user_in_groups');
return $data;
}
function getSomeRecords($fields,$condition=FALSE)
{
foreach ($fields as $field)
{
$this->db->select($field);
}
if ($condition != FALSE)
{
$this->db->where($condition);
}
$data = $this->db->get('user_in_groups');
return $data;
}
function insert($data)
{
return (bool) $this->db->insert('user_in_groups', $data);
}
function join($fields, $from, $condition=FALSE, $join=FALSE, $order=FALSE)
{
foreach ($fields as $field)
{
$this->db->select($field);
}
$this->db->from($from);
if ($condition != FALSE)
{
$this->db->where($condition);
}
if ($order != FALSE)
{
$this->db->order_by($order);
}
if (isset($join['where'], $join['type'], $join['on']))
{
$this->db->join($condition);
}
$data = $this->db->get();
return $data;
}*/

}
2 changes: 1 addition & 1 deletion application/views/admin/usergroup/addUserGroup_view.php
@@ -1,5 +1,5 @@
<div class='header ui-widget-header'><?php echo $clang->gT("Add User Group"); ?></div>
<form action='<?php echo site_url("admin/usergroups/add"); ?>' id='usergroupform' class='form30' method='post'>
<form action='<?php echo $this->createUrl("admin/usergroups/add"); ?>' id='usergroupform' class='form30' method='post'>
<ul>
<li><label for='group_name'><?php echo $clang->gT("Name:"); ?></label>
<input type='text' size='50' id='group_name' name='group_name' />
Expand Down

0 comments on commit 9ca2973

Please sign in to comment.