Наследование: extends yii\web\Controller
Пример #1
0
 /**
  * @dataProvider pSync
  * 
  * ACTION MUST:
  * 
  * 1. not allow changes of book_guid, created and updated date, filename
  * 2. generate filename based on title
  * 3. generate updated_date
  * 4. rename file if sync is ON
  */
 public function test_action_Manage_Edit($sync)
 {
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $book = $this->books['insert'][0];
     $book_expected = $this->books['expected'][0];
     $filename_expected = $filename_old = \Yii::$app->mycfg->library->directory . $book_expected['filename'];
     file_put_contents($filename_expected, 'sample-data');
     \Yii::$app->mycfg->library->sync = $sync;
     $_POST['oper'] = 'edit';
     $_POST['id'] = $book['book_guid'];
     // CHANGING
     // [ 1 ]
     $_POST['created_date'] = '2000-01-01';
     $_POST['updated_date'] = '2000-01-01';
     $_POST['filename'] = '2000-01-01';
     // [ 2 ]
     $book_expected['filename'] = ", ''title book #1'',  [].";
     // [ 3 ]
     $book_expected['updated_date'] = (new \DateTime())->format('Y-m-d H:i:s');
     $this->controllerSite->runAction('manage');
     /* @var $book_current \yii\db\BaseActiveRecord */
     $book_current = Books::findOne(['book_guid' => $book['book_guid']]);
     //remove seconds, as it fails on slow machines, definely fails on Travis
     $book_expected['updated_date'] = (new \DateTime($book_expected['updated_date']))->format('Y-m-d H:i');
     $book_current['updated_date'] = (new \DateTime($book_current['updated_date']))->format('Y-m-d H:i');
     //var_dump($book_expected,$book_current->getAttributes()); die;
     $this->assertArraySubset($book_expected, $book_current->getAttributes());
     if ($sync) {
         $filename_expected = \Yii::$app->mycfg->library->directory . $book_expected['filename'];
         $this->assertFileNotExists($filename_old);
     }
     $this->assertFileExists($filename_expected);
     $this->assertEquals(file_get_contents($filename_expected), 'sample-data');
 }
Пример #2
0
 /**
  * Удаление комментария
  * @param  integer $id   Идентификатор удаляемой записи
  * @return redirect      После выполнения редиректит на главную.
  */
 public function actionDelete($id)
 {
     //Определение текущего языка
     SiteController::locale();
     //Поиск по идентификатору
     $comment = Comment::findOne($id);
     //В зависимости от успеха удаления, пишет в память сообщение от успехе или лог ошибок
     if ($comment->delete()) {
         Yii::$app->session->setFlash('success', Yii::t('msg/msg', 'Комментарий удален'));
     } else {
         Yii::$app->session->setFlash('errors', $comment->errors);
     }
     return $this->redirect("/");
 }
Пример #3
0
 /**
  * @dataProvider pSync
  * 
  * ACTION MUST:
  * 
  * 1. not allow changes of book_guid, created and updated date, filename
  * 2. generate filename based on title
  * 3. generate updated_date
  * 4. rename file if sync is ON
  */
 public function test_action_Manage_Edit($sync)
 {
     // CONFIGURE
     $book = $this->books['inserted'][0];
     $book_expected = $this->books['expected'][0];
     $filename_expected = $filename_old = \Yii::$app->mycfg->library->directory . $book['filename'];
     file_put_contents($filename_expected, 'sample-data');
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_POST['oper'] = 'edit';
     $_POST['id'] = $book['book_guid'];
     $_POST['created_date'] = '2000-01-01';
     $_POST['updated_date'] = '2000-01-01';
     $_POST['filename'] = '2000-01-01';
     \Yii::$app->mycfg->library->sync = $sync;
     // - - - - - -
     $this->controllerSite->runAction('manage');
     $book_expected['filename'] = ", ''title book #1'',  [].";
     // #1
     // WORKAROUND FOR TRAVIS
     $dt = new \DateTime();
     $dt->setTimezone(new \DateTimeZone(\Yii::$app->getTimeZone()));
     $book_expected['updated_date'] = $dt->format('Y-m-d H:i:s');
     //CHECKING
     /* @var $book_current \yii\db\BaseActiveRecord */
     $book_current = Books::findOne(['book_guid' => $book['book_guid']]);
     // #2
     // WORKAROUND FOR TRAVIS: remove seconds, as it fails on slow machines, definely fails on Travis
     $book_expected['updated_date'] = (new \DateTime($book_expected['updated_date']))->format('Y-m-d H:i');
     $book_current['updated_date'] = (new \DateTime($book_current['updated_date']))->format('Y-m-d H:i');
     // #3
     $book_current_arr = $book_current->getAttributes();
     $keys = array_keys($book_expected);
     foreach ($keys as $k) {
         if ($k == 'filename') {
             // skip filename checks here. checked at #4 below
             continue;
         }
         $this->assertEquals($book_expected[$k], $book_current_arr[$k], "expected '{$k}' doesn't match");
     }
     // #4
     if ($sync) {
         // file rename if sync ON
         $filename_expected = \Yii::$app->mycfg->library->directory . $book_expected['filename'];
         // renamed new
         $this->assertFileNotExists($filename_old);
         // old is not existed
     }
     $this->assertFileExists($filename_expected);
     $this->assertEquals(file_get_contents($filename_expected), 'sample-data');
 }
