Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev: added survey group controllers and model, +index view
- Loading branch information
LouisGac
committed
Jul 24, 2017
1 parent
f0198e0
commit d7b92af
Showing
4 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
application/controllers/admin/SurveysGroupsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
a<?php | ||
/* | ||
* LimeSurvey | ||
* Copyright (C) 2007-2011 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. | ||
* | ||
* Surveys Groups Controller | ||
*/ | ||
|
||
if (!defined('BASEPATH')) | ||
exit('No direct script access allowed'); | ||
|
||
|
||
class SurveysGroupsController extends Survey_Common_Action | ||
{ | ||
|
||
/** | ||
* Displays a particular model. | ||
* @param integer $id the ID of the model to be displayed | ||
*/ | ||
public function view($id) | ||
{ | ||
$this->render('view',array( | ||
'model'=>$this->loadModel($id), | ||
)); | ||
} | ||
|
||
/** | ||
* Creates a new model. | ||
* If creation is successful, the browser will be redirected to the 'view' page. | ||
*/ | ||
public function create() | ||
{ | ||
$model=new SurveysGroups; | ||
|
||
// Uncomment the following line if AJAX validation is needed | ||
// $this->performAjaxValidation($model); | ||
|
||
if(isset($_POST['SurveysGroups'])) | ||
{ | ||
$model->attributes=$_POST['SurveysGroups']; | ||
if($model->save()) | ||
$this->redirect(array('view','id'=>$model->gsid)); | ||
} | ||
|
||
$this->render('create',array( | ||
'model'=>$model, | ||
)); | ||
} | ||
|
||
/** | ||
* Updates a particular model. | ||
* If update is successful, the browser will be redirected to the 'view' page. | ||
* @param integer $id the ID of the model to be updated | ||
*/ | ||
public function update($id) | ||
{ | ||
$model=$this->loadModel($id); | ||
|
||
// Uncomment the following line if AJAX validation is needed | ||
// $this->performAjaxValidation($model); | ||
|
||
if(isset($_POST['SurveysGroups'])) | ||
{ | ||
$model->attributes=$_POST['SurveysGroups']; | ||
if($model->save()) | ||
$this->redirect(array('view','id'=>$model->gsid)); | ||
} | ||
|
||
$this->render('update',array( | ||
'model'=>$model, | ||
)); | ||
} | ||
|
||
/** | ||
* Deletes a particular model. | ||
* If deletion is successful, the browser will be redirected to the 'admin' page. | ||
* @param integer $id the ID of the model to be deleted | ||
*/ | ||
public function delete($id) | ||
{ | ||
$this->loadModel($id)->delete(); | ||
|
||
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser | ||
if(!isset($_GET['ajax'])) | ||
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); | ||
} | ||
|
||
/** | ||
* Lists all models. | ||
*/ | ||
public function index() | ||
{ | ||
$model = new SurveysGroups('search'); | ||
$aData['model'] = $model; | ||
$this->_renderWrappedTemplate('surveysgroups', 'index', $aData); | ||
/* | ||
$model = new TemplateConfiguration('search'); | ||
$model->sid = $model->gsid = $model->uid = null; | ||
$aData['model'] = $model; | ||
$this->_renderWrappedTemplate('templateoptions', 'index', $aData); | ||
*/ | ||
|
||
} | ||
|
||
/** | ||
* Manages all models. | ||
*/ | ||
public function admin() | ||
{ | ||
$model=new SurveysGroups('search'); | ||
$model->unsetAttributes(); // clear any default values | ||
if(isset($_GET['SurveysGroups'])) | ||
$model->attributes=$_GET['SurveysGroups']; | ||
|
||
$this->render('admin',array( | ||
'model'=>$model, | ||
)); | ||
} | ||
|
||
/** | ||
* Returns the data model based on the primary key given in the GET variable. | ||
* If the data model is not found, an HTTP exception will be raised. | ||
* @param integer $id the ID of the model to be loaded | ||
* @return SurveysGroups the loaded model | ||
* @throws CHttpException | ||
*/ | ||
public function loadModel($id) | ||
{ | ||
$model=SurveysGroups::model()->findByPk($id); | ||
if($model===null) | ||
throw new CHttpException(404,'The requested page does not exist.'); | ||
return $model; | ||
} | ||
|
||
/** | ||
* Performs the AJAX validation. | ||
* @param SurveysGroups $model the model to be validated | ||
*/ | ||
protected function performAjaxValidation($model) | ||
{ | ||
if(isset($_POST['ajax']) && $_POST['ajax']==='surveys-groups-form') | ||
{ | ||
echo CActiveForm::validate($model); | ||
Yii::app()->end(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
/** | ||
* This is the model class for table "{{surveys_groups}}". | ||
* | ||
* The followings are the available columns in table '{{surveys_groups}}': | ||
* @property integer $gsid | ||
* @property string $name | ||
* @property string $title | ||
* @property string $description | ||
* @property integer $order | ||
* @property integer $owner_uid | ||
* @property integer $parent_id | ||
* @property string $created | ||
* @property string $modified | ||
* @property integer $created_by | ||
*/ | ||
class SurveysGroups extends CActiveRecord | ||
{ | ||
/** | ||
* @return string the associated database table name | ||
*/ | ||
public function tableName() | ||
{ | ||
return '{{surveys_groups}}'; | ||
} | ||
|
||
/** | ||
* @return array validation rules for model attributes. | ||
*/ | ||
public function rules() | ||
{ | ||
// NOTE: you should only define rules for those attributes that | ||
// will receive user inputs. | ||
return array( | ||
array('name, order, created_by', 'required'), | ||
array('order, owner_uid, parent_id, created_by', 'numerical', 'integerOnly'=>true), | ||
array('name', 'length', 'max'=>45), | ||
array('title', 'length', 'max'=>100), | ||
array('description, created, modified', 'safe'), | ||
// The following rule is used by search(). | ||
// @todo Please remove those attributes that should not be searched. | ||
array('gsid, name, title, description, order, owner_uid, parent_id, created, modified, created_by', 'safe', 'on'=>'search'), | ||
); | ||
} | ||
|
||
/** | ||
* @return array relational rules. | ||
*/ | ||
public function relations() | ||
{ | ||
// NOTE: you may need to adjust the relation name and the related | ||
// class name for the relations automatically generated below. | ||
return array( | ||
); | ||
} | ||
|
||
/** | ||
* @return array customized attribute labels (name=>label) | ||
*/ | ||
public function attributeLabels() | ||
{ | ||
return array( | ||
'gsid' => 'Gsid', | ||
'name' => 'Name', | ||
'title' => 'Title', | ||
'description' => 'Description', | ||
'order' => 'Order', | ||
'owner_uid' => 'Owner Uid', | ||
'parent_id' => 'Parent', | ||
'created' => 'Created', | ||
'modified' => 'Modified', | ||
'created_by' => 'Created By', | ||
); | ||
} | ||
|
||
/** | ||
* Retrieves a list of models based on the current search/filter conditions. | ||
* | ||
* Typical usecase: | ||
* - Initialize the model fields with values from filter form. | ||
* - Execute this method to get CActiveDataProvider instance which will filter | ||
* models according to data in model fields. | ||
* - Pass data provider to CGridView, CListView or any similar widget. | ||
* | ||
* @return CActiveDataProvider the data provider that can return the models | ||
* based on the search/filter conditions. | ||
*/ | ||
public function search() | ||
{ | ||
// @todo Please modify the following code to remove attributes that should not be searched. | ||
|
||
$criteria=new CDbCriteria; | ||
|
||
$criteria->compare('gsid',$this->gsid); | ||
$criteria->compare('name',$this->name,true); | ||
$criteria->compare('title',$this->title,true); | ||
$criteria->compare('description',$this->description,true); | ||
$criteria->compare('order',$this->order); | ||
$criteria->compare('owner_uid',$this->owner_uid); | ||
$criteria->compare('parent_id',$this->parent_id); | ||
$criteria->compare('created',$this->created,true); | ||
$criteria->compare('modified',$this->modified,true); | ||
$criteria->compare('created_by',$this->created_by); | ||
|
||
return new CActiveDataProvider($this, array( | ||
'criteria'=>$criteria, | ||
)); | ||
} | ||
|
||
/** | ||
* Returns the static model of the specified AR class. | ||
* Please note that you should have this exact method in all your CActiveRecord descendants! | ||
* @param string $className active record class name. | ||
* @return SurveysGroups the static model class | ||
*/ | ||
public static function model($className=__CLASS__) | ||
{ | ||
return parent::model($className); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/* @var $this SurveysGroupsController */ | ||
/* @var $dataProvider CActiveDataProvider */ | ||
|
||
?> | ||
<div class="col-lg-12 list-surveys"> | ||
|
||
<?php $this->renderPartial('super/fullpagebar_view', array( | ||
'fullpagebar' => array( | ||
'returnbutton'=>array( | ||
'url'=>'index', | ||
'text'=>gT('Close'), | ||
), | ||
) | ||
)); ?> | ||
|
||
<h3><?php eT('Surveys Groups:'); ?></h3> | ||
|
||
<div class="row"> | ||
<div class="col-sm-12 content-right"> | ||
<?php | ||
$this->widget('bootstrap.widgets.TbGridView', array( | ||
'dataProvider' => $model->search(), | ||
)); | ||
?> | ||
</div> | ||
</div> | ||
</div> |