From e31d97aa2966f5a0a3a51ab8199faa94124b8a9d Mon Sep 17 00:00:00 2001 From: vbrazas Date: Mon, 22 Apr 2019 23:25:19 +0300 Subject: [PATCH 1/7] [#129] Fixed several typos, changed build system, now it strongly tied up on .env --- .env.example | 11 ++++++----- config/db.php | 6 +++--- config/web.php | 13 ++++++------- controllers/CalculatorController.php | 4 ++-- controllers/ProjectsAllSearch.php | 9 ++++----- docker-compose.yml | 20 ++++++++++---------- views/calculator/index.php | 3 ++- views/projects/index.php | 13 +++++-------- views/projects/view_with_childs.php | 16 ++++++++-------- 9 files changed, 46 insertions(+), 49 deletions(-) diff --git a/.env.example b/.env.example index 196a0ae..b0361dc 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,7 @@ YII_DEBUG=true YII_ENV=dev YII_ENV_DEV=false -VD_KEY= +VD_KEY= #yii's csrf validation token # Oauth2 42 42_API_CI= #client id @@ -12,14 +12,15 @@ VD_KEY= # Mysql config # Local database -DB_HOST=mysql -DB_PORT=3306 +DB_HOST=mysql # your mysql server's IP DB_NAME=yii2 DB_USERNAME=yii2 DB_PASSWORD=yii2 # UNIX_SOCKET=/var/run/mysqld/mysqld.sock -#YII_ENV_TEST=1 -YII_ENV_DEV=true +# Ports binding +WEB_PORT=8888 +DB_PORT=3306 +PHPMA_PORT=8080 GITHUB_API_TOKEN= diff --git a/config/db.php b/config/db.php index eaed02e..828e415 100644 --- a/config/db.php +++ b/config/db.php @@ -2,9 +2,9 @@ return [ 'class' => 'yii\db\Connection', - 'dsn' => 'mysql:host=' . env('DB_HOST', 'mysql') . ';dbname=' . env('DB_NAME', 'yii2'), - 'username' => env('DB_USERNAME', 'yii2'), - 'password' => env('DB_PASSWORD', 'yii2'), + 'dsn' => 'mysql:host=' . getenv('DB_HOST', 'mysql') . ';port=' . getenv('DB_PORT', '3306') .';dbname=' . getenv('DB_NAME', 'yii2') . ';', + 'username' => getenv('DB_USERNAME', 'yii2'), + 'password' => getenv('DB_PASSWORD', 'yii2'), 'charset' => 'utf8', // Schema cache options (for production environment) //'enableSchemaCache' => true, diff --git a/config/web.php b/config/web.php index f7fec94..d8eda08 100644 --- a/config/web.php +++ b/config/web.php @@ -13,10 +13,10 @@ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], - 'modules' => [ + 'modules' => [ 'languages' => [ 'class' => 'klisl\languages\Module', - //Языки используемые в приложении + //Языки используемые в приложении 'languages' => [ 'Русский' => 'ru', 'Українська' => 'uk', @@ -28,8 +28,7 @@ ], 'components' => [ 'request' => [ - // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation - 'cookieValidationKey' => env('VD_KEY', ''), + 'cookieValidationKey' => getenv('VD_KEY'), 'enableCookieValidation' => true, 'enableCsrfValidation' => true, 'baseUrl' => '', //убрать frontend/web @@ -77,8 +76,8 @@ 'clients' => [ 'auth42' => [ 'class' => 'app\helpers\Auth42', - 'clientId' => env('42_API_CI', ''), - 'clientSecret' => env('42_API_CS', ''), + 'clientId' => getenv('42_API_CI'), + 'clientSecret' => getenv('42_API_CS'), ], ], ], @@ -105,8 +104,8 @@ 'students' => 'show/students', 'pools' => 'show/pools', 'calculator' => 'calculator/index', - 'change-theme' => 'site/change-theme', 'calculator/form-submission' => 'calculator/form-submission', + 'change-theme' => 'site/change-theme', 'corrections' => 'corrections/index', 'friends' => 'friend/index', 'friends/create//' => 'friend/create', diff --git a/controllers/CalculatorController.php b/controllers/CalculatorController.php index bd1c046..4043afe 100644 --- a/controllers/CalculatorController.php +++ b/controllers/CalculatorController.php @@ -18,7 +18,7 @@ class CalculatorController extends CommonController * * @return String which sends to the View */ - public function actionIndex( $model = null ) + public function actionIndex($model = null) { $title = Yii::t('app', 'Experience calculator'); $description = Yii::t('app', 'Want to know your level after project evaluation -- use our Experience calculator!'); @@ -46,7 +46,7 @@ public function actionIndex( $model = null ) * @param Object $model reference to Calculator's Model instance * @param Array $post $post request array */ - private function getMarkFromPost( &$model, $post ) + private function getMarkFromPost(&$model, $post) { if ($model && $post && $model->load($post) && $model->validate() ) { diff --git a/controllers/ProjectsAllSearch.php b/controllers/ProjectsAllSearch.php index 4b5c819..ce7e5dc 100644 --- a/controllers/ProjectsAllSearch.php +++ b/controllers/ProjectsAllSearch.php @@ -82,15 +82,14 @@ public function search($params) 'xlogin' => SORT_ASC, ]], ]); - - $dataProvider->sort->attributes['location'] = [ 'asc' => ['xlogins.location' => SORT_ASC], - 'desc' => ['xlogins.location' => SORT_DESC],]; - + 'desc' => ['xlogins.location' => SORT_DESC], + ]; $dataProvider->sort->attributes['lastloc'] = [ 'asc' => ['xlogins.lastloc' => SORT_ASC], - 'desc' => ['xlogins.lastloc' => SORT_DESC],]; + 'desc' => ['xlogins.lastloc' => SORT_DESC], + ]; $this->load($params); diff --git a/docker-compose.yml b/docker-compose.yml index 6cd69f3..a20403a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,12 @@ -version: '3' +version: '3.4' + services: web: build: ./ ports: - - '8888:80' + - '${WEB_PORT:-8888}:80' expose: - - "80" - - "9000" + - '9000' volumes: - ./:/var/www/html/ links: @@ -17,12 +17,12 @@ services: container_name: 'yii2-mysql' restart: 'always' ports: - - "3306:3306" + - '${DB_PORT:-3306}:3306' environment: - MYSQL_ROOT_PASSWORD: yii2 - MYSQL_DATABASE: yii2 - MYSQL_USER: yii2 - MYSQL_PASSWORD: yii2 + MYSQL_DATABASE: ${DB_NAME:-yii2} + MYSQL_USER: ${DB_USERNAME:-yii2} + MYSQL_PASSWORD: ${DB_PASSWORD:-yii2} + MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-yii2} volumes: - ./config/:/docker-entrypoint-initdb.d/ @@ -35,6 +35,6 @@ services: PMA_HOST: mysql PMA_PORT: 3306 ports: - - '8080:80' + - '${PHPMA_PORT:-8080}:80' volumes: - /sessions diff --git a/views/calculator/index.php b/views/calculator/index.php index b303d4a..e6de72c 100644 --- a/views/calculator/index.php +++ b/views/calculator/index.php @@ -9,9 +9,10 @@ /* @var $model app\models\Calculator */ $calc_js = <<

title) ?>

