public function checkValue($event)
 {
     $homepage = $this->owner->homepage;
     // Not set as homepage
     if ($homepage == 0) {
         // If no other pages are set as homepage, the owner is automatically
         // set as homepage
         $homepageExists = (bool) Page::find()->where(['homepage' => 1])->count();
         if (!$homepageExists) {
             $this->owner->homepage = 1;
             // The homepage is always a public page
             $this->owner->public = 1;
         }
     } else {
         // The flag for the current homepage has to be unset only if the
         // 'homepage' attribute of the owner changed (meaning that the
         // owner was not already the current homepage)
         if (in_array('homepage', array_keys($this->owner->getDirtyAttributes()))) {
             $currentHomepage = Page::findOne(['homepage' => 1]);
             if ($currentHomepage) {
                 $currentHomepage->homepage = 0;
                 $currentHomepage->save();
             }
         }
         // The homepage is always a public page
         if ($this->owner->public != 1) {
             $this->owner->public = 1;
         }
     }
 }
 /**
  * Returns a page, based on the alias that is provided in the request
  *
  * @return  infoweb\pages\models\Page | null
  */
 public function findRequestedPage()
 {
     // An alias is provided
     if (Yii::$app->request->get('alias')) {
         // Try to load the page with the provided alias
         $page = PageModel::findByAlias(Yii::$app->request->get('alias'), Yii::$app->language)->one();
         if (!$page) {
             return false;
         }
         // No specific page is requested, load the homepage
     } elseif (empty(Yii::$app->request->pathInfo)) {
         // Load the page that is marked as the 'homepage'
         $page = PageModel::findOne(['homepage' => 1]);
         // A custom page is requested and this has to be set in the controller action
     } else {
         return null;
     }
     // The page must be active
     if ($page->active != 1) {
         return false;
     }
     // Load formViewer
     if (is_object(Yii::$app->getModule('pages')) && Yii::$app->getModule('pages')->enableForm && (int) $page->form_id != 0) {
         try {
             $formViewer = new \infoweb\form\helpers\FormViewer((int) $page->form_id);
             $this->setFormViewer($formViewer);
         } catch (Exception $e) {
         }
     }
     return $page;
 }
 /**
  * Returns a page's html anchors
  *
  * @return  json
  */
 public function actionGetPageHtmlAnchors()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $response = ['status' => 0, 'msg' => '', 'anchors' => ['' => Yii::t('infoweb/menu', 'Choose an anchor')]];
     $page = Page::findOne(Yii::$app->request->get('page'));
     if ($page) {
         $response['anchors'] = array_merge($response['anchors'], $page->htmlAnchors);
     }
     $response['status'] = 1;
     return $response;
 }
 /**
  * Finds the Page model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Page the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Page::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'The requested item does not exist'));
     }
 }