获取模板函数

public function actionChangetemplate() {
                $status=true;
                $interactive_id=  (int)filter_input(INPUT_POST,'id');//post[id]
                $template_id= (int) filter_input(INPUT_POST, 'mb');            
		//找到页
		$interactives = Interactives::model ()->findByPk ( $interactive_id );
		//获取模板
		$interactiveTemplate = InteractiveTemplate::model ()->findByPk ( $template_id );
		//修改模板
		$interactives->template_id =$template_id;
                $interactives->save();

		// 根据用户选择的模板来设置不同的内容
		$template_info = $interactiveTemplate->template_content;	
		$interactiveContent = new InteractiveContent ();
		$interactivePic = new InteractivePic(); 
		//添加内容,以下根据content进行正则表达式匹配,生成相对应的content
		if (preg_match_all ( '/preview_t_[0-9]+/', $template_info, $arr )) {		
						//删除
			$res = InteractiveContent::model ()->deleteAll ("interactive_id=:ID",array(
					":ID"=>$interactive_id
			) );
			foreach ($arr[0] as $key=>$value){			
			$content = new InteractiveContent ();
			$content->interactive_id =$interactive_id;
			$content->color = "rgba(0,0,0,0.1)";
			$content->content = '<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:24px;\"><strong>文本输入框<\/strong><\/span>\n<\/p>\n<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:16px;\">您可以进行文本输入、复制、黏贴;调整字体大小、颜色、对齐、行间距;也可以对文本框本身设置相应的背景颜色以及透明度。<\/span>\n<\/p>';
			$content->c_time = date ( "y-m-d H:i:s" );
			$ret=$content->save ();
                        if($ret>0)//如果正确,则结果为true
                            $status=$status&true;
                        else
                            $status=$status&false;
			}			
		}
		//添加图片
		if (preg_match_all ( '/preview_p_[0-9]+/', $template_info, $arr )) {                    
			//删除
			$res = InteractivePic::model ()->deleteAll ("interactive_id=:ID",array(
					":ID"=>$_POST ['id']
			) );
			for($i = 1; $i <= count ( $arr[0] ); $i ++) {
				
			$interactivePic = new InteractivePic();
			
			$interactivePic->interactive_id = $_POST ['id'];
			$interactivePic->pic_scale = 2.2;
			$interactivePic->pic_src = "/images/editinteractive/pcover_000.jpg";
			$interactivePic->pic_width = 30;
			$interactivePic->pic_height =30;
			$interactivePic->pic_x = 0;
			$interactivePic->pic_y =0;
			$interactivePic->tag = $i;
			$interactivePic->c_time = date ( "y-m-d H:i:s" );			
			$ret=$interactivePic->save();
                        if($ret>0)//如果正确,则结果为true
                            $status=$status&true;
                        else
                            $status=$status&false;
			}
		}
		
		if (preg_match_all ( '/preview_s1_1_p[0-9]+/', $template_info, $arr )) {
		//删除
			$res = InteractivePic::model ()->deleteAll ("interactive_id=:ID",array(
					":ID"=>$_POST ['id']
			) );
			for($i = 1; $i <= count ( $arr[0] ); $i ++) {
				
			$interactivePic = new InteractivePic();
			
			$interactivePic->interactive_id = $_POST ['id'];
			$interactivePic->pic_scale = 2.2;
			$interactivePic->pic_src = "/images/editinteractive/pcover_000.jpg";
			$interactivePic->pic_width = 33;
			$interactivePic->pic_height =44;
			$interactivePic->pic_x = 33;
			$interactivePic->pic_y =44;
			$interactivePic->tag = 33;
			$interactivePic->c_time = date ( "y-m-d H:i:s" );			
			$ret=$interactivePic->save();
                        if($ret>0)//如果正确,则结果为true
                            $status=$status&true;
                        else
                            $status=$status&false;
			}
		}
		if (preg_match_all ( '/preview_s1_1_t[0-9]+/', $template_info, $arr )) {
		//删除
			$res = InteractiveContent::model ()->deleteAll ("interactive_id=:ID",array(
					":ID"=>$_POST ['id']
			) );
			foreach ($arr[0] as $key=>$value){
			
			$content = new InteractiveContent ();
			$content->interactive_id = $_POST ['id'];
			$content->color = "rgba(0,0,0,0.1)";
			$content->content = '<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:24px;\"><strong>文本输入框<\/strong><\/span>\n<\/p>\n<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:16px;\">您可以进行文本输入、复制、黏贴;调整字体大小、颜色、对齐、行间距;也可以对文本框本身设置相应的背景颜色以及透明度。<\/span>\n<\/p>';
			$content->c_time = date ( "y-m-d H:i:s" );
			$ret=$content->save ();
                        if($ret>0)//如果正确,则结果为true
                            $status=$status&true;
                        else
                            $status=$status&false;
			}
		}
		if (preg_match_all ( '/preview_s1_1_t_[0-9]+/', $template_info, $arr )) {
		//删除
			$res = InteractiveContent::model ()->deleteAll ("interactive_id=:ID",array(
					":ID"=>$_POST ['id']
			) );
			foreach ($arr[0] as $key=>$value){
			
			$content = new InteractiveContent ();
			$content->interactive_id = $_POST ['id'];
			$content->color = "rgba(0,0,0,0.1)";
			$content->content = '<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:24px;\"><strong>文本输入框<\/strong><\/span>\n<\/p>\n<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:16px;\">您可以进行文本输入、复制、黏贴;调整字体大小、颜色、对齐、行间距;也可以对文本框本身设置相应的背景颜色以及透明度。<\/span>\n<\/p>';
			$content->c_time = date ( "y-m-d H:i:s" );
			$ret=$content->save ();
                        if($ret>0)//如果正确,则结果为true
                            $status=$status&true;
                        else
                            $status=$status&false;
			}
		}
		

		if ($status) {
			echo json_encode ( array (
					//success
					'status' => 'success' 
			) );
		} else {
			echo json_encode ( array (
					'status' => 'fail' 
			) );
		}
	}
来源: http://myfetish.cn/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值