Пример #4
0
 public function beforeAction($action)
 {
     //echo $action->id;
     if (isset($this->actions[$action->id])) {
         //se o Usuário NÃO tiver acesso
         if (!\Yii::$app->user->can($this->actions[$action->id])) {
             //
             if (\Yii::$app->user->isGuest) {
                 return SiteController::redirect('@web/user/login');
             } else {
                 throw new HttpException(403, 'Acesso negado.');
             }
         }
     } else {
         throw new HttpException(403, 'Acesso negado.');
     }
     return parent::beforeAction($action);
 }
Пример #5
0
 public function run()
 {
     $site = new SiteController();
     switch ($_SERVER["REQUEST_URI"]) {
         case '/':
         case '/home':
             return $site->actionIndex();
             break;
         case '/profile':
             return $site->actionProfile();
             break;
         case '/login':
             return $site->actionLogin();
             break;
         case '/signup':
             return $site->actionSignup();
             break;
         case '/email-unique':
             return $site->actionEmailUnique();
             break;
         case '/verify-password':
             return $site->actionVerifyPassword();
             break;
         case '/logout':
             return $site->actionLogout();
             break;
         case '/400':
             $error = new ErrorController(400);
             return $error->actionIndex();
             break;
         case '/403':
             $error = new ErrorController(403);
             return $error->actionIndex();
             break;
         default:
             $error = new ErrorController(404);
             return $error->actionIndex();
             break;
     }
 }
Пример #6
0
    echo Url::to(['/user/all-order']);
    ?>
 class="btn btn-default">Все заказы <?php 
    echo FA::icon('shopping-basket');
    ?>
</a>
                        </div>
                    <?php 
}
?>
                </div>
            </div>
            <div class="row">
                <div class="col-md-2">
                    <?php 
echo SideNav::widget(['type' => 'primary', 'encodeLabels' => false, 'items' => SiteController::listCategory(ArrayHelper::index(Category::find()->orderBy('name')->asArray()->all(), 'id'))]);
?>

                </div>
                <div class="col-md-10">
                    <div class="panel panel-default">
                        <div id="alert">
                            <?php 
echo AlertWidget::widget();
?>
                        </div>
                        <?php 
echo Breadcrumbs::widget(['links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]);
?>
                        <div class="panel-body">
                            <?php 
Пример #7
0
 public function actionRefresh()
 {
     SiteController::actionReceiver();
     return SiteController::actionLogin();
 }
Пример #8
0
 /**
  * Удаление определенной записи
  * @param  integer $id Идентификатор удаляемой записи
  * @return redirect
  */
 public function actionDelete($id)
 {
     //Определение текущего языка
     SiteController::locale();
     //Поиск задания по идентификатору
     $task = Task::findOne($id);
     //Удаление всех связанных с заданием комментариев
     $commentDeleted = Comment::deleteAll(["task_id" => $id]);
     if ($task->delete()) {
         Yii::$app->session->setFlash('success', Yii::t('msg/msg', 'Запись удалена'));
         return $this->redirect("/");
     } else {
         Yii::$app->session->setFlash('errors', $task->errors);
     }
 }