<commit_before><?php

namespace app\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\UploadedFile;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;
use app\models\DictionaryForm;
use app\models\Dictionary;
use app\models\WiwShift;
use app\models\WiwUser;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use GuzzleHttp\Client;

class SiteController extends Controller
{
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'contact', 'about'],
                'rules' => [
                    [
                        'actions' => ['logout'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    public function actionIndex()
    {
        $arr = [
            'facebook'      => 'https://facebook.com/xerxes333',
            'twitter'       => 'https://twitter.com/xerxes333',
            'instagram'     => 'https://instagram.com/xerxes333',
            'pinterest'     => 'https://pinterest.com/jdraxler',
            'stackoverflow' => 'https://stackoverflow.com/users/1332233/xerxes333',
            'github'        => 'https://github.com/xerxes333',
            'bitbucket'     => 'https://bitbucket.com/xerxes333',
            'linkedin'      => 'https://www.linkedin.com/pub/jeremy-draxler/11/b76/309',
        ];
        
        
        // messing with Guzzle
        $client = new Client([
            'base_uri' => 'http://dictionary.dev/',
            'headers' => [
                'Accept'     => 'application/json',
            ]
        ]);
        $response = $client->get('dictionary');
        $body = json_decode($response->getBody());
        
        $d = Dictionary::find()->all();
        
        
        /**
         *
         *  
The API must follow REST specification:

POST should be used to create
GET should be used to read
PUT should be used to update (and optionally to create)
DELETE should be used to delete

GET As an employee, I want to know when I am working, by being able to see all of the shifts assigned to me.
GET As an employee, I want to know who I am working with, by being able see the employees that are working during the same time period as me.
GET As an employee, I want to know how much I worked, by being able to get a summary of hours worked for each week.
GET As an employee, I want to be able to contact my managers, by seeing manager contact information for my shifts.


GET As a manager, I want to see the schedule, by listing shifts within a specific time period.
GET As a manager, I want to contact an employee, by seeing employee details.

POST/PUT As a manager, I want to schedule my employees, by creating shifts for any employee.
PUT As a manager, I want to be able to change a shift, by updating the time details.
PUT As a manager, I want to be able to assign a shift, by changing the employee that will work a shift.

         
         * 
         * 
         * 
         */
         
        // quick and dirty shift table propigation
        $this->generateRandomShifts();        


        return $this->render('index',[
            'social' => $arr,
        ]);
    }

	public function generateRandomShifts(){
	        for ($i=1; $i <= 31; $i++) {
        	
			// gets 5 random employees
        	$emps = range(1,10);
			shuffle($emps);
            $emp = array_splice($emps,0,5);
			
			$mgr = rand(11,15);
			$month  = 8;
			$day	= $i;
            $year   = 2015;
            
			
			foreach ($emps as $key => $emp) {
				$start  = rand(0,23);
				$shiftLen = rand(2,6);
				
				if($start + $shiftLen > 23){
					$end = $start;
					$start = $end - $shiftLen;
				} else {
					$end = $start + $shiftLen;
				}
				
				// save to shifts
	            $x = new WiwShift();
	            $x->attributes = [
	                'manager_id'    => $mgr,
	                'employee_id'   => $emp,
	                'start_time'    => "{$year}-{$month}-{$day} {$start}:00:00",
	                'end_time'      => "{$year}-{$month}-{$day} {$end}:00:00",
	                'created_at'    => date("Y-m-d H:i:s")
	            ];
	            // $x->save();
				
			}
			
			
        }
	}
    
    public function actionDictionary()
    {
        $model  = new DictionaryForm();
        
        if (Yii::$app->request->isPost) {
            
            $model->load(Yii::$app->request->post());
            $model->dictionaryFile = UploadedFile::getInstance($model, 'dictionaryFile');
            if($model->process())
            	 Yii::$app->session->setFlash('success', 'Success! See below for output files.');
            
            
        } else {
            // set the default params
            $model->seqLength = 4;
            $model->appearance = 1;
        }
        
        return $this->render('dictionary',[
            'model'    => $model,
        ]);
    }


    public function actionDownload($name = "none"){
        $path = Url::to('@app/uploads/');
        $file = $path . $name;
        
        if (file_exists($file))
            return Yii::$app->response->sendFile($file);
        else
            return $this->goHome();
        
    }





    public function actionLogin()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goBack();
        } else {
            return $this->render('login', [
                'model' => $model,
            ]);
        }
    }

    public function actionLogout()
    {
        Yii::$app->user->logout();

        return $this->goHome();
    }

    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();
        } else {
            return $this->render('contact', [
                'model' => $model,
            ]);
        }
    }

    public function actionAbout()
    {
        return $this->render('about');
    }
}
<commit_msg>clean up db table propagation<commit_after><?php

namespace app\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\UploadedFile;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;
use app\models\DictionaryForm;
use app\models\Dictionary;
use app\models\WiwShift;
use app\models\WiwUser;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use GuzzleHttp\Client;

