Commit 5d07a369 by henny flora panjaitan

PROYEK PSWII FINAL

parent ad3d9a5b
{
"directory" : "vendor/bower-asset"
}
# phpstorm project files
.idea
# netbeans project files
nbproject
# zend studio for eclipse project files
.buildpath
.project
.settings
# windows thumbnail cache
Thumbs.db
# composer vendor dir
/vendor
# composer itself is not needed
composer.phar
# Mac DS_Store Files
.DS_Store
# phpunit itself is not needed
phpunit.phar
# local phpunit config
/phpunit.xml
tests/_output/*
tests/_support/_generated
#vagrant folder
/.vagrant
\ No newline at end of file
Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Yii Software LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
<p align="center">
<a href="https://github.com/yiisoft" target="_blank">
<img src="https://avatars0.githubusercontent.com/u/993323" height="100px">
</a>
<h1 align="center">Yii 2 Basic Project Template</h1>
<br>
</p>
Yii 2 Basic Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for
rapidly creating small projects.
The template contains the basic features including user login/logout and a contact page.
It includes all commonly used configurations that would allow you to focus on adding new
features to your application.
[![Latest Stable Version](https://img.shields.io/packagist/v/yiisoft/yii2-app-basic.svg)](https://packagist.org/packages/yiisoft/yii2-app-basic)
[![Total Downloads](https://img.shields.io/packagist/dt/yiisoft/yii2-app-basic.svg)](https://packagist.org/packages/yiisoft/yii2-app-basic)
[![Build Status](https://travis-ci.com/yiisoft/yii2-app-basic.svg?branch=master)](https://travis-ci.com/yiisoft/yii2-app-basic)
DIRECTORY STRUCTURE
-------------------
assets/ contains assets definition
commands/ contains console commands (controllers)
config/ contains application configurations
controllers/ contains Web controller classes
mail/ contains view files for e-mails
models/ contains model classes
runtime/ contains files generated during runtime
tests/ contains various tests for the basic application
vendor/ contains dependent 3rd-party packages
views/ contains view files for the Web application
web/ contains the entry script and Web resources
REQUIREMENTS
------------
The minimum requirement by this project template that your Web server supports PHP 5.6.0.
INSTALLATION
------------
### Install via Composer
If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions
at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).
You can then install this project template using the following command:
~~~
composer create-project --prefer-dist yiisoft/yii2-app-basic basic
~~~
Now you should be able to access the application through the following URL, assuming `basic` is the directory
directly under the Web root.
~~~
http://localhost/basic/web/
~~~
### Install from an Archive File
Extract the archive file downloaded from [yiiframework.com](http://www.yiiframework.com/download/) to
a directory named `basic` that is directly under the Web root.
Set cookie validation key in `config/web.php` file to some random secret string:
```php
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '<secret random string goes here>',
],
```
You can then access the application through the following URL:
~~~
http://localhost/basic/web/
~~~
### Install with Docker
Update your vendor packages
docker-compose run --rm php composer update --prefer-dist
Run the installation triggers (creating cookie validation code)
docker-compose run --rm php composer install
Start the container
docker-compose up -d
You can then access the application through the following URL:
http://127.0.0.1:8000
**NOTES:**
- Minimum required Docker engine version `17.04` for development (see [Performance tuning for volume mounts](https://docs.docker.com/docker-for-mac/osxfs-caching/))
- The default configuration uses a host-volume in your home directory `.docker-composer` for composer caches
CONFIGURATION
-------------
### Database
Edit the file `config/db.php` with real data, for example:
```php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2basic',
'username' => 'root',
'password' => '1234',
'charset' => 'utf8',
];
```
**NOTES:**
- Yii won't create the database for you, this has to be done manually before you can access it.
- Check and edit the other files in the `config/` directory to customize your application as required.
- Refer to the README in the `tests` directory for information specific to basic application tests.
TESTING
-------
Tests are located in `tests` directory. They are developed with [Codeception PHP Testing Framework](http://codeception.com/).
By default there are 3 test suites:
- `unit`
- `functional`
- `acceptance`
Tests can be executed by running
```
vendor/bin/codecept run
```
The command above will execute unit and functional tests. Unit tests are testing the system components, while functional
tests are for testing user interaction. Acceptance tests are disabled by default as they require additional setup since
they perform testing in real browser.
### Running acceptance tests
To execute acceptance tests do the following:
1. Rename `tests/acceptance.suite.yml.example` to `tests/acceptance.suite.yml` to enable suite configuration
2. Replace `codeception/base` package in `composer.json` with `codeception/codeception` to install full featured
version of Codeception
3. Update dependencies with Composer
```
composer update
```
4. Download [Selenium Server](http://www.seleniumhq.org/download/) and launch it:
```
java -jar ~/selenium-server-standalone-x.xx.x.jar
```
In case of using Selenium Server 3.0 with Firefox browser since v48 or Google Chrome since v53 you must download [GeckoDriver](https://github.com/mozilla/geckodriver/releases) or [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/downloads) and launch Selenium with it:
```
# for Firefox
java -jar -Dwebdriver.gecko.driver=~/geckodriver ~/selenium-server-standalone-3.xx.x.jar
# for Google Chrome
java -jar -Dwebdriver.chrome.driver=~/chromedriver ~/selenium-server-standalone-3.xx.x.jar
```
As an alternative way you can use already configured Docker container with older versions of Selenium and Firefox:
```
docker run --net=host selenium/standalone-firefox:2.53.0
```
5. (Optional) Create `yii2_basic_tests` database and update it by applying migrations if you have them.
```
tests/bin/yii migrate
```
The database configuration can be found at `config/test_db.php`.
6. Start web server:
```
tests/bin/yii serve
```
7. Now you can run all available tests
```
# run all available tests
vendor/bin/codecept run
# run acceptance tests
vendor/bin/codecept run acceptance
# run only unit and functional tests
vendor/bin/codecept run unit,functional
```
### Code coverage support
By default, code coverage is disabled in `codeception.yml` configuration file, you should uncomment needed rows to be able
to collect code coverage. You can run your tests and collect coverage with the following command:
```
#collect coverage for all tests
vendor/bin/codecept run -- --coverage-html --coverage-xml
#collect coverage only for unit tests
vendor/bin/codecept run unit -- --coverage-html --coverage-xml
#collect coverage for unit and functional tests
vendor/bin/codecept run functional,unit -- --coverage-html --coverage-xml
```
You can see code coverage output under the `tests/_output` directory.
require 'yaml'
require 'fileutils'
required_plugins = %w( vagrant-hostmanager vagrant-vbguest )
required_plugins.each do |plugin|
exec "vagrant plugin install #{plugin}" unless Vagrant.has_plugin? plugin
end
domains = {
app: 'yii2basic.test'
}
vagrantfile_dir_path = File.dirname(__FILE__)
config = {
local: vagrantfile_dir_path + '/vagrant/config/vagrant-local.yml',
example: vagrantfile_dir_path + '/vagrant/config/vagrant-local.example.yml'
}
# copy config from example if local config not exists
FileUtils.cp config[:example], config[:local] unless File.exist?(config[:local])
# read config
options = YAML.load_file config[:local]
# check github token
if options['github_token'].nil? || options['github_token'].to_s.length != 40
puts "You must place REAL GitHub token into configuration:\n/yii2-app-basic/vagrant/config/vagrant-local.yml"
exit
end
# vagrant configurate
Vagrant.configure(2) do |config|
# select the box
config.vm.box = 'bento/ubuntu-16.04'
# should we ask about box updates?
config.vm.box_check_update = options['box_check_update']
config.vm.provider 'virtualbox' do |vb|
# machine cpus count
vb.cpus = options['cpus']
# machine memory size
vb.memory = options['memory']
# machine name (for VirtualBox UI)
vb.name = options['machine_name']
end
# machine name (for vagrant console)
config.vm.define options['machine_name']
# machine name (for guest machine console)
config.vm.hostname = options['machine_name']
# network settings
config.vm.network 'private_network', ip: options['ip']
# sync: folder 'yii2-app-advanced' (host machine) -> folder '/app' (guest machine)
config.vm.synced_folder './', '/app', owner: 'vagrant', group: 'vagrant'
# disable folder '/vagrant' (guest machine)
config.vm.synced_folder '.', '/vagrant', disabled: true
# hosts settings (host machine)
config.vm.provision :hostmanager
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
config.hostmanager.aliases = domains.values
# quick fix for failed guest additions installations
# config.vbguest.auto_update = false
# provisioners
config.vm.provision 'shell', path: './vagrant/provision/once-as-root.sh', args: [options['timezone']]
config.vm.provision 'shell', path: './vagrant/provision/once-as-vagrant.sh', args: [options['github_token']], privileged: false
config.vm.provision 'shell', path: './vagrant/provision/always-as-root.sh', run: 'always'
# post-install message (vagrant console)
config.vm.post_up_message = "App URL: http://#{domains[:app]}"
end
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace app\assets;
use yii\web\AssetBundle;
/**
* Main application asset bundle.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
actor: Tester
bootstrap: _bootstrap.php
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
memory_limit: 1024M
colors: true
modules:
config:
Yii2:
configFile: 'config/test.php'
# To enable code coverage:
#coverage:
# #c3_url: http://localhost:8080/index-test.php/
# enabled: true
# #remote: true
# #remote_config: '../codeception.yml'
# whitelist:
# include:
# - models/*
# - controllers/*
# - commands/*
# - mail/*
# blacklist:
# include:
# - assets/*
# - config/*
# - runtime/*
# - vendor/*
# - views/*
# - web/*
# - tests/*
<?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;
}
}
{
"name": "yiisoft/yii2-app-basic",
"description": "Yii 2 Basic Project Template",
"keywords": ["yii2", "framework", "basic", "project template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "stable",
"require": {
"php": ">=5.6.0",
"yiisoft/yii2": "~2.0.14",
"yiisoft/yii2-bootstrap": "~2.0.0",
"yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0",
"hscstudio/yii2-mimin": "~1.1.5",
"miloschuman/yii2-highcharts-widget": "^7.1",
"kartik-v/yii2-grid": "@dev",
"kartik-v/yii2-mpdf": "dev-master"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.1.0",
"yiisoft/yii2-gii": "~2.1.0",
"yiisoft/yii2-faker": "~2.0.0",
"codeception/codeception": "^4.0",
"codeception/verify": "~0.5.0 || ~1.1.0",
"codeception/specify": "~0.4.6",
"symfony/browser-kit": ">=2.7 <=4.2.4",
"codeception/module-filesystem": "^1.0.0",
"codeception/module-yii2": "^1.0.0",
"codeception/module-asserts": "^1.0.0"
},
"config": {
"process-timeout": 1800,
"fxp-asset": {
"enabled": false
}
},
"scripts": {
"post-install-cmd": [
"yii\\composer\\Installer::postInstall"
],
"post-create-project-cmd": [
"yii\\composer\\Installer::postCreateProject",
"yii\\composer\\Installer::postInstall"
]
},
"extra": {
"yii\\composer\\Installer::postCreateProject": {
"setPermission": [
{
"runtime": "0777",
"web/assets": "0777",
"yii": "0755"
}
]
},
"yii\\composer\\Installer::postInstall": {
"generateCookieValidationKey": [
"config/web.php"
]
}
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?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\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,
]);
}
}
version: '2'
services:
php:
image: yiisoftware/yii2-php:7.1-apache
volumes:
- ~/.composer-docker/cache:/root/.composer/cache:delegated
- ./:/app:delegated
ports:
- '8000:80'
\ No newline at end of file
<?php
use yii\helpers\Html;
/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\MessageInterface the message being composed */
/* @var $content string main view render result */
?>
<?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<?= $content ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
<?php
namespace app\models;
use Yii;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
/**
* This is the model class for table "akun".
*
* @property int $id
* @property string $username
* @property string $password
* @property string $last_login
*/
class Account extends \yii\db\ActiveRecord implements IdentityInterface
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 't_user';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['username', 'password'], 'required'],
//[['last_login'], 'safe'],
[['username', 'password'], 'string', 'max' => 255],
/*[['fullname'], 'string', 'max' => 150],
[['role'], 'string', 'max' => 25],*/
/*[['auth_key'], 'safe'],*/
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'username' => 'Username',
'password' => 'Password',
];
}
public static function findByUsername($username)
{
return static::findOne(['username' => $username]);
}
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password);
}
public static function findIdentity($id)
{
return static::findOne(['id' => $id]);
}
public static function findIdentityByAccessToken($token, $type = null)
{
//throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
return static::findOne(['acccess_token' => $token]);
}
public function getId()
{
//return $this->getPrimaryKey();
return $this->id;
}
public function getAuthKey()
{
return $this->auth_key;
}
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
}
<?php
namespace app\models;
use Yii;
use yii\base\Model;
/**
* ContactForm is the model behind the contact form.
*/
class ContactForm extends Model
{
public $name;
public $email;
public $subject;
public $body;
public $verifyCode;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// name, email, subject and body are required
[['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address
['email', 'email'],
// verifyCode needs to be entered correctly
['verifyCode', 'captcha'],
];
}
/**
* @return array customized attribute labels
*/
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
];
}
/**
* Sends an email to the specified email address using the information collected by this model.
* @param string $email the target email address
* @return bool whether the model passes validation
*/
public function contact($email)
{
if ($this->validate()) {
Yii::$app->mailer->compose()
->setTo($email)
->setFrom([Yii::$app->params['senderEmail'] => Yii::$app->params['senderName']])
->setReplyTo([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
return true;
}
return false;
}
}
<?php
namespace app\models;
use Yii;
use yii\db\ActiveRecord;
use yii\db\Expression;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "hasil_voting".
*
* @property int $id_voting
* @property int $id_user
* @property int $pilihan
* @property int $status_voting
* @property string|null $created_at
* @property int|null $created_by
* @property string|null $updated_at
* @property int|null $updated_by
* @property int|null $active
*
* @property TUser $user
* @property MVoting $voting
*/
class HasilVoting extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'hasil_voting';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id_voting', 'id_user', 'pilihan', 'status_voting'], 'required'],
[['id_voting', 'id_user', 'pilihan', 'status_voting', 'created_by', 'updated_by', 'active'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['id_voting', 'id_user'], 'unique', 'targetAttribute' => ['id_voting', 'id_user']],
[['id_user'], 'exist', 'skipOnError' => true, 'targetClass' => TUser::className(), 'targetAttribute' => ['id_user' => 'id']],
[['id_voting'], 'exist', 'skipOnError' => true, 'targetClass' => MVoting::className(), 'targetAttribute' => ['id_voting' => 'id_voting']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id_voting' => 'Id Voting',
'id_user' => 'Id User',
'pilihan' => 'Pilihan',
'status_voting' => 'Status Voting',
'created_at' => 'Created At',
'created_by' => 'Created By',
'updated_at' => 'Updated At',
'updated_by' => 'Updated By',
'active' => 'Active',
];
}
public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at',
],
'value' => new Expression('NOW()'),
],
];
}
public function beforeSave($insert)
{
if (!parent::beforeSave($insert)) {
return false;
}
if(ActiveRecord::EVENT_BEFORE_INSERT){
$this->created_by = Yii::$app->user->identity->id;
$this->updated_by = Yii::$app->user->identity->id;
}else if(ActiveRecord::EVENT_BEFORE_UPDATE){
$this->updated_by = Yii::$app->user->identity->id;
}
return true;
}
/**
* Gets query for [[User]].
*
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasOne(TUser::className(), ['id' => 'id_user']);
}
/**
* Gets query for [[Voting]].
*
* @return \yii\db\ActiveQuery
*/
public function getVoting()
{
return $this->hasOne(MVoting::className(), ['id_voting' => 'id_voting']);
}
}
<?php
namespace app\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\HasilVoting;
/**
* HasilVotingSearch represents the model behind the search form of `app\models\HasilVoting`.
*/
class HasilVotingSearch extends HasilVoting
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id_voting', 'id_user', 'pilihan', 'status_voting', 'created_by', 'updated_by', 'active'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = HasilVoting::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id_voting' => $this->id_voting,
'id_user' => $this->id_user,
'pilihan' => $this->pilihan,
'status_voting' => $this->status_voting,
'created_at' => $this->created_at,
'created_by' => $this->created_by,
'updated_at' => $this->updated_at,
'updated_by' => $this->updated_by,
'active' => $this->active,
]);
return $dataProvider;
}
public function searchData($model,$params)
{
$query = $model;
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id_voting' => $this->id_voting,
'id_user' => $this->id_user,
'pilihan' => $this->pilihan,
'status_voting' => $this->status_voting,
'created_at' => $this->created_at,
'created_by' => $this->created_by,
'updated_at' => $this->updated_at,
'updated_by' => $this->updated_by,
'active' => $this->active,
]);
return $dataProvider;
}
}
<?php
namespace app\models;
use Yii;
use yii\base\Model;
/**
* LoginForm is the model behind the login form.
*
* @property User|null $user This property is read-only.
*
*/
class LoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
private $_user = false;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, 'Incorrect username or password.');
}
}
}
/**
* Logs in a user using the provided username and password.
* @return bool whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 : 0);
}
return false;
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
}
<?php
namespace app\models;
use Yii;
use yii\db\ActiveRecord;
use yii\db\Expression;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "m_voting".
*
* @property int $id_voting
* @property string|null $nama_voting
* @property string|null $periode_awal
* @property string|null $periode_tutup
*
* @property HasilVoting[] $hasilVotings
* @property TUser[] $users
* @property TKandidat[] $tKandidats
*/
class MVoting extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'm_voting';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['periode_awal', 'periode_tutup','status_aktif','nama_voting'], 'required'],
[['periode_awal', 'periode_tutup','created_at','updated_at'], 'safe'],
[['status_aktif','created_by','updated_by'], 'integer'],
[['nama_voting'], 'string', 'max' => 500],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id_voting' => 'Id Voting',
'nama_voting' => 'Deskripsi',
'periode_awal' => 'Tanggal Mulai Voting',
'periode_tutup' => 'Tanggal Akhir Voting',
'status_aktif' => 'Status Voting',
];
}
public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at',
],
'value' => new Expression('NOW()'),
],
];
}
public function beforeSave($insert)
{
if (!parent::beforeSave($insert)) {
return false;
}
if(ActiveRecord::EVENT_BEFORE_INSERT){
$this->created_by = Yii::$app->user->identity->id;
$this->updated_by = Yii::$app->user->identity->id;
}else if(ActiveRecord::EVENT_BEFORE_UPDATE){
$this->updated_by = Yii::$app->user->identity->id;
}
return true;
}
/**
* Gets query for [[HasilVotings]].
*
* @return \yii\db\ActiveQuery
*/
public function getHasilVotings()
{
return $this->hasMany(HasilVoting::className(), ['id_voting' => 'id_voting']);
}
/**
* Gets query for [[Users]].
*
* @return \yii\db\ActiveQuery
*/
public function getUsers()
{
return $this->hasMany(TUser::className(), ['id' => 'id_user'])->viaTable('hasil_voting', ['id_voting' => 'id_voting']);
}
/**
* Gets query for [[TKandidats]].
*
* @return \yii\db\ActiveQuery
*/
public function getTKandidats()
{
return $this->hasMany(TKandidat::className(), ['id_voting' => 'id_voting']);
}
}
<?php
namespace app\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\MVoting;
/**
* MVotingSearch represents the model behind the search form of `app\models\MVoting`.
*/
class MVotingSearch extends MVoting
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id_voting'], 'integer'],
[['nama_voting', 'periode_awal', 'periode_tutup'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = MVoting::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id_voting' => $this->id_voting,
'periode_awal' => $this->periode_awal,
'periode_tutup' => $this->periode_tutup,
]);
$query->andFilterWhere(['like', 'nama_voting', $this->nama_voting]);
return $dataProvider;
}
}
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use app\models\User;
/**
* LoginForm is the model behind the login form.
*
* @property User|null $user This property is read-only.
*
*/
class RegistrationForm extends Model
{
public $fullname;
public $role;
public $username;
public $password;
private $_user = false;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password','fullname','role'], 'required'],
[['username', 'password'], 'required','on' => 'register'],
[['fullname', 'role'], 'required','on' => 'register'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, 'Incorrect username or password.');
}
}
}
public function scenarios(){
$scenarios = parent::scenarios();
$scenarios['register'] = ['username','password','fullname','role','last_login'];
return $scenarios;
}
public function attributeLabels()
{
return [
'id' => 'ID',
'username' => 'Username',
'password' => 'Password',
'last_login' => 'Last Login',
'role' => 'Role',
'fullname' => 'Full Name',
];
}
public static function hashPassword($_password){
return (Yii::$app->getSecurity()->generatePasswordHash($_password));
}
public function generateAuthKey()
{
return Yii::$app->security->generateRandomString();
}
public function register(){
if ($this->validate()) {
$account = new Account();
$account->username = $this->username;
$account->password = self::hashPassword($this->password);
$account->fullname = $this->fullname;
$account->role = $this->role;
$account->auth_key = self::generateAuthKey();
if($account->save()){
return $account;
}else{
print_r($account->errors);
}
return false;
}
}
/**
* Logs in a user using the provided username and password.
* @return bool whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 : 0);
}
return false;
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
}
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "t_kandidat".
*
* @property int $id_kandidat
* @property string $nama_kandidat
* @property int $id_voting
*
* @property MVoting $voting
*/
class TKandidat extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 't_kandidat';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['nama_kandidat', 'id_voting'], 'required'],
[['id_voting'], 'integer'],
[['nama_kandidat'], 'string', 'max' => 500],
[['id_voting'], 'exist', 'skipOnError' => true, 'targetClass' => MVoting::className(), 'targetAttribute' => ['id_voting' => 'id_voting']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id_kandidat' => 'Id Kandidat',
'nama_kandidat' => 'Nama Kandidat',
'id_voting' => 'Id Voting',
];
}
/**
* Gets query for [[Voting]].
*
* @return \yii\db\ActiveQuery
*/
public function getVoting()
{
return $this->hasOne(MVoting::className(), ['id_voting' => 'id_voting']);
}
}
<?php
namespace app\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\TKandidat;
/**
* TKandidatSearch represents the model behind the search form of `app\models\TKandidat`.
*/
class TKandidatSearch extends TKandidat
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id_kandidat', 'id_voting'], 'integer'],
[['nama_kandidat'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = TKandidat::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id_kandidat' => $this->id_kandidat,
'id_voting' => $this->id_voting,
]);
$query->andFilterWhere(['like', 'nama_kandidat', $this->nama_kandidat]);
return $dataProvider;
}
public function searchData($model,$params)
{
$query = $model;
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id_kandidat' => $this->id_kandidat,
'id_voting' => $this->id_voting,
]);
$query->andFilterWhere(['like', 'nama_kandidat', $this->nama_kandidat]);
return $dataProvider;
}
}
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "t_user".
*
* @property int $id
* @property string $username
* @property string|null $auth_key
* @property string $password_hash
* @property string|null $password_reset_token
* @property string $email
* @property int $status
* @property int $created_at
* @property int $updated_at
* @property string|null $id_lokasi
* @property string|null $inisial_user
* @property string|null $nama_user
* @property string|null $telp
* @property string|null $foto
* @property string|null $alamat
*
* @property HasilVoting[] $hasilVotings
* @property MVoting[] $votings
*/
class TUser extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 't_user';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['username', 'password_hash', 'email', 'created_at', 'updated_at'], 'required'],
[['status', 'created_at', 'updated_at'], 'integer'],
[['username', 'auth_key', 'password_hash', 'password_reset_token', 'email', 'id_lokasi', 'inisial_user', 'nama_user', 'telp', 'foto'], 'string', 'max' => 255],
[['alamat'], 'string', 'max' => 500],
[['username'], 'unique'],
[['email'], 'unique'],
[['password_reset_token'], 'unique'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'username' => 'Username',
'auth_key' => 'Auth Key',
'password_hash' => 'Password Hash',
'password_reset_token' => 'Password Reset Token',
'email' => 'Email',
'status' => 'Status',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
'id_lokasi' => 'Id Lokasi',
'inisial_user' => 'Inisial User',
'nama_user' => 'Nama Pengguna',
'telp' => 'Telp',
'foto' => 'Foto',
'alamat' => 'Alamat',
];
}
/**
* Gets query for [[HasilVotings]].
*
* @return \yii\db\ActiveQuery
*/
public function getHasilVotings()
{
return $this->hasMany(HasilVoting::className(), ['id_user' => 'id']);
}
/**
* Gets query for [[Votings]].
*
* @return \yii\db\ActiveQuery
*/
public function getVotings()
{
return $this->hasMany(MVoting::className(), ['id_voting' => 'id_voting'])->viaTable('hasil_voting', ['id_user' => 'id']);
}
}
<?php
namespace app\models;
use Yii;
use yii\db\Expression;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
//use hscstudio\mimin\components\Mimin;
/**
* This is the model class for table "user".
*
* @property integer $id
* @property string $username
* @property string $auth_key
* @property string $password_hash
* @property string $password_reset_token
* @property string $email
* @property integer $role
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
*/
class User extends ActiveRecord implements IdentityInterface
{
const STATUS_ACTIVE = 10;
const STATUS_NON_ACTIVE = 20;
// const ROLE_ADMIN = 10;
/**
* @inheritdoc
*/
public static function tableName()
{
return 't_user';
}
public function behaviors()
{
return [
TimeStampBehavior::className(),
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'email','nama_user','status','password_hash'], 'required'],
[['username', 'email'], 'filter', 'filter' => 'trim'],
[['username', 'email'], 'unique'],
['status', 'default', 'value' => self::STATUS_ACTIVE],
// ['role', 'default', 'value' => self::ROLE_ADMIN],
['email', 'email'],
[['username','nama_user','password_hash'], 'string', 'min' => 2, 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'username' => 'Username',
'auth_key' => 'Auth Key',
//'plainPassword' => 'Password',
'password_hash' => 'Password',
'password_reset_token' => 'Password Reset Token',
'email' => 'Email',
//'role' => 'Role',
'status' => 'Status',
'created_at' => 'Ditambahkan Pada',
'updated_at' => 'Diupdate Pada',
'nama_user' => 'Nama Lengkap Pengguna',
];
}
public function getStatusOptions()
{
return [
self::STATUS_ACTIVE => 'Active',
self::STATUS_NON_ACTIVE => 'Non Active',
];
}
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $type = null)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
}
public static function findByEmail($email)
{
return static::findOne(['email' => $email, 'status' => self::STATUS_ACTIVE]);
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
if (!static::isPasswordResetTokenValid($token)) {
return null;
}
return static::findOne([
'password_reset_token' => $token,
'status' => self::STATUS_ACTIVE,
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return boolean
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return false;
}
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
$parts = explode('_', $token);
$timestamp = (int) end($parts);
return $timestamp + $expire >= time();
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* @inheritdoc
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return boolean if password provided is valid for current user
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = null;
}
}
panduan berikut berisi tahapan untuk instalasi Online voting system:
Online voting system masih berjalan pada localhost.
1. Sudah menginstal xampp versi 3.2.2 atau php versi 7 sebelumnya
2. Letakkan folder Online voting pada direktori C://xampp/htdocs/
3. Insert database rating pada phpmyadmin dengan cara sebagai berikut:
- Buka phpmyadmin
- Klik link import
- Kemudian akan muncul halaman untuk upload file. Klik browse ...
- Cari dan pilih file db_online_voting.sql, kemudian klik go
- Jika berhasil database rating akan muncul di list database phpmyadmin
4. Jalankan Online voting system di browser dengan url: localhost8080:/online_voting/web/index.php
5. Login sebagai admin dengan username: admin, password: admin2020
6. Login ke gmail menggunakan akun email : gtconlinesystem@gmail.com dan password : GtcKey@2019OK!
agar fitur send email dapat terkirim karena dibutuhkan akun email pengirim untuk mengirim notifikasi kepada peserta voting
dan juga harus terhubung ke internet agar email dapat dikirim.
7. Untuk dapat login sebagai user, maka user harus daftar terlebih dahulu dengan klik link daftar.
8. Untuk informasi selengkapnya dapat membuka menu informasi pada Online voting system.
9. Apabila masih membutuhkan informasi dapat menghubungi henny flora panjaitan (if319040@students.del.ac.id)
selaku project manajer dalam kelompok 6 PSWII.
<?php
/**
* Application requirement checker script.
*
* In order to run this script use the following console command:
* php requirements.php
*
* In order to run this script from the web, you should copy it to the web root.
* If you are using Linux you can create a hard link instead, using the following command:
* ln ../requirements.php requirements.php
*/
// you may need to adjust this path to the correct Yii framework path
// uncomment and adjust the following line if Yii is not located at the default path
//$frameworkPath = dirname(__FILE__) . '/vendor/yiisoft/yii2';
if (!isset($frameworkPath)) {
$searchPaths = array(
dirname(__FILE__) . '/vendor/yiisoft/yii2',
dirname(__FILE__) . '/../vendor/yiisoft/yii2',
);
foreach ($searchPaths as $path) {
if (is_dir($path)) {
$frameworkPath = $path;
break;
}
}
}
if (!isset($frameworkPath) || !is_dir($frameworkPath)) {
$message = "<h1>Error</h1>\n\n"
. "<p><strong>The path to yii framework seems to be incorrect.</strong></p>\n"
. '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) . "</abbr>.</p>\n"
. '<p>Please refer to the <abbr title="' . dirname(__FILE__) . "/README.md\">README</abbr> on how to install Yii.</p>\n";
if (!empty($_SERVER['argv'])) {
// do not print HTML when used in console mode
echo strip_tags($message);
} else {
echo $message;
}
exit(1);
}
require_once($frameworkPath . '/requirements/YiiRequirementChecker.php');
$requirementsChecker = new YiiRequirementChecker();
$gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.';
$gdOK = $imagickOK = false;
if (extension_loaded('imagick')) {
$imagick = new Imagick();
$imagickFormats = $imagick->queryFormats('PNG');
if (in_array('PNG', $imagickFormats)) {
$imagickOK = true;
} else {
$imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.';
}
}
if (extension_loaded('gd')) {
$gdInfo = gd_info();
if (!empty($gdInfo['FreeType Support'])) {
$gdOK = true;
} else {
$gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.';
}
}
/**
* Adjust requirements according to your application specifics.
*/
$requirements = array(
// Database :
array(
'name' => 'PDO extension',
'mandatory' => true,
'condition' => extension_loaded('pdo'),
'by' => 'All DB-related classes',
),
array(
'name' => 'PDO SQLite extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_sqlite'),
'by' => 'All DB-related classes',
'memo' => 'Required for SQLite database.',
),
array(
'name' => 'PDO MySQL extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_mysql'),
'by' => 'All DB-related classes',
'memo' => 'Required for MySQL database.',
),
array(
'name' => 'PDO PostgreSQL extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_pgsql'),
'by' => 'All DB-related classes',
'memo' => 'Required for PostgreSQL database.',
),
// Cache :
array(
'name' => 'Memcache extension',
'mandatory' => false,
'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-memcache.html">MemCache</a>',
'memo' => extension_loaded('memcached') ? 'To use memcached set <a href="http://www.yiiframework.com/doc-2.0/yii-caching-memcache.html#$useMemcached-detail">MemCache::useMemcached</a> to <code>true</code>.' : ''
),
// CAPTCHA:
array(
'name' => 'GD PHP extension with FreeType support',
'mandatory' => false,
'condition' => $gdOK,
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
'memo' => $gdMemo,
),
array(
'name' => 'ImageMagick PHP extension with PNG support',
'mandatory' => false,
'condition' => $imagickOK,
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
'memo' => $imagickMemo,
),
// PHP ini :
'phpExposePhp' => array(
'name' => 'Expose PHP',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
'by' => 'Security reasons',
'memo' => '"expose_php" should be disabled at php.ini',
),
'phpAllowUrlInclude' => array(
'name' => 'PHP allow url include',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
'by' => 'Security reasons',
'memo' => '"allow_url_include" should be disabled at php.ini',
),
'phpSmtp' => array(
'name' => 'PHP mail SMTP',
'mandatory' => false,
'condition' => strlen(ini_get('SMTP')) > 0,
'by' => 'Email sending',
'memo' => 'PHP mail SMTP server required',
),
);
// OPcache check
if (!version_compare(phpversion(), '5.5', '>=')) {
$requirements[] = array(
'name' => 'APC extension',
'mandatory' => false,
'condition' => extension_loaded('apc'),
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-apccache.html">ApcCache</a>',
);
}
$result = $requirementsChecker->checkYii()->check($requirements)->getResult();
$requirementsChecker->render();
exit($result['summary']['errors'] === 0 ? 0 : 1);
*
!.gitignore
\ No newline at end of file
<?php
define('YII_ENV', 'test');
defined('YII_DEBUG') or define('YII_DEBUG', true);
require_once __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
require __DIR__ .'/../vendor/autoload.php';
\ No newline at end of file
*
!.gitignore
\ No newline at end of file
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
/**
* Define custom actions here
*/
}
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
}
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://127.0.0.1:8080/
browser: firefox
- Yii2:
part: orm
entryScript: index-test.php
cleanup: false
<?php
use yii\helpers\Url;
class AboutCest
{
public function ensureThatAboutWorks(AcceptanceTester $I)
{
$I->amOnPage(Url::toRoute('/site/about'));
$I->see('About', 'h1');
}
}
<?php
use yii\helpers\Url;
class ContactCest
{
public function _before(\AcceptanceTester $I)
{
$I->amOnPage(Url::toRoute('/site/contact'));
}
public function contactPageWorks(AcceptanceTester $I)
{
$I->wantTo('ensure that contact page works');
$I->see('Contact', 'h1');
}
public function contactFormCanBeSubmitted(AcceptanceTester $I)
{
$I->amGoingTo('submit contact form with correct data');
$I->fillField('#contactform-name', 'tester');
$I->fillField('#contactform-email', 'tester@example.com');
$I->fillField('#contactform-subject', 'test subject');
$I->fillField('#contactform-body', 'test content');
$I->fillField('#contactform-verifycode', 'testme');
$I->click('contact-button');
$I->wait(2); // wait for button to be clicked
$I->dontSeeElement('#contact-form');
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
}
}
<?php
use yii\helpers\Url;
class HomeCest
{
public function ensureThatHomePageWorks(AcceptanceTester $I)
{
$I->amOnPage(Url::toRoute('/site/index'));
$I->see('My Company');
$I->seeLink('About');
$I->click('About');
$I->wait(2); // wait for page to be opened
$I->see('This is the About page.');
}
}
<?php
use yii\helpers\Url;
class LoginCest
{
public function ensureThatLoginWorks(AcceptanceTester $I)
{
$I->amOnPage(Url::toRoute('/site/login'));
$I->see('Login', 'h1');
$I->amGoingTo('try to login with correct credentials');
$I->fillField('input[name="LoginForm[username]"]', 'admin');
$I->fillField('input[name="LoginForm[password]"]', 'admin');
$I->click('login-button');
$I->wait(2); // wait for button to be clicked
$I->expectTo('see user info');
$I->see('Logout');
}
}
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
$config = yii\helpers\ArrayHelper::merge(
require __DIR__ . '/../../config/console.php',
[
'components' => [
'db' => require __DIR__ . '/../../config/test_db.php'
]
]
);
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
@echo off
rem -------------------------------------------------------------
rem Yii command line bootstrap script for Windows.
rem
rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/
rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/
rem -------------------------------------------------------------
@setlocal
set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %*
@endlocal
# Codeception Test Suite Configuration
# suite for functional (integration) tests.
# emulate web requests and make application process them.
# (tip: better to use with frameworks).
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
#basic/web/index.php
class_name: FunctionalTester
modules:
enabled:
- Filesystem
- Yii2
<?php
class ContactFormCest
{
public function _before(\FunctionalTester $I)
{
$I->amOnPage(['site/contact']);
}
public function openContactPage(\FunctionalTester $I)
{
$I->see('Contact', 'h1');
}
public function submitEmptyForm(\FunctionalTester $I)
{
$I->submitForm('#contact-form', []);
$I->expectTo('see validations errors');
$I->see('Contact', 'h1');
$I->see('Name cannot be blank');
$I->see('Email cannot be blank');
$I->see('Subject cannot be blank');
$I->see('Body cannot be blank');
$I->see('The verification code is incorrect');
}
public function submitFormWithIncorrectEmail(\FunctionalTester $I)
{
$I->submitForm('#contact-form', [
'ContactForm[name]' => 'tester',
'ContactForm[email]' => 'tester.email',
'ContactForm[subject]' => 'test subject',
'ContactForm[body]' => 'test content',
'ContactForm[verifyCode]' => 'testme',
]);
$I->expectTo('see that email address is wrong');
$I->dontSee('Name cannot be blank', '.help-inline');
$I->see('Email is not a valid email address.');
$I->dontSee('Subject cannot be blank', '.help-inline');
$I->dontSee('Body cannot be blank', '.help-inline');
$I->dontSee('The verification code is incorrect', '.help-inline');
}
public function submitFormSuccessfully(\FunctionalTester $I)
{
$I->submitForm('#contact-form', [
'ContactForm[name]' => 'tester',
'ContactForm[email]' => 'tester@example.com',
'ContactForm[subject]' => 'test subject',
'ContactForm[body]' => 'test content',
'ContactForm[verifyCode]' => 'testme',
]);
$I->seeEmailIsSent();
$I->dontSeeElement('#contact-form');
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
}
}
<?php
class LoginFormCest
{
public function _before(\FunctionalTester $I)
{
$I->amOnRoute('site/login');
}
public function openLoginPage(\FunctionalTester $I)
{
$I->see('Login', 'h1');
}
// demonstrates `amLoggedInAs` method
public function internalLoginById(\FunctionalTester $I)
{
$I->amLoggedInAs(100);
$I->amOnPage('/');
$I->see('Logout (admin)');
}
// demonstrates `amLoggedInAs` method
public function internalLoginByInstance(\FunctionalTester $I)
{
$I->amLoggedInAs(\app\models\User::findByUsername('admin'));
$I->amOnPage('/');
$I->see('Logout (admin)');
}
public function loginWithEmptyCredentials(\FunctionalTester $I)
{
$I->submitForm('#login-form', []);
$I->expectTo('see validations errors');
$I->see('Username cannot be blank.');
$I->see('Password cannot be blank.');
}
public function loginWithWrongCredentials(\FunctionalTester $I)
{
$I->submitForm('#login-form', [
'LoginForm[username]' => 'admin',
'LoginForm[password]' => 'wrong',
]);
$I->expectTo('see validations errors');
$I->see('Incorrect username or password.');
}
public function loginSuccessfully(\FunctionalTester $I)
{
$I->submitForm('#login-form', [
'LoginForm[username]' => 'admin',
'LoginForm[password]' => 'admin',
]);
$I->see('Logout (admin)');
$I->dontSeeElement('form#login-form');
}
}
\ No newline at end of file
# Codeception Test Suite Configuration
# suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: UnitTester
modules:
enabled:
- Asserts
- Yii2:
part: [orm, email, fixtures]
<?php
// add unit testing specific bootstrap code here
<?php
namespace tests\unit\models;
use app\models\ContactForm;
use yii\mail\MessageInterface;
class ContactFormTest extends \Codeception\Test\Unit
{
private $model;
/**
* @var \UnitTester
*/
public $tester;
public function testEmailIsSentOnContact()
{
/** @var ContactForm $model */
$this->model = $this->getMockBuilder('app\models\ContactForm')
->setMethods(['validate'])
->getMock();
$this->model->expects($this->once())
->method('validate')
->willReturn(true);
$this->model->attributes = [
'name' => 'Tester',
'email' => 'tester@example.com',
'subject' => 'very important letter subject',
'body' => 'body of current message',
];
expect_that($this->model->contact('admin@example.com'));
// using Yii2 module actions to check email was sent
$this->tester->seeEmailIsSent();
/** @var MessageInterface $emailMessage */
$emailMessage = $this->tester->grabLastSentEmail();
expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
expect($emailMessage->getTo())->hasKey('admin@example.com');
expect($emailMessage->getFrom())->hasKey('noreply@example.com');
expect($emailMessage->getReplyTo())->hasKey('tester@example.com');
expect($emailMessage->getSubject())->equals('very important letter subject');
expect($emailMessage->toString())->stringContainsString('body of current message');
}
}
<?php
namespace tests\unit\models;
use app\models\LoginForm;
class LoginFormTest extends \Codeception\Test\Unit
{
private $model;
protected function _after()
{
\Yii::$app->user->logout();
}
public function testLoginNoUser()
{
$this->model = new LoginForm([
'username' => 'not_existing_username',
'password' => 'not_existing_password',
]);
expect_not($this->model->login());
expect_that(\Yii::$app->user->isGuest);
}
public function testLoginWrongPassword()
{
$this->model = new LoginForm([
'username' => 'demo',
'password' => 'wrong_password',
]);
expect_not($this->model->login());
expect_that(\Yii::$app->user->isGuest);
expect($this->model->errors)->hasKey('password');
}
public function testLoginCorrect()
{
$this->model = new LoginForm([
'username' => 'demo',
'password' => 'demo',
]);
expect_that($this->model->login());
expect_not(\Yii::$app->user->isGuest);
expect($this->model->errors)->hasntKey('password');
}
}
<?php
namespace tests\unit\models;
use app\models\User;
class UserTest extends \Codeception\Test\Unit
{
public function testFindUserById()
{
expect_that($user = User::findIdentity(100));
expect($user->username)->equals('admin');
expect_not(User::findIdentity(999));
}
public function testFindUserByAccessToken()
{
expect_that($user = User::findIdentityByAccessToken('100-token'));
expect($user->username)->equals('admin');
expect_not(User::findIdentityByAccessToken('non-existing'));
}
public function testFindUserByUsername()
{
expect_that($user = User::findByUsername('admin'));
expect_not(User::findByUsername('not-admin'));
}
/**
* @depends testFindUserByUsername
*/
public function testValidateUser($user)
{
$user = User::findByUsername('admin');
expect_that($user->validateAuthKey('test100key'));
expect_not($user->validateAuthKey('test102key'));
expect_that($user->validatePassword('admin'));
expect_not($user->validatePassword('123456'));
}
}
# local configuration
vagrant-local.yml
\ No newline at end of file
# Your personal GitHub token
github_token: <your-personal-github-token>
# Read more: https://github.com/blog/1509-personal-api-tokens
# You can generate it here: https://github.com/settings/tokens
# Guest OS timezone
timezone: Europe/London
# Are we need check box updates for every 'vagrant up'?
box_check_update: false
# Virtual machine name
machine_name: yii2basic
# Virtual machine IP
ip: 192.168.83.137
# Virtual machine CPU cores number
cpus: 1
# Virtual machine RAM
memory: 1024
server {
charset utf-8;
client_max_body_size 128M;
sendfile off;
listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name yii2basic.test;
root /app/web/;
index index.php;
access_log /app/vagrant/nginx/log/yii2basic.access.log;
error_log /app/vagrant/nginx/log/yii2basic.error.log;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
# uncomment to avoid processing of calls to non-existing static files by Yii
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
# try_files $uri =404;
#}
#error_page 404 /404.html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
try_files $uri =404;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}
#nginx logs
yii2basic.access.log
yii2basic.error.log
\ No newline at end of file
#!/usr/bin/env bash
#== Bash helpers ==
function info {
echo " "
echo "--> $1"
echo " "
}
#== Provision script ==
info "Provision-script user: `whoami`"
info "Restart web-stack"
service php7.0-fpm restart
service nginx restart
service mysql restart
\ No newline at end of file
#!/usr/bin/env bash
#== Import script args ==
timezone=$(echo "$1")
#== Bash helpers ==
function info {
echo " "
echo "--> $1"
echo " "
}
#== Provision script ==
info "Provision-script user: `whoami`"
export DEBIAN_FRONTEND=noninteractive
info "Configure timezone"
timedatectl set-timezone ${timezone} --no-ask-password
info "Prepare root password for MySQL"
debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password password \"''\""
debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password_again password \"''\""
echo "Done!"
info "Update OS software"
apt-get update
apt-get upgrade -y
info "Install additional software"
apt-get install -y php7.0-curl php7.0-cli php7.0-intl php7.0-mysqlnd php7.0-gd php7.0-fpm php7.0-mbstring php7.0-xml unzip nginx mariadb-server-10.0 php.xdebug
info "Configure MySQL"
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mariadb.conf.d/50-server.cnf
mysql -uroot <<< "CREATE USER 'root'@'%' IDENTIFIED BY ''"
mysql -uroot <<< "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'"
mysql -uroot <<< "DROP USER 'root'@'localhost'"
mysql -uroot <<< "FLUSH PRIVILEGES"
echo "Done!"
info "Configure PHP-FPM"
sed -i 's/user = www-data/user = vagrant/g' /etc/php/7.0/fpm/pool.d/www.conf
sed -i 's/group = www-data/group = vagrant/g' /etc/php/7.0/fpm/pool.d/www.conf
sed -i 's/owner = www-data/owner = vagrant/g' /etc/php/7.0/fpm/pool.d/www.conf
cat << EOF > /etc/php/7.0/mods-available/xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.remote_autostart=1
EOF
echo "Done!"
info "Configure NGINX"
sed -i 's/user www-data/user vagrant/g' /etc/nginx/nginx.conf
echo "Done!"
info "Enabling site configuration"
ln -s /app/vagrant/nginx/app.conf /etc/nginx/sites-enabled/app.conf
echo "Done!"
info "Removing default site configuration"
rm /etc/nginx/sites-enabled/default
echo "Done!"
info "Initailize databases for MySQL"
mysql -uroot <<< "CREATE DATABASE yii2basic"
mysql -uroot <<< "CREATE DATABASE yii2basic_test"
echo "Done!"
info "Install composer"
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
\ No newline at end of file
#!/usr/bin/env bash
#== Import script args ==
github_token=$(echo "$1")
#== Bash helpers ==
function info {
echo " "
echo "--> $1"
echo " "
}
#== Provision script ==
info "Provision-script user: `whoami`"
info "Configure composer"
composer config --global github-oauth.github.com ${github_token}
echo "Done!"
info "Install project dependencies"
cd /app
composer --no-progress --prefer-dist install
info "Create bash-alias 'app' for vagrant user"
echo 'alias app="cd /app"' | tee /home/vagrant/.bash_aliases
info "Enabling colorized prompt for guest console"
sed -i "s/#force_color_prompt=yes/force_color_prompt=yes/" /home/vagrant/.bashrc
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\HasilVoting */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="hasil-voting-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'id_voting')->textInput() ?>
<?= $form->field($model, 'id_user')->textInput() ?>
<?= $form->field($model, 'pilihan')->textInput() ?>
<?= $form->field($model, 'status_voting')->textInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<head>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
</head>
<?php
use yii\helpers\Html;
use kartik\form\ActiveForm;
use kartik\select2\Select2;
use yii\grid\GridView;
use app\models\TKandidat;
use miloschuman\highcharts\Highcharts;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $model app\models\HasilVoting */
/* @var $form yii\widgets\ActiveForm */
$urlHasilVoting = Url::to(['hasil-voting/result-voting']);
?>
<hr>
<center><h3 class="text-danger"><b>Hasil Voting <?= $voting->nama_voting;?></b></h3></center>
<hr>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="panel panel-danger">
<div class="panel-heading">
<center><h3 class="panel-title">Grafik Persentase Voting <?= $voting->nama_voting;?></h3></center>
</div>
<div class="panel-body">
<figure class="highcharts-figure" id="voting">
</figure>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="panel panel-success">
<div class="panel-heading">
<center><h3 class="panel-title"><b>Jumlah Suara Kandidat <?= $voting->nama_voting;?></b></h3></center>
</div>
<div class="panel-body">
<table class="table">
<tr>
<td><b>KANDIDAT</b></td>
<td align="center"><b>JUMLAH SUARA</b></td>
</tr>
<?php
foreach ($hasil_voting as $key => $value) {
?>
<tr>
<td>
<?php
$kandidat = TKandidat::find()->where(['id_kandidat' => $value['pilihan']])->one();
echo $kandidat->nama_kandidat;
?>
</td>
<td align="center"><h4><span class="label label-primary"><?= $value['Jumlah_Voting']?></span></h4></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
<?php
$this->title = '';
$script = <<< JS
$(document).ready(function(){
txt = 'Hasil Voting '
$.ajax({
url: '{$urlHasilVoting}',
type: "GET",
data:{
id_voting: {$voting->id_voting},
},
contentType: "application/json",
dataType: 'json',
success: function(response){
Highcharts.chart('voting', {
credits: {
enabled: false
},
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: ''
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
accessibility: {
point: {
valueSuffix: '%'
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.2f} %'
}
}
},
series: [{
name: 'Persentase Voting',
colorByPoint: true,
data: response,
}]
});
},
});
});
JS;
$this->registerJs($script)
?>
\ No newline at end of file
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\HasilVotingSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="hasil-voting-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id_voting') ?>
<?= $form->field($model, 'id_user') ?>
<?= $form->field($model, 'pilihan') ?>
<?= $form->field($model, 'status_voting') ?>
<?= $form->field($model, 'created_at') ?>
<?php // echo $form->field($model, 'created_by') ?>
<?php // echo $form->field($model, 'updated_at') ?>
<?php // echo $form->field($model, 'updated_by') ?>
<?php // echo $form->field($model, 'active') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\models\HasilVoting */
$this->title = 'Create Hasil Voting';
$this->params['breadcrumbs'][] = ['label' => 'Hasil Votings', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hasil-voting-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<head>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
</head>
<?php
use yii\helpers\Html;
use kartik\form\ActiveForm;
use kartik\select2\Select2;
use yii\grid\GridView;
use app\models\TKandidat;
use miloschuman\highcharts\Highcharts;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $model app\models\HasilVoting */
/* @var $form yii\widgets\ActiveForm */
$urlHasilVoting = Url::to(['hasil-voting/result-voting']);
$urlFilterHasilVoting = Url::to(['hasil-voting/filter-hasil-voting']);
?>
<div class="hasil-voting-form">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
</div>
<div class="col-lg-2 col-md-2 col-sm-2" align="right">
<?= Html::a('<span class="glyphicon glyphicon-step-backward"></span>Kembali', ['voting/index-hasil-voting'], ['class' => 'btn btn-default']) ?>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<?php
echo Select2::widget([
'name' => 'id_voting',
'data' => $arrayVoting,
'options' => [
'placeholder' => 'Filter Data Voting...',
'id'=>'hasilvoting'
],
'pluginOptions' => [
'allowClear' => false
],
]);
?>
</div>
</div>
<div id="filterhasilvoting">
<hr>
<center><h3 class="text-danger"><b>Hasil Voting <?= $voting->nama_voting;?></b></h3></center>
<hr>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="panel panel-danger">
<div class="panel-heading">
<center><h3 class="panel-title">Grafik Persentase Voting <?= $voting->nama_voting;?></h3></center>
</div>
<div class="panel-body">
<figure class="highcharts-figure" id="voting">
</figure>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="panel panel-success">
<div class="panel-heading">
<center><h3 class="panel-title"><b>Jumlah Suara Kandidat <?= $voting->nama_voting;?></b></h3></center>
</div>
<div class="panel-body">
<table class="table">
<tr>
<td><b>KANDIDAT</b></td>
<td align="center"><b>JUMLAH SUARA</b></td>
</tr>
<?php
foreach ($hasil_voting as $key => $value) {
?>
<tr>
<td>
<?php
$kandidat = TKandidat::find()->where(['id_kandidat' => $value['pilihan']])->one();
echo $kandidat->nama_kandidat;
?>
</td>
<td align="center"><h4><span class="label label-primary"><?= $value['Jumlah_Voting']?></span></h4></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
<?php
$this->title = '';
$script = <<< JS
$(document).ready(function(){
txt = 'Hasil Voting '
$.ajax({
url: '{$urlHasilVoting}',
type: "GET",
data:{
id_voting: {$voting->id_voting},
},
contentType: "application/json",
dataType: 'json',
success: function(response){
Highcharts.chart('voting', {
credits: {
enabled: false
},
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: ''
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
accessibility: {
point: {
valueSuffix: '%'
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.2f} %'
}
}
},
series: [{
name: 'Persentase Voting',
colorByPoint: true,
data: response,
}]
});
},
});
});
$("#hasilvoting").on("change",function(){
//$(".loading-image").show();
$.ajax({
url:"{$urlFilterHasilVoting}",
type: "GET",
data:"id_voting="+$(this).val(),
success:function(data){
$("#filterhasilvoting").html(data);
//$(".loading-image").hide();
},
error:function(xhr, ajaxOptions, throwError)
{
//$(".loading-image").hide();
alert("GAGAL LOAD DATA");
}
});
});
JS;
$this->registerJs($script)
?>
\ No newline at end of file
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel app\models\HasilVotingSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Hasil Votings';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hasil-voting-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Create Hasil Voting', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id_voting',
'id_user',
'pilihan',
'status_voting',
'created_at',
//'created_by',
//'updated_at',
//'updated_by',
//'active',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
<?php
use yii\helpers\Html;
use kartik\form\ActiveForm;
use kartik\select2\Select2;
/* @var $this yii\web\View */
/* @var $model app\models\HasilVoting */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="hasil-voting-form">
<?php
if(!is_null($hasil_voting)){
?>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="panel panel-primary">
<div class="panel-heading">
<center><h4>Voting <?= $voting->nama_voting;?></h4></center>
</div>
<div class="panel-body">
<h4>Terima Kasih Buat Partisipasi Anda Telah Melakukan Online Voting Pada <i class="text-danger"><?= $voting->nama_voting;?></i><br></h4>
</div>
</div>
</div>
</div>
<?php
}
else{
?>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="panel panel-primary">
<div class="panel-heading">
<center><h4>Voting <?= $voting->nama_voting;?></h4></center>
</div>
<div class="panel-body">
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'type' => ActiveForm::TYPE_VERTICAL,
'formConfig' => ['labelSpan' => 3, 'deviceSize' => ActiveForm::SIZE_SMALL]
]); ?>
<div class="form-group" align="justify">
<?php
echo $form->field($model, 'pilihan')->radioList($arrayPilihan,['separator' => "<br>" ])->label(false);
?>
</div>
<div class="form-group">
<center>
<?= Html::submitButton('SUBMIT VOTING', ['class' => 'btn btn-primary',
'data' => [
'confirm' => 'APAKAH ANDA SUDAH YAKIN DENGAN PILIHAN ANDA?',
'method' => 'post',
],])
?>
</center>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
<?php
use yii\helpers\Html;
use kartik\form\ActiveForm;
use kartik\select2\Select2;
//use yii\grid\GridView;
use app\models\TKandidat;
use miloschuman\highcharts\Highcharts;
use kartik\grid\GridView;
use kartik\mpdf\Pdf;
/* @var $this yii\web\View */
/* @var $model app\models\HasilVoting */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="hasil-voting-form">
<div class="row">
<center><h3 class="text-danger"><b>Rekapitulasi Pengguna Voting <?= $voting->nama_voting;?></b></h3></center>
<p align="right">
<?= Html::a('<span class="glyphicon glyphicon-step-backward"></span>Kembali', ['voting/index-pengguna-voting'], ['class' => 'btn btn-default']) ?>
</p>
<hr>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="alert alert-success" role="alert">
<h4 class="text-danger">Total Pengguna Voting</h4>
<h3><b><?= $count_total_pengguna;?></b> User</h3>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="alert alert-info" role="alert">
<h4 class="text-danger">Pengguna Sudah Voting</h4>
<h3><b><?= $count_sudah_voting;?></b> User</h3>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="alert alert-danger" role="alert">
<h4 class="text-danger">Pengguna Belum Voting</h4>
<h3><b><?= $count_belum_voting;?></b> User</h3>
</div>
</div>
</div>
<hr>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
<?php
echo GridView::widget([
'dataProvider'=>$dataProvider,
//'filterModel'=>$searchModel,
/*'summary'=>'',*/
'showPageSummary'=>true,
'pjax'=>true,
'striped'=>true,
'hover'=>true,
'headerRowOptions' => ['class' => 'kartik-sheet-style'],
'responsive'=>true,
//'containerOptions' => ['style' => 'overflow: auto'],
'export'=>['fontAwesome'=>true,
'showConfirmAlert'=>false,
'label'=>'Download',
'header'=>'',
'options'=>[
'class' => 'btn btn-info',
],
],
'exportConfig'=>[
GridView::PDF =>[
'icon' => 'file-pdf-o',
'iconOptions' => ['class' => 'text-success'],
'filename' => 'Rekapitulasi_Pengguna_Sudah_Voting',
'alertMsg' =>null,
'options' => ['title' => 'Portable Document Format'],
'mime' => 'application/pdf',
'format' => Pdf::FORMAT_A4,
'config' => [
'methods' => [
'SetHeader' => ['Dicetak dari: Aplikasi Online Voting ||Dicetak tanggal: ' . date("D/d-M-Y")],
/*'SetHeader' =>'',*/
'SetFooter' => ['||Halaman {PAGENO}'],
],
'contentBefore'=>'',
'contentAfter'=>'',
]
],
GridView::EXCEL =>[
'icon' => 'file-excel-o',
'iconOptions' => ['class' => 'text-success'],
'filename' => 'Rekapitulasi_Pengguna_Sudah_Voting',
],
],
'toolbar'=>['{toggleData}{export}'],
'panel'=>['type'=>'primary', 'heading'=>'REKAPITULASI PENGGUNA SUDAH VOTING'],
'columns'=>[
[
'class'=>'yii\grid\SerialColumn',
],
'user.nama_user',
'user.email',
[
'header' => 'Status Voting',
'attribute' => 'id_user',
//'value' => 'id_user',
'format' => 'raw',
'value' => function ($model, $key, $index, $widget) {
if ($model->status_voting == 1) {
return '<b><span class="label label-primary">SUDAH MELAKUKAN VOTING</span></b>';
}else{
return '<b><span class="label label-primary">BELUM MELAKUKAN VOTING</span></b>';
}
},
'contentOptions' => [
'class' => 'text-center',
//'style' => 'font-weight: bold;'
],
'headerOptions' => [
'class' => 'text-center',
],
],
],
]);
?>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<?php
echo GridView::widget([
'dataProvider'=>$dataProvider2,
//'filterModel'=>$searchModel,
/*'summary'=>'',*/
'showPageSummary'=>true,
'pjax'=>true,
'striped'=>true,
'hover'=>true,
'headerRowOptions' => ['class' => 'kartik-sheet-style'],
'responsive'=>true,
//'containerOptions' => ['style' => 'overflow: auto'],
'export'=>['fontAwesome'=>true,
'showConfirmAlert'=>false,
'label'=>'Download',
'header'=>'',
'options'=>[
'class' => 'btn btn-danger',
],
],
'exportConfig'=>[
GridView::PDF =>[
'icon' => 'file-pdf-o',
'iconOptions' => ['class' => 'text-success'],
'filename' => 'Rekapitulasi_Pengguna_Belum_Voting',
'alertMsg' =>null,
'options' => ['title' => 'Portable Document Format'],
'mime' => 'application/pdf',
'format' => Pdf::FORMAT_A4,
'config' => [
'methods' => [
'SetHeader' => ['Dicetak dari: Aplikasi Online Voting ||Dicetak tanggal: ' . date("D/d-M-Y")],
/*'SetHeader' =>'',*/
'SetFooter' => ['||Halaman {PAGENO}'],
],
'contentBefore'=>'',
'contentAfter'=>'',
]
],
GridView::EXCEL =>[
'icon' => 'file-excel-o',
'iconOptions' => ['class' => 'text-success'],
'filename' => 'Rekapitulasi_Pengguna_Belum_Voting',
],
],
'toolbar'=>['{toggleData}{export}'],
'panel'=>['type'=>'danger', 'heading'=>'REKAPITULASI PENGGUNA BELUM VOTING'],
'columns'=>[
[
'class'=>'yii\grid\SerialColumn',
],
'nama_user',
'email',
[
'header' => 'Status Voting',
'attribute' => 'id',
//'value' => 'id_user',
'format' => 'raw',
'value' => function ($model, $key, $index, $widget) {
if ($model->id != NULL) {
return '<b><span class="label label-danger">BELUM VOTING</span></b>';
}else{
return '-';
}
},
'contentOptions' => [
'class' => 'text-center',
//'style' => 'font-weight: bold;'
],
'headerOptions' => [
'class' => 'text-center',
],
],
],
]);
?>
</div>
</div>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\models\HasilVoting */
$this->title = 'Update Hasil Voting: ' . $model->id_voting;
$this->params['breadcrumbs'][] = ['label' => 'Hasil Votings', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id_voting, 'url' => ['view', 'id_voting' => $model->id_voting, 'id_user' => $model->id_user]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="hasil-voting-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model app\models\HasilVoting */
$this->title = $model->id_voting;
$this->params['breadcrumbs'][] = ['label' => 'Hasil Votings', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="hasil-voting-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id_voting' => $model->id_voting, 'id_user' => $model->id_user], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id_voting' => $model->id_voting, 'id_user' => $model->id_user], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id_voting',
'id_user',
'pilihan',
'status_voting',
'created_at',
'created_by',
'updated_at',
'updated_by',
'active',
],
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\TKandidat */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="tkandidat-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'nama_kandidat')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<center>
<?= Html::submitButton('SIMPAN DATA KANDIDAT', ['class' => 'btn btn-success']) ?>
</center>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\TKandidatSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="tkandidat-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id_kandidat') ?>
<?= $form->field($model, 'nama_kandidat') ?>
<?= $form->field($model, 'id_voting') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\models\TKandidat */
$this->title = 'Tambah Kandidat';
?>
<div class="tkandidat-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\bootstrap\Modal;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel app\models\TKandidatSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Kandidat';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php
Modal::begin([
'header' => '<center><h4>FORM DATA KANDIDAT</h4></center>',
'id' => 'modal-data',
'size' => 'modal-md',
'options' => [
'tabindex' => false,
],
]);
echo '<div id="content-modal-data"></div>';
Modal::end();
?>
<div class="tkandidat-index">
<center><h3><b class="text-danger">DATA KANDIDAT PADA VOTING</b></h3></center>
<p align="right">
<?= Html::a('<span class="glyphicon glyphicon-step-backward"></span>Kembali', ['voting/index'], ['class' => 'btn btn-default']) ?>
<?= Html::button('<span class="glyphicon glyphicon-plus"></span> TAMBAH DATA KANDIDAT', ['id' => 'modalButton', 'value' => \yii\helpers\Url::to(['kandidat/create','id_voting' =>$_GET['id_voting']]), 'class' => 'btn btn-success']) ?>
</p>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'nama_kandidat',
'voting.nama_voting',
[
'options' => [
'width' => '150px',
],
'header' => 'AKSI',
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'buttons' => [
'update' => function($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', '#', [
'class' => 'btn btn-warning',
'title' => 'EDIT DATA',
'id' => 'modalButton',
'onclick' => "
$.ajax({
url: '$url',
success:function(data){
$('#title').html('Detail Organisasi');
$('#content-modal-data').html(data);
$('#modal-data').modal('show');
},
error:function(xhr, ajaxOptions, throwError){
alert(xhr.responseText);
}
})
",
]);
},
'delete' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', Url::to(['kandidat/delete','id'=>$model->id_kandidat,'id_voting'=>$model->id_voting]), [
'class' => 'btn btn-danger',
'title' => 'HAPUS DATA',
'data-toggle' => 'tooltip',
'data-method' => 'post',
'data-confirm' => 'Apakah anda yakin ingin menghapus data ini?'
]);
},
]
],
],
]); ?>
</div>
<?php
$script = <<< JS
$(function () {
$('#modalButton').click(function () {
$('#modal-data').modal('show')
.find('#content-modal-data')
.load($(this).attr('value'));
});
});
JS;
$this->registerJs($script)
?>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\models\TKandidat */
$this->title = 'Update Kandidat';
?>
<div class="tkandidat-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model app\models\TKandidat */
$this->title = 'View Kandidat';
\yii\web\YiiAsset::register($this);
?>
<div class="tkandidat-view">
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'nama_kandidat',
],
]) ?>
</div>
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