public static function getOne_page($slug) { $options = []; $datas = []; $parent_pages = self::find()->joinWith('page_rel')->where(['page.page_slug' => $slug])->andWhere(['is_archive' => 0])->all(); if (!empty($parent_pages)) { foreach ($parent_pages as $key => $value) { $options['page_data']['id'] = $value->id; $options['page_data']['page_title'] = $value->page_title; $options['page_data']['page_slug'] = $value->page_slug; $options['page_data']['short_desc'] = $value->short_desc; $options['page_data']['page_desc'] = $value->page_desc; $options['page_data']['sort_order'] = $value->sort_order; $options['sort_order'] = $value->sort_order; $options['show_video_icon'] = $value->is_video; $get_page_rels = PageTypeRel::find()->where(['page_id' => $value->id])->one(); if (!empty($get_page_rels)) { $options['page_type'] = $get_page_rels->page_type; } //$options['page_types'] = $value->types; //$options['page_tags'] = $value->tags; $x = 0; $options['page_images'] = array(); $options['page_banner'] = ''; $options['page_thumb'] = ''; $tmp = array(); if (!empty($value->images)) { foreach ($value->images as $key) { $tmp['image'] = Yii::$app->urlManager->createAbsoluteUrl('/') . 'uploads/' . $key->image; $tmp['sort_order'] = $key->sort_order; $tmp['is_gallery'] = $key->is_gallery; $tmp['is_banner'] = $key->is_banner; $tmp['short_desc'] = $key->short_desc; $tmp['short_title'] = $key->short_title; array_push($options['page_images'], $tmp); if ($key->is_banner) { $options['page_banner'] = Yii::$app->urlManager->createAbsoluteUrl('/') . 'uploads/' . $key->image; $options['page_thumb'] = Yii::$app->urlManager->createAbsoluteUrl('/') . 'uploads/thumb/' . $key->image; } if ($key->is_gallery) { $options['page_thumb'] = Yii::$app->urlManager->createAbsoluteUrl('/') . 'uploads/' . $key->image; } $x++; } } foreach ($value->post as $p) { $options['page_post'][$p->id]['data'] = $p; $options['page_post'][$p->id]['images'] = $p->images; } $options['child_pages'] = self::get_child_pages_One_page($value->id, $datas); } } return $options; }
public static function update_page_type_rel($model) { PageTypeRel::deleteAll('page_id = :page_id', [':page_id' => $model->page_id]); foreach ($model->page_type as $key => $value) { $new_model = new PageTypeRel(); $new_model->page_id = $model->page_id; $new_model->page_type = $value; if ($new_model->save()) { } else { throw new NotFoundHttpException('The requested page does not exist.'); } } return true; }
/** * Deletes an existing Page model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { PageSelfRels::updateAll(['parent_page_id' => 0], 'parent_page_id = ' . $id); PageTypeRel::deleteAll(['page_id' => $id]); PageSelfRels::deleteAll(['page_id' => $id]); $images = PageImageRel::findAll(['page_id' => $id]); if (!empty($images)) { foreach ($images as $key => $value) { unlink(\Yii::getAlias('@webroot') . '/uploads/' . $value->image); } } PageImageRel::deleteAll(['page_id' => $id]); MenuPageRels::deleteAll(['page_id' => $id]); MenuPageRels::deleteAll(['parent_page_id' => $id]); Post::deleteAll(['page_id' => $id]); $this->findModel($id)->delete(); return $this->redirect(['index']); }