class SiteController extends Controller
{
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'contact', 'about'],
                'rules' => [
                    [
                        'actions' => ['logout'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    public function actionIndex()
    {
        $arr = [
            'facebook'      => 'https://facebook.com/xerxes333',
            'twitter'       => 'https://twitter.com/xerxes333',
            'instagram'     => 'https://instagram.com/xerxes333',
            'pinterest'     => 'https://pinterest.com/jdraxler',
            'stackoverflow' => 'https://stackoverflow.com/users/1332233/xerxes333',
            'github'        => 'https://github.com/xerxes333',
            'bitbucket'     => 'https://bitbucket.com/xerxes333',
            'linkedin'      => 'https://www.linkedin.com/pub/jeremy-draxler/11/b76/309',
        ];
        
        
        // messing with Guzzle
        $client = new Client([
            'base_uri' => 'http://dictionary.dev/',
            'headers' => [
                'Accept'     => 'application/json',
            ]
        ]);
        $response = $client->get('dictionary');
        $body = json_decode($response->getBody());
        
        $d = Dictionary::find()->all();
        
        
        /**
         *
         *  
The API must follow REST specification:

POST should be used to create
GET should be used to read
PUT should be used to update (and optionally to create)
DELETE should be used to delete

GET As an employee, I want to know when I am working, by being able to see all of the shifts assigned to me.
GET As an employee, I want to know who I am working with, by being able see the employees that are working during the same time period as me.
GET As an employee, I want to know how much I worked, by being able to get a summary of hours worked for each week.
GET As an employee, I want to be able to contact my managers, by seeing manager contact information for my shifts.


GET As a manager, I want to see the schedule, by listing shifts within a specific time period.
GET As a manager, I want to contact an employee, by seeing employee details.

POST/PUT As a manager, I want to schedule my employees, by creating shifts for any employee.
PUT As a manager, I want to be able to change a shift, by updating the time details.
PUT As a manager, I want to be able to assign a shift, by changing the employee that will work a shift.

         
         * 
         * 
         * 
         */
         
        // quick and dirty shift table propigation
        // $this->generateRandomShifts();        


        return $this->render('index',[
            'social' => $arr,
        ]);
    }

	public function generateRandomShifts(){
	        for ($i=1; $i <= 31; $i++) {
        	
			// gets 5 random employees
        	$emps = range(1,10);
			shuffle($emps);
            $emp = array_splice($emps,0,5);
			
			$mgr = rand(11,15);
			$month  = 8;
			$day	= $i;
            $year   = 2015;
            
			
			foreach ($emps as $key => $emp) {
				$start  = rand(0,23);
				$shiftLen = rand(2,6);
				
				if($start + $shiftLen > 23){
					$end = $start;
					$start = $end - $shiftLen;
				} else {
					$end = $start + $shiftLen;
				}
				
				// save to shifts
	            $x = new WiwShift();
	            $x->attributes = [
	                'manager_id'    => $mgr,
	                'employee_id'   => $emp,
	                'start_time'    => "{$year}-{$month}-{$day} {$start}:00:00",
	                'end_time'      => "{$year}-{$month}-{$day} {$end}:00:00",
	                'created_at'    => date("Y-m-d H:i:s")
	            ];
	            $x->save();
				
			}
			
			
        }
	}
    
    public function actionDictionary()
    {
        $model  = new DictionaryForm();
        
        if (Yii::$app->request->isPost) {
            
            $model->load(Yii::$app->request->post());
            $model->dictionaryFile = UploadedFile::getInstance($model, 'dictionaryFile');
            if($model->process())
            	 Yii::$app->session->setFlash('success', 'Success! See below for output files.');
            
            
        } else {
            // set the default params
            $model->seqLength = 4;
            $model->appearance = 1;
        }
        
        return $this->render('dictionary',[
            'model'    => $model,
        ]);
    }


    public function actionDownload($name = "none"){
        $path = Url::to('@app/uploads/');
        $file = $path . $name;
        
        if (file_exists($file))
            return Yii::$app->response->sendFile($file);
        else
            return $this->goHome();
        
    }





    public function actionLogin()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goBack();
        } else {
            return $this->render('login', [
                'model' => $model,
            ]);
        }
    }

    public function actionLogout()
    {
        Yii::$app->user->logout();

        return $this->goHome();
    }

    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();
        } else {
            return $this->render('contact', [
                'model' => $model,
            ]);
        }
    }

    public function actionAbout()
    {
        return $this->render('about');
    }
}

{'fraction_non_alphanumeric': 0.1418223960596842, 'fraction_numerical': 0.009705924960162248, 'mean_word_length': 1.6055859596150217, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 167, 'https://': 16, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4913684', 'n_tokens_mistral': 4262, 'n_tokens_neox': 3936, 'n_words': 1014}