[ 'class' => AccessControl::className (), 'only' => [ 'logout', 'signup' ], 'rules' => [ [ 'actions' => [ 'signup' ], 'allow' => true, 'roles' => [ '?' ] ], [ '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 ] ]; } public function actionIndex() { $counts = $this->getCounts(); $news = $this->getNews(); $totalRecords = $this->getTotal(); return $this->render ( 'index' ,['counts' => $counts, 'contentleft'=>"", 'contentright' =>$counts, 'news'=>$news, 'totalRecords'=>$totalRecords]); } 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->validate ()) { if ($model->sendEmail ( Yii::$app->params ['adminEmail'] )) { Yii::$app->session->setFlash ( 'success', 'Thank you for contacting us. We will respond to you as soon as possible.' ); } else { Yii::$app->session->setFlash ( 'error', 'There was an error sending email.' ); } return $this->refresh (); } else { return $this->render ( 'contact', [ 'model' => $model ] ); } } public function actionAbout() { return $this->render ( 'about' ); } public function actionGgbn2016() { return $this->render ( 'ggbn2016' ); } public function actionPast() { return $this->render ( 'past/index' ); } public function actionGgbn2014() { return $this->render ( 'past/ggbn2014' ); } public function actionGgbn2012() { return $this->render ( 'past/ggbn2012' ); } public function actionGgbn2011() { return $this->render ( 'past/ggbn2011' ); } public function actionSignup() { $model = new SignupForm (); if ($model->load ( Yii::$app->request->post () )) { if ($user = $model->signup ()) { if (Yii::$app->getUser ()->login ( $user )) { return $this->goHome (); } } } return $this->render ( 'signup', [ 'model' => $model ] ); } public function actionRequestPasswordReset() { $model = new PasswordResetRequestForm (); if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) { if ($model->sendEmail ()) { Yii::$app->getSession ()->setFlash ( 'success', 'Check your email for further instructions.' ); return $this->goHome (); } else { Yii::$app->getSession ()->setFlash ( 'error', 'Sorry, we are unable to reset password for email provided.' ); } } return $this->render ( 'requestPasswordResetToken', [ 'model' => $model ] ); } public function actionResetPassword($token) { try { $model = new ResetPasswordForm ( $token ); } catch ( InvalidParamException $e ) { throw new BadRequestHttpException ( $e->getMessage () ); } if ($model->load ( Yii::$app->request->post () ) && $model->validate () && $model->resetPassword ()) { Yii::$app->getSession ()->setFlash ( 'success', 'New password was saved.' ); return $this->goHome (); } return $this->render ( 'resetPassword', [ 'model' => $model ] ); } public function actionSay($message = 'Hello') { return $this->render ( 'say', [ 'message' => $message ] ); } public function actionSearch() { return $this->redirect ( Yii::$app->getUrlManager ()->createUrl ( [ 'search/query' ] ) ); } public function getCounts() { $connection = new \yii\db\Connection(Yii::$app->db); $connection->open(); $command = $connection->createCommand ( 'SELECT * FROM counts' ); $dataReader = $command->queryAll(); $counts="Samples"; $tmpTaxa=""; $col1=[]; $col2=[]; $col1b=[]; $col2b=[]; foreach ( $dataReader as $row ) { if($row ['kind'] != "Taxa" && $row ['kind'] != "Cultures" && $row ['kind'] != "Specimens" && $row ['kind'] != "Unknown"){ array_push($col1, explode(" samples", $row ['kind'])[0]); array_push($col2, $row ['counts']); //$counts=$counts."
  • " . explode(" samples", $row ['kind'])[0] . " " . $row ['counts'].'
  • '; } if($row ['kind'] == "Cultures" || $row ['kind'] == "Specimens" || $row ['kind'] == "Unknown"){ array_push($col1b, explode(" samples", $row ['kind'])[0]); array_push($col2b, $row ['counts']); //$counts=$counts."
  • " . explode(" samples", $row ['kind'])[0] . " " . $row ['counts'].'
  • '; } if($row ['kind'] == "Taxa") $tmpTaxa="
    " . $row ['kind'] . "
    " . $row ['counts'].'
    '; } $counts.= "
    ".implode("
    ", $col1)."
    "; $counts.= "
    ".implode("
    ", $col2)."
    "; $counts.="Vouchers"; $counts.= "
    ".implode("
    ", $col1b)."
    "; $counts.= "
    ".implode("
    ", $col2b)."
    "; $counts=$counts."Taxa
    ".$tmpTaxa."
    "; Yii::$app->db->close(); // Yii::info("getCounts: ".$counts); return $counts; } public function getTotal() { $connection = new \yii\db\Connection(Yii::$app->db); $connection->open(); $command = $connection->createCommand ( 'SELECT count(occurrenceid) as cnt FROM occurrence' ); $dataReader = $command->queryAll(); $total=0; foreach ( $dataReader as $row ) { $total =$row ['cnt']; } Yii::$app->db->close(); // Yii::info("getCounts: ".$counts); return $total; } function getNews(){ $news = file_get_contents("http://wiki.bgbm.org/dnabankwiki/api.php?action=parse&prop=sections&page=News&format=json"); $jsonnews = json_decode($news); $newsitems = $jsonnews->parse->sections; $news=[]; $year = date ("Y"); foreach ($newsitems as $newsitem){ if (strpos($newsitem->line,strval($year))) array_push($news, [$newsitem->line,"http://wiki.bgbm.org/dnabankwiki/index.php/News#".$newsitem->anchor]); } if(sizeof($news)===0){ //get last year $year--; foreach ($newsitems as $newsitem){ $tmp=$newsitem->line; if (stripos($newsitem->line,strval($year))) array_push($news, [$newsitem->line,"http://wiki.bgbm.org/dnabankwiki/index.php/News#".$newsitem->anchor]); } } return $news; } }