+ 10000 ]); ?> + render('_search', ['model' => $searchModel, 'action' => $action, 'months' => $months, 'years' => $years]) ?>
@@ -53,12 +55,7 @@ ], ]); ?>
--->registerJs(" -//// $('table tr[data-href]').click(function () { -//// if ($(this).data('href') !== undefined) { -//// window.location.href = $(this).data('href'); -//// } -//// });"); -// ?> + + + diff --git a/views/projects/view_with_childs.php b/views/projects/view_with_childs.php index a9cb5c4..f4e2c8a 100644 --- a/views/projects/view_with_childs.php +++ b/views/projects/view_with_childs.php @@ -18,13 +18,19 @@ $this->params['breadcrumbs'][] = ['label' => ucfirst($breadcrumbs['1']['name']), 'url' => [$breadcrumbs['1']['url']]]; $this->params['breadcrumbs'][] = ucfirst(strtok($this->title, '::')); +$this->registerJs(" + $('table tr[data-href]').click(function () { + if ($(this).data('href') !== undefined) { + window.location.href = $(this).data('href'); + } + });"); + ?>

title, '::'))) ?>

render('_sub', ['action' => $action, 'searchModel' => $searchModelSubProject, 'dataProvider' => $dataProviderSubProject, 'pageName' => $pageName, 'subPage' => $subPage, 'months' => $months, 'years' => $years]); $marks = $this->render('_marks', ['action' => $action, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'pageName' => $pageName, 'months' => $months, 'years' => $years]); @@ -47,12 +53,6 @@ 'position'=>TabsX::POS_ABOVE, 'encodeLabels'=>false ]); -$this->registerJs(" - $('table tr[data-href]').click(function () { - if ($(this).data('href') !== undefined) { - window.location.href = $(this).data('href'); - } - });"); - ?> +?>
From 8fc9204672ec79041980da29eee47aa364795b73 Mon Sep 17 00:00:00 2001 From: vbrazas Date: Mon, 22 Apr 2019 23:45:24 +0300 Subject: [PATCH 2/7] [#129] Fixed issue with visible column, deleted all about vagrant --- Vagrantfile | 81 ------------------- helpers/Auth42.php | 2 +- helpers/RememberUserInfo/RememberUser.php | 4 +- helpers/RememberUserInfo/RememberUserInfo.php | 10 +-- vagrant/config/.gitignore | 2 - vagrant/config/vagrant-local.example.yml | 22 ----- vagrant/nginx/app.conf | 38 --------- vagrant/nginx/log/.gitignore | 3 - vagrant/provision/always-as-root.sh | 18 ----- vagrant/provision/once-as-root.sh | 71 ---------------- vagrant/provision/once-as-vagrant.sh | 31 ------- 11 files changed, 7 insertions(+), 275 deletions(-) delete mode 100644 Vagrantfile delete mode 100644 vagrant/config/.gitignore delete mode 100644 vagrant/config/vagrant-local.example.yml delete mode 100644 vagrant/nginx/app.conf delete mode 100644 vagrant/nginx/log/.gitignore delete mode 100644 vagrant/provision/always-as-root.sh delete mode 100644 vagrant/provision/once-as-root.sh delete mode 100644 vagrant/provision/once-as-vagrant.sh diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index 5c9e123..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,81 +0,0 @@ -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.dev' -} - -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 diff --git a/helpers/Auth42.php b/helpers/Auth42.php index b57e70b..1f63d96 100644 --- a/helpers/Auth42.php +++ b/helpers/Auth42.php @@ -85,7 +85,7 @@ public function fetchMe($params) ->setHeaders($params); $response = $this->sendRequest($request); - RememberUserInfo\RememberUserInfo::rememberAllToDB($response); + new RememberUserInfo\RememberUserInfo($response); $profileLink = '/pools/'; if (isset($response['cursus_users'])) { diff --git a/helpers/RememberUserInfo/RememberUser.php b/helpers/RememberUserInfo/RememberUser.php index 749e3e7..002ed11 100644 --- a/helpers/RememberUserInfo/RememberUser.php +++ b/helpers/RememberUserInfo/RememberUser.php @@ -22,10 +22,12 @@ protected function norminate() { $this->responseSubset['lastloc'] = date('Y-m-d H:i:s'); $this->responseSubset['howach'] = count($this->responseSubset['achievements']); - $this->responseSubset['visible'] = $this->responseSubset['visible'] ?? 1; $this->responseSubset['needupd'] = 0; $this->responseSubset['kick'] = 0; + $this->responseSubset['campus'] = $this->responseSubset['campus'][0]['name']; + $this->responseSubset['visible'] = ($this->responseSubset['campus'] === 'Kyiv'); + $this->responseSubset['hours'] = 0; // ! Need help $this->responseSubset['lasthours'] = 0; // ! Need help diff --git a/helpers/RememberUserInfo/RememberUserInfo.php b/helpers/RememberUserInfo/RememberUserInfo.php index 335688c..8b07fa9 100644 --- a/helpers/RememberUserInfo/RememberUserInfo.php +++ b/helpers/RememberUserInfo/RememberUserInfo.php @@ -5,21 +5,17 @@ use Yii; /** - * Fills `cursus_users`, `skills`, `projects_users`, `achievements` and `xlogin` tables of cheatera's database - * .json given from 42 RESTfull API -- $response + * Fills `cursus_users`, `skills`, `projects_users`, `achievements` and `xlogin` tables of cheatera's database + * by response from OAuth2, 42API, when user login */ class RememberUserInfo { /** * rememberAllToDB - * * @param array $response - .json given from 42 RESTfull API converted to php array - * - * @return void - * @throws \Exception */ - public static function rememberAllToDB($response) + public function __construct($response) { if ($response === null) { return ; diff --git a/vagrant/config/.gitignore b/vagrant/config/.gitignore deleted file mode 100644 index 0685a56..0000000 --- a/vagrant/config/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# local configuration -vagrant-local.yml \ No newline at end of file diff --git a/vagrant/config/vagrant-local.example.yml b/vagrant/config/vagrant-local.example.yml deleted file mode 100644 index 919aec0..0000000 --- a/vagrant/config/vagrant-local.example.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Your personal GitHub token -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 diff --git a/vagrant/nginx/app.conf b/vagrant/nginx/app.conf deleted file mode 100644 index 08ec5bb..0000000 --- a/vagrant/nginx/app.conf +++ /dev/null @@ -1,38 +0,0 @@ -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.dev; - 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; - } -} diff --git a/vagrant/nginx/log/.gitignore b/vagrant/nginx/log/.gitignore deleted file mode 100644 index c0fbfdd..0000000 --- a/vagrant/nginx/log/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -#nginx logs -yii2basic.access.log -yii2basic.error.log \ No newline at end of file diff --git a/vagrant/provision/always-as-root.sh b/vagrant/provision/always-as-root.sh deleted file mode 100644 index e5d8e33..0000000 --- a/vagrant/provision/always-as-root.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/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 diff --git a/vagrant/provision/once-as-root.sh b/vagrant/provision/once-as-root.sh deleted file mode 100644 index 12165b1..0000000 --- a/vagrant/provision/once-as-root.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/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 "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 diff --git a/vagrant/provision/once-as-vagrant.sh b/vagrant/provision/once-as-vagrant.sh deleted file mode 100644 index 8da4721..0000000 --- a/vagrant/provision/once-as-vagrant.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 From 330ae1783aab3518ae5af3d248fdf81785e01268 Mon Sep 17 00:00:00 2001 From: vbrazas Date: Tue, 23 Apr 2019 00:11:16 +0300 Subject: [PATCH 3/7] [#129] Fixed documentation in helpers/RememberUserInfo/ --- helpers/RememberUserInfo/RememberHelper.php | 38 ++----------------- helpers/RememberUserInfo/RememberUserInfo.php | 1 + 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/helpers/RememberUserInfo/RememberHelper.php b/helpers/RememberUserInfo/RememberHelper.php index 02a54e7..b712b42 100644 --- a/helpers/RememberUserInfo/RememberHelper.php +++ b/helpers/RememberUserInfo/RememberHelper.php @@ -21,21 +21,18 @@ abstract class RememberHelper /** * init - * * @return void */ abstract protected function init(); /** * remember - * * @return void */ abstract protected function remember(); /** * norminate - * * @return void */ abstract protected function norminate(); @@ -43,9 +40,8 @@ abstract protected function norminate(); /** * __construct - method will done all work children of the class created for * @param array $response - .json given from 42 RESTfull API converted to php array - * @throws \Exception * @see app\helpers\RememberUserInfo\RememberUserInfo - * + * @throws \Exception - in case of db error */ public function __construct(&$response) { @@ -61,12 +57,9 @@ public function __construct(&$response) /** * isArraysIdentical - * * @param array $a1 * @param array $a2 * @param array $arrayKeysToCompare - * - * @return bool */ public static function isArraysIdentical($a1, $a2, $arrayKeysToCompare) { @@ -80,10 +73,7 @@ public static function isArraysIdentical($a1, $a2, $arrayKeysToCompare) /** * setTrueFalse - * * @param bool reference $varToSetTrueFalse - * - * @return void */ public static function setTrueFalse(&$varToSetTrueFalse) { @@ -92,10 +82,7 @@ public static function setTrueFalse(&$varToSetTrueFalse) /** * setNULLtoZero - * * @param array reference $arrToSetZeros - * - * @return void */ public static function setNULLtoZero(&$arrToSetZeros) { @@ -106,10 +93,7 @@ public static function setNULLtoZero(&$arrToSetZeros) /** * dateToSqlFormat - * * @param string $date - * - * @return void */ public static function dateToSqlFormat(&$date) { @@ -120,11 +104,8 @@ public static function dateToSqlFormat(&$date) /** * swapKeysInArr - * * @param array reference $arrToChangeKeys * @param array $keys - * - * @return void */ public static function swapKeysInArr(&$arrToChangeKeys, $keys) { @@ -136,11 +117,8 @@ public static function swapKeysInArr(&$arrToChangeKeys, $keys) /** * mergeChildArrByKey - * * @param array $arr * @param mixed $key - $arr's valid key - * - * @return void */ public static function mergeChildArrByKey(&$arr, $key) { @@ -153,9 +131,7 @@ public static function mergeChildArrByKey(&$arr, $key) /** * findARbyId - * * @param array $arrToPutIntoDb - * * @return mixed|bool */ protected function findARbyId($arrToPutIntoDb) @@ -172,7 +148,6 @@ protected function findARbyId($arrToPutIntoDb) /** * batchInsert - * * @return bool|void */ protected function batchInsert() @@ -188,7 +163,6 @@ protected function batchInsert() /** * batchUpdate - * * @return bool|void */ protected function batchUpdate() @@ -204,7 +178,6 @@ protected function batchUpdate() /** * batchDelete - * * @return bool|void */ protected function batchDelete() @@ -220,9 +193,7 @@ protected function batchDelete() /** * updateDB - * - * @return void - * @throws \Exception + * @throws \Exception - in case of db error */ protected function updateDB() { @@ -240,10 +211,7 @@ protected function updateDB() /** * saveChangesToDB - * - * @param mixed $arrToPutIntoDb - * - * @return void + * @param array $arrToPutIntoDb */ protected function saveChangesToDB($arrToPutIntoDb) { diff --git a/helpers/RememberUserInfo/RememberUserInfo.php b/helpers/RememberUserInfo/RememberUserInfo.php index 8b07fa9..47ad442 100644 --- a/helpers/RememberUserInfo/RememberUserInfo.php +++ b/helpers/RememberUserInfo/RememberUserInfo.php @@ -14,6 +14,7 @@ class RememberUserInfo /** * rememberAllToDB * @param array $response - .json given from 42 RESTfull API converted to php array + * @throws \Exception - in case of db error */ public function __construct($response) { From f415581973b703b2aa4889d096c6cd9998c755ea Mon Sep 17 00:00:00 2001 From: vbrazas Date: Tue, 23 Apr 2019 00:29:25 +0300 Subject: [PATCH 4/7] [#129] refactored all Remember subclasses --- .../RememberUserInfo/RememberAchievements.php | 18 +++++------------ helpers/RememberUserInfo/RememberCurses.php | 18 +++++------------ helpers/RememberUserInfo/RememberHelper.php | 9 +-------- helpers/RememberUserInfo/RememberProjects.php | 18 +++++------------ helpers/RememberUserInfo/RememberSkills.php | 20 +++++-------------- helpers/RememberUserInfo/RememberUser.php | 16 +++++---------- 6 files changed, 26 insertions(+), 73 deletions(-) diff --git a/helpers/RememberUserInfo/RememberAchievements.php b/helpers/RememberUserInfo/RememberAchievements.php index 02bcce0..a9577ed 100644 --- a/helpers/RememberUserInfo/RememberAchievements.php +++ b/helpers/RememberUserInfo/RememberAchievements.php @@ -13,12 +13,16 @@ protected function init() $this->responseSubset = $this->response['achievements']; $this->model = 'app\models\Achievements'; $this->idcol = 'aid'; + + $this->ARcollection = $this->model::find() + ->where(['xlogin' => $this->xlogin]) + ->all(); } /** * {@inheritdoc} */ - protected function norminate() + protected function remember() { foreach ($this->responseSubset as &$achievement) { $achievement['xlogin'] = $this->xlogin; @@ -27,19 +31,7 @@ protected function norminate() self::swapKeysInArr($achievement, [ 'id' => 'aid' ]); $achievement['description'] = htmlentities($achievement['description']); $achievement['visible'] = $achievement['visible'] ?? 'True'; - } - } - - /** - * {@inheritdoc} - */ - protected function remember() - { - $this->ARcollection = $this->model::find() - ->where(['xlogin' => $this->xlogin]) - ->all(); - foreach ($this->responseSubset as $achievement) { self::saveChangesToDB($achievement); } } diff --git a/helpers/RememberUserInfo/RememberCurses.php b/helpers/RememberUserInfo/RememberCurses.php index b1f7805..c9ea30e 100644 --- a/helpers/RememberUserInfo/RememberCurses.php +++ b/helpers/RememberUserInfo/RememberCurses.php @@ -13,12 +13,16 @@ protected function init() $this->responseSubset = $this->response['cursus_users']; $this->model = 'app\models\Curses'; $this->idcol = 'cursus_users_id'; + + $this->ARcollection = $this->model::find() + ->where([ 'xlogin' => $this->xlogin ]) + ->all(); } /** * {@inheritdoc} */ - protected function norminate() + protected function remember() { foreach ($this->responseSubset as &$curs) { unset($curs['user']); @@ -32,19 +36,7 @@ protected function norminate() $curs['xid'] = $this->xid; self::setTrueFalse($curs['has_coalition']); $curs['grade'] = $curs['grade'] ?? 'None'; - } - } - - /** - * {@inheritdoc} - */ - protected function remember() - { - $this->ARcollection = $this->model::find() - ->where([ 'xlogin' => $this->xlogin ]) - ->all(); - foreach ($this->responseSubset as $curs) { $this->saveChangesToDB($curs); } } diff --git a/helpers/RememberUserInfo/RememberHelper.php b/helpers/RememberUserInfo/RememberHelper.php index b712b42..0f81f6d 100644 --- a/helpers/RememberUserInfo/RememberHelper.php +++ b/helpers/RememberUserInfo/RememberHelper.php @@ -31,12 +31,6 @@ abstract protected function init(); */ abstract protected function remember(); - /** - * norminate - * @return void - */ - abstract protected function norminate(); - /** * __construct - method will done all work children of the class created for * @param array $response - .json given from 42 RESTfull API converted to php array @@ -48,9 +42,8 @@ public function __construct(&$response) $this->response =& $response; $this->xlogin = $response['login']; $this->xid = $response['id']; - $this->init(); - $this->norminate(); + $this->init(); $this->remember(); $this->updateDB(); } diff --git a/helpers/RememberUserInfo/RememberProjects.php b/helpers/RememberUserInfo/RememberProjects.php index 928ab89..51a9ffa 100644 --- a/helpers/RememberUserInfo/RememberProjects.php +++ b/helpers/RememberUserInfo/RememberProjects.php @@ -13,12 +13,16 @@ protected function init() $this->responseSubset = $this->response['projects_users']; $this->model = 'app\models\ProjectsAll'; $this->idcol = 'puid'; + + $this->ARcollection = $this->model::find() + ->where(['xlogin' => $this->xlogin]) + ->all(); } /** * {@inheritdoc} */ - protected function norminate() + protected function remember() { foreach ($this->responseSubset as &$project) { $project['xlogin'] = $this->xlogin; @@ -32,19 +36,7 @@ protected function norminate() self::mergeChildArrByKey($project, 'project'); self::swapKeysInArr($project, [ 'id' => 'project_id' ]); self::setNULLtoZero($project); - } - } - - /** - * {@inheritdoc} - */ - protected function remember() - { - $this->ARcollection = $this->model::find() - ->where(['xlogin' => $this->xlogin]) - ->all(); - foreach ($this->responseSubset as $project) { $this->saveChangesToDB($project); } } diff --git a/helpers/RememberUserInfo/RememberSkills.php b/helpers/RememberUserInfo/RememberSkills.php index 12550d7..c6628de 100644 --- a/helpers/RememberUserInfo/RememberSkills.php +++ b/helpers/RememberUserInfo/RememberSkills.php @@ -13,12 +13,16 @@ protected function init() $this->responseSubset = $this->response['cursus_users']; $this->model = 'app\models\Skills'; $this->idcol = 'skills_id'; + + $this->ARcollection = $this->model::find() + ->where([ 'xlogin' => $this->xlogin ]) + ->all(); } /** * {@inheritdoc} */ - protected function norminate() + protected function remember() { foreach ($this->responseSubset as &$cursus) { foreach ($cursus['skills'] as &$skill) { @@ -26,21 +30,7 @@ protected function norminate() $skill['cursus_id'] = $cursus['cursus_id']; self::swapKeysInArr($skill, [ 'id' => 'skills_id', 'name' => 'skills_name', 'level' => 'skills_level' ]); $skill['skills_name'] = htmlentities($skill['skills_name']); - } - } - } - - /** - * {@inheritdoc} - */ - protected function remember() - { - $this->ARcollection = $this->model::find() - ->where([ 'xlogin' => $this->xlogin ]) - ->all(); - foreach ($this->responseSubset as $cursus) { - foreach ($cursus['skills'] as $skill) { self::saveChangesToDB($skill); } } diff --git a/helpers/RememberUserInfo/RememberUser.php b/helpers/RememberUserInfo/RememberUser.php index 002ed11..49becee 100644 --- a/helpers/RememberUserInfo/RememberUser.php +++ b/helpers/RememberUserInfo/RememberUser.php @@ -13,12 +13,16 @@ protected function init() $this->responseSubset = $this->response; $this->model = 'app\models\Show'; $this->idcol = 'xid'; + + $this->ARcollection = $this->model::find() + ->where([ 'login' => $this->responseSubset['login'] ]) + ->all(); } /** * {@inheritdoc} */ - protected function norminate() + protected function remember() { $this->responseSubset['lastloc'] = date('Y-m-d H:i:s'); $this->responseSubset['howach'] = count($this->responseSubset['achievements']); @@ -33,16 +37,6 @@ protected function norminate() self::swapKeysInArr($this->responseSubset, [ 'id' => 'xid', 'staff?' => 'staff' ]); self::setTrueFalse($this->responseSubset['staff']); - } - - /** - * {@inheritdoc} - */ - protected function remember() - { - $this->ARcollection = $this->model::find() - ->where([ 'login' => $this->responseSubset['login'] ]) - ->all(); $this->saveChangesToDB($this->responseSubset); } From ae86788ed31aee44ebe0fb0a4c2c835750bf4b94 Mon Sep 17 00:00:00 2001 From: vbrazas Date: Tue, 23 Apr 2019 00:39:07 +0300 Subject: [PATCH 5/7] [#129] now RememberUser is working properly, but I still need to know where to find the kick, hours and lasthours! --- helpers/RememberUserInfo/RememberUser.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/helpers/RememberUserInfo/RememberUser.php b/helpers/RememberUserInfo/RememberUser.php index 49becee..8ebc28b 100644 --- a/helpers/RememberUserInfo/RememberUser.php +++ b/helpers/RememberUserInfo/RememberUser.php @@ -24,16 +24,18 @@ protected function init() */ protected function remember() { + $user = $this->ARcollection[$this->findARbyId($this->ARcollection)]; + $this->responseSubset['lastloc'] = date('Y-m-d H:i:s'); $this->responseSubset['howach'] = count($this->responseSubset['achievements']); - $this->responseSubset['needupd'] = 0; - $this->responseSubset['kick'] = 0; $this->responseSubset['campus'] = $this->responseSubset['campus'][0]['name']; $this->responseSubset['visible'] = ($this->responseSubset['campus'] === 'Kyiv'); - $this->responseSubset['hours'] = 0; // ! Need help - $this->responseSubset['lasthours'] = 0; // ! Need help + $this->responseSubset['needupd'] = 0; + $this->responseSubset['kick'] = $user->kick ?? 0; // ! Need help + $this->responseSubset['hours'] = $user->hours ?? 0; // ! Need help + $this->responseSubset['lasthours'] = $user->lasthours ?? 0; // ! Need help self::swapKeysInArr($this->responseSubset, [ 'id' => 'xid', 'staff?' => 'staff' ]); self::setTrueFalse($this->responseSubset['staff']); From eed93a2c77708b4695fbf92090a7488842c8a239 Mon Sep 17 00:00:00 2001 From: vbrazas Date: Wed, 24 Apr 2019 12:40:32 +0300 Subject: [PATCH 6/7] [#129] fixed last issues, ready to deploy --- .gitignore | 8 +++++--- helpers/RememberUserInfo/RememberUser.php | 7 ++++--- web/index.php | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 9ff59a0..8fb4d4d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,12 +24,10 @@ composer.phar # phpunit itself is not needed phpunit.phar + # local phpunit config /phpunit.xml -/.vagrant -.env - # yii2 dirs /web/assets assets @@ -48,3 +46,7 @@ tests/_support/_generated # to include !assets/AppAsset.php + +# files to exclude +.env +index.php diff --git a/helpers/RememberUserInfo/RememberUser.php b/helpers/RememberUserInfo/RememberUser.php index 8ebc28b..f86fd78 100644 --- a/helpers/RememberUserInfo/RememberUser.php +++ b/helpers/RememberUserInfo/RememberUser.php @@ -33,9 +33,10 @@ protected function remember() $this->responseSubset['visible'] = ($this->responseSubset['campus'] === 'Kyiv'); $this->responseSubset['needupd'] = 0; - $this->responseSubset['kick'] = $user->kick ?? 0; // ! Need help - $this->responseSubset['hours'] = $user->hours ?? 0; // ! Need help - $this->responseSubset['lasthours'] = $user->lasthours ?? 0; // ! Need help + $this->responseSubset['kick'] = $user->kick ?? 0; // ! Need some refactor + $this->responseSubset['location'] = $user->location ?? 0; // ! Need some refactor + $this->responseSubset['hours'] = $user->hours ?? 0; // ! Need some refactor + $this->responseSubset['lasthours'] = $user->lasthours ?? 0; // ! Need some refactor self::swapKeysInArr($this->responseSubset, [ 'id' => 'xid', 'staff?' => 'staff' ]); self::setTrueFalse($this->responseSubset['staff']); diff --git a/web/index.php b/web/index.php index 2970474..2db4f81 100644 --- a/web/index.php +++ b/web/index.php @@ -7,9 +7,9 @@ $dotenv->load(); // comment out the following two lines when deployed to production -defined('YII_DEBUG') or define('YII_DEBUG', getenv('YII_DEBUG')); -defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV')); -defined('YII_ENV_DEV') or define('YII_ENV_DEV', getenv('YII_ENV_DEV')); +defined('YII_DEBUG') or define('YII_DEBUG', getenv('YII_DEBUG', 'false')); +defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV', 'prod')); +defined('YII_ENV_DEV') or define('YII_ENV_DEV', getenv('YII_ENV_DEV', 'false')); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); From 91e34ebd6051b934f1b67b1ed313ffaa44f6b7e7 Mon Sep 17 00:00:00 2001 From: vbrazas Date: Wed, 24 Apr 2019 13:02:48 +0300 Subject: [PATCH 7/7] [#129] CHANGELOG.md changed --- CHANGELOG.md | 1 + views/corrections/index.php | 6 ------ views/show/view.php | 4 ++-- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25eb5f4..c54f442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Cheatera Change Log ------------------------ +- Issue #129 BUG: #66 fix - Issue #66 FEATURE: Добавить обновление данных о пользователе в БД при логине - Issue #102 FEATURE: Добавить камеры с marvin.unit.ua - Issue #64 FEATURE: Добавить просмотры групп по проектам diff --git a/views/corrections/index.php b/views/corrections/index.php index fe81781..142ba1e 100644 --- a/views/corrections/index.php +++ b/views/corrections/index.php @@ -70,10 +70,4 @@ - '; - // var_export( ); - // echo ''; - ?> - diff --git a/views/show/view.php b/views/show/view.php index 65ae687..80abe54 100644 --- a/views/show/view.php +++ b/views/show/view.php @@ -52,9 +52,9 @@

Profile

user->identity->username) { if(\app\models\Friend::check($model['login'])) { ?> - + - +