Commit 749be554 by henny flora panjaitan

by henny

parent 026e0bb1
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace app\commands;
use yii\console\Controller;
use yii\console\ExitCode;
/**
* This command echoes the first argument that you have entered.
*
* This command is provided as an example for you to learn how to create console commands.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class HelloController extends Controller
{
/**
* This command echoes what you have entered as the message.
* @param string $message the message to be echoed.
* @return int Exit code
*/
public function actionIndex($message = 'hello world')
{
echo $message . "\n";
return ExitCode::OK;
}
}
<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'app\commands',
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
'@tests' => '@app/tests',
],
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
],
'params' => $params,
/*
'controllerMap' => [
'fixture' => [ // Fixture generation command line.
'class' => 'yii\faker\FixtureController',
],
],
*/
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=db_online_voting',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
// Schema cache options (for production environment)
//'enableSchemaCache' => true,
//'schemaCacheDuration' => 60,
//'schemaCache' => 'cache',
];
<?php
return [
'adminEmail' => 'admin@example.com',
'senderEmail' => 'noreply@example.com',
'senderName' => 'Example.com mailer',
];
<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/test_db.php';
/**
* Application configuration shared by all test types
*/
return [
'id' => 'basic-tests',
'basePath' => dirname(__DIR__),
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'language' => 'en-US',
'components' => [
'db' => $db,
'mailer' => [
'useFileTransport' => true,
],
'assetManager' => [
'basePath' => __DIR__ . '/../web/assets',
],
'urlManager' => [
'showScriptName' => true,
],
'user' => [
'identityClass' => 'app\models\User',
],
'request' => [
'cookieValidationKey' => 'test',
'enableCsrfValidation' => false,
// but if you absolutely need it set cookie domain to localhost
/*
'csrfCookie' => [
'domain' => 'localhost',
],
*/
],
],
'params' => $params,
];
<?php
$db = require __DIR__ . '/db.php';
// test database! Important not to run tests on production or development databases
$db['dsn'] = 'mysql:host=localhost;dbname=yii2_basic_tests';
return $db;
<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '123',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => false,
'authTimeout' => 1000,
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => 'mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
/*'host' => 'email-smtp.us-west-2.amazonaws.com',
'username' => 'AKIA5TT7FXGNG7WGIZ5T',
'password' => 'BFNUb8VDVUGDvtshQIrQlpgvWJfoTBIu64R98/L48T5E',*/
'host' => 'smtp.gmail.com',
'username' => 'gtconlinesystem@gmail.com',
'password' => 'GtcKey@2019OK!',
'port' => '587',
'encryption' => 'tls',
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
'authManager' => [
'class' => 'yii\rbac\DbManager', // only support DbManager
],
],
'as access' => [
'class' => '\hscstudio\mimin\components\AccessControl',
'allowActions' => [
// add wildcard allowed action here!
'site/*',
//'user/*',
//'debug/*',
//'mimin/*', // only in dev mode
],
],
'modules' => [
'mimin' => [
'class' => '\hscstudio\mimin\Module',
],
'gridview' =>[
'class' => 'kartik\grid\Module',
],
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
return $config;
<?php
namespace app\controllers;
use Yii;
use app\models\HasilVoting;
use app\models\HasilVotingSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use app\models\MVoting;
use app\models\TKandidat;
use yii\helpers\ArrayHelper;
use yii\data\ActiveDataProvider;
use app\models\User;
use app\models\TUser;
use yii\web\Response;
/**
* HasilVotingController implements the CRUD actions for HasilVoting model.
*/
class HasilVotingController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all HasilVoting models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new HasilVotingSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single HasilVoting model.
* @param integer $id_voting
* @param integer $id_user
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id_voting, $id_user)
{
return $this->render('view', [
'model' => $this->findModel($id_voting, $id_user),
]);
}
/**
* Creates a new HasilVoting model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new HasilVoting();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id_voting' => $model->id_voting, 'id_user' => $model->id_user]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing HasilVoting model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id_voting
* @param integer $id_user
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id_voting, $id_user)
{
$model = $this->findModel($id_voting, $id_user);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id_voting' => $model->id_voting, 'id_user' => $model->id_user]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing HasilVoting model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id_voting
* @param integer $id_user
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id_voting, $id_user)
{
$this->findModel($id_voting, $id_user)->delete();
return $this->redirect(['index']);
}
/**
* Finds the HasilVoting model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id_voting
* @param integer $id_user
* @return HasilVoting the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id_voting, $id_user)
{
if (($model = HasilVoting::findOne(['id_voting' => $id_voting, 'id_user' => $id_user])) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionOnlineVoting(){
$user = Yii::$app->user->identity;
$voting = MVoting::find()->where(['status_aktif'=>1])->one();
$hasil_voting = HasilVoting::find()->where(['id_voting' => $voting->id_voting])->andWhere(['id_user' =>$user->id])->one();
$arrayPilihan = ArrayHelper::map(TKandidat::find()->where(['id_voting'=>$voting->id_voting])->orderBy(['id_kandidat' => SORT_ASC])->all(),'id_kandidat','nama_kandidat');
$model = new HasilVoting();
if ($model->load(Yii::$app->request->post())) {
$model->id_voting = $voting->id_voting;
$model->id_user = $user->id;
$model->status_voting = 1;
$model->save();
if($model->save()){
$email = \Yii::$app->mailer->compose()
->setTo($user->email)
->setFrom(['gtconlinesystem@gmail.com' => 'Online Voting System'])
->setSubject('Informasi Pemberitahuan Voting')
->setHtmlBody('
<b>Terima Kasih Buat Partisipasi Anda Telah Melakukan Voting</b>
<br><br>
<b>Hasil Voting Akan Ditunjukkan Jika Periode Voting Telah Berakhir</b>')
->send();
if($email){
Yii::$app->session->setFlash('success', "Voting Berhasil Dilakukan, Informasi bahwa anda telah berhasil melakukan Voting dikirim ke Email Anda");
}
else{
Yii::$app->session->setFlash('success', "Terima Kasih, Voting Berhasil Dilakukan");
}
}else{
Yii::$app->getSession()->setFlash('danger','Maaf, Pilihan Anda Belum Berhasil Disimpan pada Online Voting');
}
return $this->redirect(['online-voting']);
}
return $this->render('online_voting', [
'model' => $model,
'arrayPilihan' => $arrayPilihan,
'hasil_voting' => $hasil_voting,
'voting' => $voting,
]);
}
public function actionHasilVoting($id_voting){
$query_hasil_voting = HasilVoting::find()->select(['id_voting','id_user','pilihan','COUNT(pilihan) AS Jumlah_Voting '])->where(['id_voting'=>$id_voting])->groupBy(['pilihan']);
$hasil_voting = $query_hasil_voting->asArray()->all();
$dataGrafik=[];
foreach ($hasil_voting as $key => $value) {
$kandidat = TKandidat::find()->where(['id_kandidat' => $value['pilihan']])->one();
$dataGrafik[] = [
'name' => $kandidat->nama_kandidat,
'y' => floatval($value['Jumlah_Voting']),
];
}
$voting = MVoting::find()->where(['id_voting'=>$id_voting])->one();
$dataProvider = new ActiveDataProvider([
'query' => $query_hasil_voting,
'pagination' => [
'pageSize' => 30,
],
'sort' => [
'defaultOrder' => [
'pilihan' => SORT_ASC,
]
],
]);
$arrayVoting = ArrayHelper::map(MVoting::find()->all(),'id_voting','nama_voting');
return $this->render('hasil_voting', [
'hasil_voting' => $hasil_voting,
'voting' => $voting,
'dataProvider' => $dataProvider,
'dataGrafik' => $dataGrafik,
'arrayVoting' => $arrayVoting,
]);
}
public function actionFilterHasilVoting($id_voting){
$query_hasil_voting = HasilVoting::find()->select(['id_voting','id_user','pilihan','COUNT(pilihan) AS Jumlah_Voting '])->where(['id_voting'=>$id_voting])->groupBy(['pilihan']);
$hasil_voting = $query_hasil_voting->asArray()->all();
$dataGrafik=[];
foreach ($hasil_voting as $key => $value) {
$kandidat = TKandidat::find()->where(['id_kandidat' => $value['pilihan']])->one();
$dataGrafik[] = [
'name' => $kandidat->nama_kandidat,
'y' => floatval($value['Jumlah_Voting']),
];
}
$voting = MVoting::find()->where(['id_voting'=>$id_voting])->one();
$arrayVoting = ArrayHelper::map(MVoting::find()->all(),'id_voting','nama_voting');
return $this->renderAjax('_renderHasilVoting', [
'hasil_voting' => $hasil_voting,
'voting' => $voting,
'dataGrafik' => $dataGrafik,
'arrayVoting' => $arrayVoting,
]);
}
public function actionResultVoting($id_voting){
$query_hasil_voting = HasilVoting::find()->select(['id_voting','id_user','pilihan','COUNT(pilihan) AS Jumlah_Voting '])->where(['id_voting'=>$id_voting])->groupBy(['pilihan']);
$hasil_voting = $query_hasil_voting->asArray()->all();
$dataGrafik=[];
foreach ($hasil_voting as $key => $value) {
$kandidat = TKandidat::find()->where(['id_kandidat' => $value['pilihan']])->one();
$dataGrafik[] = [
'name' => $kandidat->nama_kandidat,
'y' => floatval($value['Jumlah_Voting']),
];
}
Yii::$app->response->format = Response::FORMAT_JSON;
return $dataGrafik;
}
public function actionRekapitulasiPenggunaVoting($id_voting){
$query_pengguna_voting = HasilVoting::find()->where(['id_voting'=>$id_voting]);
//$hasil_voting = $query->asArray()->all();
$voting = MVoting::find()->where(['id_voting'=>$id_voting])->one();
/*$dataProvider = new ActiveDataProvider([
'query' => $query_pengguna_voting,
'pagination' => [
'pageSize' => 20,
],
'sort' => [
'defaultOrder' => [
'id_user' => SORT_ASC,
]
],
]);*/
$dataSudahVoting = HasilVoting::find()->where(['id_voting'=>$id_voting])->asArray()->all();
$arraySudahVoting = ArrayHelper::getColumn($dataSudahVoting,'id_user');
$query_pengguna_belum_voting = TUser::find()->join('JOIN','auth_assignment','t_user.id = auth_assignment.user_id')->where(['auth_assignment.item_name'=>'PESERTA_VOTING'])->andWhere(['NOT IN','t_user.id',$arraySudahVoting]);
//print_r($arraySudahVoting);die;
//print_r($query_pengguna_voting->asArray()->all());die;
$count_total_pengguna = TUser::find()->join('JOIN','auth_assignment','t_user.id = auth_assignment.user_id')->where(['auth_assignment.item_name'=>'PESERTA_VOTING'])->count();
$count_sudah_voting = HasilVoting::find()->where(['id_voting'=>$id_voting])->count();
$count_belum_voting = $count_total_pengguna - $count_sudah_voting;
$searchModel = new HasilVotingSearch();
$dataProvider = $searchModel->searchData($query_pengguna_voting,Yii::$app->request->queryParams);
$searchModel2 = new HasilVotingSearch();
$dataProvider2 = $searchModel2->searchData($query_pengguna_belum_voting,Yii::$app->request->queryParams);
return $this->render('rekapitulasi_pengguna_voting', [
//'hasil_voting' => $hasil_voting,
'voting' => $voting,
'dataProvider' => $dataProvider,
'dataProvider2' => $dataProvider2,
'count_total_pengguna' => $count_total_pengguna,
'count_sudah_voting' => $count_sudah_voting,
'count_belum_voting' => $count_belum_voting,
]);
}
}
<?php
namespace app\controllers;
use Yii;
use app\models\TKandidat;
use app\models\TKandidatSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* KandidatController implements the CRUD actions for TKandidat model.
*/
class KandidatController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all TKandidat models.
* @return mixed
*/
public function actionIndex($id_voting)
{
$model = TKandidat::find()->where(['id_voting' => $id_voting]);
$searchModel = new TKandidatSearch();
$dataProvider = $searchModel->searchData($model,Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single TKandidat model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->renderAjax('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new TKandidat model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($id_voting)
{
$model = new TKandidat();
if ($model->load(Yii::$app->request->post())) {
$model->id_voting = $id_voting;
$model->save();
return $this->redirect(['index','id_voting'=>$id_voting]);
}
return $this->renderAjax('create', [
'model' => $model,
]);
}
/**
* Updates an existing TKandidat model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index', 'id_voting' => $model->id_voting]);
}
return $this->renderAjax('update', [
'model' => $model,
]);
}
/**
* Deletes an existing TKandidat model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id,$id_voting)
{
$this->findModel($id)->delete();
return $this->redirect(['index','id_voting'=>$id_voting]);
}
/**
* Finds the TKandidat model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return TKandidat the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = TKandidat::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\Response;
use yii\filters\VerbFilter;
use yii\web\NotFoundHttpException;
use app\models\LoginForm;
use app\models\ContactForm;
use app\models\RegistrationForm;
use app\models\User;
use hscstudio\mimin\models\AuthAssignment;
use app\models\TUser;
class SiteController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
/**
* {@inheritdoc}
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
/**
* Displays homepage.
*
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
/**
* Login action.
*
* @return Response|string
*/
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
//return $this->goHome();
return $this->redirect(['site/index']);
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
//return $this->redirect(['site/index']);
}
$model->password = '';
return $this->render('login', [
'model' => $model,
]);
}
/**
* Logout action.
*
* @return Response
*/
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
/**
* Displays contact page.
*
* @return Response|string
*/
public function actionContact()
{
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
]);
}
/**
* Displays about page.
*
* @return string
*/
public function actionAbout()
{
return $this->render('about');
}
/*
Fungsi Register : Untuk menambahkan user baru
*/
public function actionRegister()
{
$model = new User();
$modelRole = new AuthAssignment();
if ($model->load(Yii::$app->request->post())) {
$password = $model->password_hash;
//print_r($password);die;
$model->setPassword($password);
$model->status = 10;
if ($model->save()) {
$user = TUser::find()->where(['username' => $model->username])->andWhere(['email'=>$model->email])->one();
$modelRole->item_name = "PESERTA_VOTING";
$modelRole->user_id = $user->id;
if($modelRole->save()){
Yii::$app->session->setFlash('success', 'Registrasi User Berhasil');
}else{
$user->delete();
Yii::$app->session->setFlash('danger', 'Mohon Maaf, Registrasi User Gagal');
}
} else {
Yii::$app->session->setFlash('danger', 'Mohon Maaf, Registrasi User Gagal');
}
return $this->redirect(['index']);
} else {
return $this->render('register_user', [
'model' => $model,
]);
}
}
}
<?php
namespace app\controllers;
use Yii;
use app\models\User;
use hscstudio\mimin\models\AuthAssignment;
use hscstudio\mimin\models\AuthItem;
use hscstudio\mimin\models\UserSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\helpers\ArrayHelper;
use yii\filters\AccessControl;
/**
* UserController implements the CRUD actions for User model.
*/
class UserController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all User models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single User model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$model = $this->findModel($id);
$authAssignments = AuthAssignment::find()->where([
'user_id' => $model->id,
])->column();
$authItems = ArrayHelper::map(
AuthItem::find()->where([
'type' => 1,
])->asArray()->all(),
'name', 'name');
$authAssignment = new AuthAssignment([
'user_id' => $model->id,
]);
if (Yii::$app->request->post()) {
$authAssignment->load(Yii::$app->request->post());
// delete all role
AuthAssignment::deleteAll(['user_id' => $model->id]);
if (is_array($authAssignment->item_name)) {
foreach ($authAssignment->item_name as $item) {
if (!in_array($item, $authAssignments)) {
$authAssignment2 = new AuthAssignment([
'user_id' => $model->id,
]);
$authAssignment2->item_name = $item;
$authAssignment2->created_at = time();
$authAssignment2->save();
$authAssignments = AuthAssignment::find()->where([
'user_id' => $model->id,
])->column();
}
}
}
Yii::$app->session->setFlash('success', 'Data tersimpan');
}
$authAssignment->item_name = $authAssignments;
return $this->render('view', [
'model' => $model,
'authAssignment' => $authAssignment,
'authItems' => $authItems,
]);
}
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new User();
if ($model->load(Yii::$app->request->post())) {
$model->setPassword('123456');
$model->status = $model->status==1?10:0;
if ($model->save()) {
Yii::$app->session->setFlash('success', 'User berhasil dibuat dengan password 123456');
} else {
Yii::$app->session->setFlash('error', 'User gagal dibuat');
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing User model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if (!empty($model->new_password)) {
$model->setPassword($model->new_password);
}
$model->status = $model->status==1?10:0;
if ($model->save()) {
Yii::$app->session->setFlash('success', 'User berhasil diupdate');
} else {
Yii::$app->session->setFlash('error', 'User gagal diupdate');
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
$model->status = $model->status==10?1:0;
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing User model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
$authAssignments = AuthAssignment::find()->where([
'user_id' => $model->id,
])->all();
foreach ($authAssignments as $authAssignment) {
$authAssignment->delete();
}
Yii::$app->session->setFlash('success', 'Delete success');
$model->delete();
return $this->redirect(['index']);
}
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = User::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace app\controllers;
use Yii;
use app\models\MVoting;
use app\models\MVotingSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* MVotingController implements the CRUD actions for MVoting model.
*/
class VotingController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all MVoting models.
* @return mixed
*/
public function actionIndex()
{
//$model_voting = MVoting::find()->all();//"Select * from m_voting";
$searchModel = new MVotingSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
//'model_voting' => $model_voting,
]);
}
/**
* Displays a single MVoting model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->renderAjax('view', [
'model' => $this->findModel($id),
]);
}
public function actionViewdata(){
return $this->render('view_data', [
]);
}
/**
* Creates a new MVoting model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new MVoting();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$email = \Yii::$app->mailer->compose()
->setFrom(['gtconlinesystem@gmail.com'=>'Online Voting System'])
->setTo('goklasif10029@gmail.com')
->setSubject('Informasi Pemberitahuan Voting')
->setHtmlBody('
<b>Terima Kasih Buat Partisipasi Anda Telah Melakukan Voting</b>
<br><br>
<b>Hasil Voting Akan Ditunjukkan Jika Periode Voting Telah Berakhir</b>')
->send();
if($email){
Yii::$app->session->setFlash('success', "Voting Berhasil Dilakukan, Informasi bahwa anda telah berhasil melakukan Voting dikirim ke Email Anda");
}
else{
Yii::$app->session->setFlash('warning', "Voting Gagal Dilakukan, Silahkan Coba Kembali");
}
return $this->redirect(['index']);
}
return $this->renderAjax('create', [
'model' => $model,
]);
}
/**
* Updates an existing MVoting model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
}
return $this->renderAjax('update', [
'model' => $model,
]);
}
/**
* Deletes an existing MVoting model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the MVoting model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return MVoting the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = MVoting::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionIndexHasilVoting()
{
$searchModel = new MVotingSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index_hasil_voting', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
public function actionIndexPenggunaVoting()
{
$searchModel = new MVotingSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index_pengguna_voting', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment