/**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     //
     DB::table('tutorials')->delete();
     $faker = Faker\Factory::create();
     $minimum = $this->option('minimum');
     $tutorialcontent = "\n{Far|far|away|behind|the|word|mountains|far|from|the}\n{countries|Vokalia|and|Consonantia|there}\n{live|the|blind|texts|Separated}\n{they|live|in|Bookmarksgrove|right}\n{at|the|coast|of|the}\n{Semantics|a|large|language|ocean}\n{A|small|river|named|Duden}\n{flows|by|their|place|and}\n{supplies|it|with|the|necessary}\n{regelialia|It|is|a|paradisematic}\n{country|in|which|roasted|parts}\n{of|sentences|fly|into|your}\n{mouth|Even|the|all-powerful|Pointing|has|no|control}\n{about|the|blind|texts|it}\n{is|an|almost|unorthographic|life}\n{One|day|however|a|small}\n{line|of|blind|text|by}\n{the|name|of|Lorem|Ipsum}\n{decided|to}";
     $tutorialcontent = $tutorialcontent . $tutorialcontent . $tutorialcontent;
     $tutorialcontent = $tutorialcontent . $tutorialcontent . $tutorialcontent;
     $tutorialtitle = "This is a {title|heading|header}.";
     $tutorialdesc = "This is a sample {data|words|description}";
     for ($i = 1; $i <= $minimum; $i++) {
         $tutorial = new Tutorials();
         $tutorial->name = self::spintax($tutorialtitle);
         $tutorial->subjectid = rand(1, 55);
         $tutorial->createdby = $this->option('user');
         $tutorial->description = self::spintax($tutorialdesc);
         $tutorial->published = 1;
         $tutorial->content = self::spintax($tutorialcontent);
         $tutorial->created_at = self::randDate('10th January 2013', date('jS F o'));
         $tutorial->save();
     }
 }
 /**
  * Are we allowed to add tutorials?
  */
 public function actionaddtutorial()
 {
     if (!Yii::app()->user->checkAccess('op_tutorials_addtutorials')) {
         throw new CHttpException(403, Yii::t('error', 'Sorry, You are not allowed to perform that action.'));
     }
     $model = new Tutorials();
     if (isset($_POST['Tutorials'])) {
         $model->attributes = $_POST['Tutorials'];
         if (!Yii::app()->user->checkAccess('op_tutorials_manage')) {
             // Can we auto approve tutorials for this category?
             $model->status = 0;
             $cat = TutorialsCats::model()->findByPk($model->catid);
             if ($cat) {
                 if ($cat->autoaddperms) {
                     $perms = explode(',', $cat->autoaddperms);
                     if (count($perms)) {
                         foreach ($perms as $perm) {
                             if (Yii::app()->user->checkAccess($perm)) {
                                 $model->status = 1;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
         if ($model->save()) {
             if ($model->status) {
                 Yii::app()->user->setFlash('success', Yii::t('tutorials', 'Tutorial Added.'));
                 $this->redirect(array('/tutorials/view/' . $model->alias, 'lang' => false));
             } else {
                 Yii::app()->user->setFlash('success', Yii::t('tutorials', 'Tutorial Added. It will be displayed once approved.'));
                 $this->redirect('tutorials/index');
             }
         }
     }
     // Grab cats that we can add tutorials to
     $cats = TutorialsCats::model()->getCatsForMember(null, 'add');
     // Make a category selection
     $categories = array();
     foreach ($cats as $cat) {
         $categories[$cat->id] = $cat->title;
     }
     // Add page breadcrumb and title
     $this->pageTitle[] = Yii::t('tutorials', 'Adding Tutorial');
     $this->breadcrumbs[Yii::t('tutorials', 'Adding Tutorial')] = '';
     $this->render('tutorial_form', array('model' => $model, 'label' => Yii::t('tutorials', 'Adding Tutorial'), 'categories' => $categories));
 }
 private function createtutorial($dash)
 {
     $user = Sentry::getUser();
     $userid = Sentry::getUser()->id;
     $teacher = Teacher::findOrFail($user->id);
     $ssubjects = $teacher->extra;
     $subjects = unserialize($ssubjects);
     $truth = self::subjectValidator($user->id, $subjects, Input::get('subject'));
     if ($truth == 0) {
         if (!Sentry::getUser()->inGroup(Sentry::findGroupByName('admin'))) {
             return Redirect::to(URL::previous());
         }
     }
     $tutorial = new Tutorials();
     $tutorial->name = Input::get('title');
     $tutorial->description = Input::get('description');
     $tutorial->content = Input::get('tutorial');
     $tutorial->createdby = Sentry::getUser()->id;
     $tutorial->subjectid = Input::get('subject');
     if (Input::get('published') == 'on') {
         $tutorial->published = 1;
     } else {
         $tutorial->published = 0;
     }
     $tutorial->save();
     $newtutorial = DB::table('tutorials')->orderby('id', 'desc')->first();
     if (Input::hasFile('attachments')) {
         $files = Input::file('attachments');
         foreach ($files as $file) {
             if ($file) {
                 $name = $file->getClientOriginalName();
                 $file->move(app_path() . '/attachments/tutorial-' . $newtutorial->id . '/', $name);
             }
         }
     }
     $newid = $newtutorial->id;
     Cache::forget("tutorial_listing_dash");
     return $newid;
 }
 public function tutorials_save()
 {
     if (Auth::check()) {
         if (Auth::User()->ldap_verified == 0) {
             $messageBag = new MessageBag();
             $messageBag->add('message', "Please Verify Your GPO ID before Uploading a Tutorial");
             return Redirect::Route('user.profile')->with('messages', $messageBag)->withInput();
         } else {
             $user_id = Auth::User()->id;
             $name = Input::get("Name");
             $club = Input::get("Club");
             $file = Input::file("File");
             if (!Input::hasFile("File") || $user_id == "" || $name == "" || $club == "") {
                 $messageBag = new MessageBag();
                 $messageBag->add('message', "Error in form. Fill up all the required fields correctly");
                 return Redirect::back()->with('messages', $messageBag)->withInput();
             }
             if (Input::file("File")->getSize() > 2 * 1024 * 1024) {
                 $messageBag = new MessageBag();
                 $messageBag->add('message', "Files Bigger than 2 MB aren't allowed");
                 return Redirect::back()->with('messages', $messageBag)->withInput();
             }
             $tutorial = new Tutorials();
             $tutorial->name = $name;
             $tutorial->by = intval($user_id);
             $tutorial->club = $club;
             // $tutorial->url = $filename;
             $tutorial->save();
             $destinationPath = public_path() . "/assets/tutorials/";
             $extension = $file->getClientOriginalExtension();
             $filename = $tutorial->id . "." . $extension;
             $file->move($destinationPath, $filename);
             // $tutorial->name = $name;
             // $tutorial->by = intval($user_id);
             // $tutorial->club = $club;
             $tutorial->url = $filename;
             $tutorial->save();
             $messageBag = new MessageBag();
             $messageBag->add('message', "Tutorial successfully uploaded.");
             return Redirect::back()->with('messages', $messageBag)->withInput();
         }
     } else {
         $messageBag = new MessageBag();
         $messageBag->add('message', 'Please Login before Uploading a Tutorial');
         return Redirect::Route('user.profile')->with('messages', $messageBag)->withInput();
     }
 }
 /**
  * Add tutorial action
  */
 public function actionaddtutorial()
 {
     // Perms
     if (!Yii::app()->user->checkAccess('op_tutorials_addtutorials')) {
         throw new CHttpException(403, Yii::t('error', 'Sorry, You don\'t have the required permissions to enter this section'));
     }
     $model = new Tutorials();
     if (isset($_POST['Tutorials'])) {
         $model->attributes = $_POST['Tutorials'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', Yii::t('admintuts', 'Tutorial Added.'));
             $this->redirect(array('viewcategory', 'id' => $model->catid));
         }
     }
     // Adding by cat?
     if (Yii::app()->request->getParam('catid')) {
         $model->catid = Yii::app()->request->getParam('catid');
     }
     // cat list
     $parents = array();
     $parentlist = TutorialsCats::model()->getRootCats();
     if (count($parentlist)) {
         foreach ($parentlist as $row) {
             $parents[$row->id] = $row->title;
         }
     }
     $this->breadcrumbs[Yii::t('admintuts', 'Adding Tutorial')] = '';
     $this->pageTitle[] = Yii::t('admintuts', 'Adding Tutorial');
     // Render
     $this->render('tutorial_form', array('model' => $model, 'parents' => $parents, 'label' => Yii::t('admintuts', 'Adding Tutorial')));
 }