Esempio n. 1
0
 public function beforeSave($options = array())
 {
     //parent::beforeSave($options);
     //print_r($this->data);
     $loggedInUser = AuthComponent::user();
     $found = false;
     $userId = $loggedInUser['user_id'];
     $this->data['Post']['post_by'] = $userId;
     $this->data['Post']['post_date'] = (new DateTime())->format('Y-m-d');
     //format('Y-m-d H:i:s')
     if (!empty($this->data['Topic']['topic_subject'])) {
         $str = $this->data['Topic']['topic_subject'];
         $num = $this->data['Post']['post_cat'];
         $subject = new Topic();
         $found = $subject->find('first', array('conditions' => array('Topic.topic_subject LIKE' => $str, 'Topic.topic_cat =' => $num)));
         if (!$found) {
             $subject->create();
             //create topic
             $subject->save(array('topic_subject' => $this->data['Topic']['topic_subject'], 'topic_date' => (new DateTime())->format('Y-m-d'), 'topic_cat' => $this->data['Post']['post_cat'], 'topic_by' => $userId));
             //see also save associated model method cakephp
             $this->data['Post']['post_topic'] = $this->Topic->getLastInsertId();
             return true;
         }
         $this->data['Post']['post_topic'] = $found['Topic']['topic_id'];
         return true;
     }
     //nothing
     return true;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     if (Auth::check()) {
         $data = Input::all();
         $rules = array('Title' => array('required', 'max:30'), 'Content' => array('required', 'max:500'), 'Category' => array('required'));
         $validator = Validator::make($data, $rules);
         if ($validator->fails()) {
             return Redirect::to('newTopic')->withErrors($validator);
         } else {
             $newTitle = Input::get('Title');
             $newContent = Input::get('Content');
             $newCategory = Input::get('Category');
             $user_id = Auth::user()->id;
             $topic = new Topic();
             $topic->title = $newTitle;
             $topic->content = $newContent;
             $topic->category_id = $newCategory;
             $topic->user_id = $user_id;
             $topic->save();
             return Redirect::to('forum');
         }
     } else {
         Redirect::to('login')->withErrors('You must be logged in to create a topic');
     }
 }
 public function run()
 {
     $table = $this->getTable();
     $title = 'Lorem ipsum dolor sit amet';
     $topic = new Topic(['title' => $title]);
     $topic->save();
 }
Esempio n. 4
0
 public function actionNew($groupId = null)
 {
     $data = array("type" => "new", "groupId" => $groupId);
     $data['groups'] = GroupUser::getGroups(GroupUser::find("userId", Rays::user()->id)->join("group")->order_desc("groupId")->all());
     if (Rays::isPost()) {
         $validation = new RValidation(array(array("field" => "title", "label" => "Title", "rules" => "trim|required"), array("field" => "group", "label" => "Group", "rules" => "trim|required|number"), array("field" => "post-content", "label" => "Content", "rules" => "trim|required")));
         if ($validation->run()) {
             $topic = new Topic();
             $topic->groupId = $_POST['group'];
             $topic->userId = Rays::user()->id;
             $topic->title = $_POST["title"];
             $topic->content = RHtml::encode($_POST['post-content']);
             $topic->createdTime = date('Y-m-d H:i:s');
             $topic->lastCommentTime = date('Y-m-d H:i:s');
             $topic->commentCount = 0;
             $topic->save();
             $this->redirectAction('post', 'view', $topic->id);
         } else {
             $data['newPostForm'] = $_POST;
             $data['validation_errors'] = $validation->getErrors();
         }
     }
     $this->layout = 'user';
     $this->addCss('/public/css/post.css');
     $this->setHeaderTitle("New post");
     $this->render("edit", $data, false);
 }
Esempio n. 5
0
 function addTopic($title = 'none')
 {
     $toc = new Topic();
     $toc->tocTitle = $title;
     $toc->tocMax = 4;
     if ($toc->save()) {
         echo $toc->to_json();
     }
 }
Esempio n. 6
0
 public function create()
 {
     foreach ($this->required as $required => $strlen) {
         if (!Input::has($required) || strlen(Input::get($required)) < $strlen) {
             return Response::make(['error' => 'You must introduce a ' . $required . ' with ' . $strlen . ' of length...'], 404);
         }
     }
     $new = new Topic();
     $new->fill(Input::only(['title', 'author', 'message']));
     $new->place = $this->place;
     $new->save();
     return Response::make(['success' => 'You just created a new topic!', 'topic' => $new->toArray()], 404);
 }
Esempio n. 7
0
 public function create()
 {
     if (Request::isMethod('get')) {
         return View::make('forum::topic_create');
     }
     if (Request::isMethod('post')) {
         $new = new Topic();
         $new->fill(Input::only(['title', 'author', 'message']));
         $new->place = Input::has('api') ? 'api' : 'web';
         $new->save();
         return Redirect::to('/forum');
     }
 }
Esempio n. 8
0
 /**
  * Given a list of topic names, return the list of topic ids
  */
 public static function idsFromNames(array $names)
 {
     $ids = [];
     foreach ($names as $name) {
         $topic = static::whereName($name)->first();
         if (!$topic) {
             $topic = new Topic();
             $topic->name = $name;
             $topic->save();
         }
         $ids[] = $topic->id;
     }
     return $ids;
 }
Esempio n. 9
0
function create_account()
{
	global $CONF;
	$user = new RegUser();

	if (!preg_match("/^[".$CONF['nickname_chars']."]+$/i", $_POST['nickname_create_account']))
		return array('ok'=>false, 'error'=>'invalid nickname');

	if (trim($_POST['password_create_account'])=='')
		return array('ok'=>false, 'error'=>'no password');

	$user->setEmail($_POST['email_create_account']);
	$user->setNickname($_POST['nickname_create_account']);
	$user->setPassword($_POST['password_create_account']);
	if (isset($_POST['signature_create_account']))
		$user->setSignature($_POST['signature_create_account']);

	if (isset($_POST['camefrom_create_account']))
		$user->setCameFrom($_POST['camefrom_create_account']);

	$r = $user->save();
	if ($r=='ok')
	{
		$channel=new Channel();
		$channel->setId(1);
		$channel->forceFollow($user);
		$r = $user->sendEmail();
		if (!$r)
			return array('ok'=>false, 'error'=>'we could not send the e-mail.');
		else{
			$GLOBALS['user'] = $user;
			$rc = new RegUser();
			$rc->setNickname("RapidCoffee");
			$rc->load();
			$topic = new Topic();
			$topic->setChannel($channel);
			$topic->setUser($rc);
			$topic->setSubject("Dêem boas vindas ao usuário " . $user->getNickname() . "!");
			$msg = "Seja bem-vindo(a), <b>" . $user->getNickname() . "</b>. Criamos este tópico para que você possa se apresentar e conhecer um pouco dos usuários do site. Boa estadia =)<br /><br />Equipe Rapid Coffee.";
			$msg = str_replace('&nbsp;',' ',$msg);
			$topic->setMsg($msg);
			$topic->save();
			$topic->follow();
			return array('ok'=>true, 'error'=>'');
		}
	}
	return array('ok'=>false, 'error'=>$r);
}
Esempio n. 10
0
 public static function store($group_id)
 {
     self::checkLoggedIn();
     $user = self::getUserLoggedIn();
     $params = $_POST;
     $topic = new Topic(array('title' => $params['title'], 'forum_group_id' => $group_id, 'creator' => $user->id));
     $errors = $topic->errors();
     $message;
     if (count($errors) == 0) {
         $topic->save();
         $message = array('message' => 'Aihe lisätty onnistuneesti');
     } else {
         $message = array('errors' => $errors);
     }
     Redirect::to('/groups/' . $group_id, $message);
 }
Esempio n. 11
0
function update_topic()
{
	global $user;
	global $CONF;

//	if (isset($_SESSION['topic_last_flood_time'])){
//
//		if ((time() - $_SESSION['topic_last_flood_time']) < $CONF['topic_time_to_wait_flood']){
//			$time_to_wait = $CONF['topic_time_to_wait_flood'] - (time() - $_SESSION['topic_last_flood_time']);
//			return array('ok'=>false, 'error'=>'flood '.$time_to_wait);
//		}
//
//	}

	$_SESSION['topic_last_flood_time']=time();

	$user = $_SESSION['user'];	

	$topic = new Topic();
	if (isset($_GET['topicid_update_topic'])){
		$topic->setId($_GET['topicid_update_topic']);
		$topic->load();
		if ( ($user->getId()!=$topic->getUser()->getId()) || ($user->isAnon()!=$topic->getUser()->isAnon()) )
			return array('ok'=>false, 'error'=>'you are not the owner');
	} else {
		return array('ok'=>false, 'error'=>'no id');
	}

	//$subject = strip_tags($_POST['subject']);
	//if (strlen(str_replace(' ', '', $subject)) < $CONF['min_msg_chars'])
	//	return array('ok'=>false, 'error'=>'Too short subject.');
	//$topic->setSubject($subject);

	$msg = unescape_ampersand($_POST['msg_update_topic']);
	if (strlen(str_replace(' ', '', strip_tags($msg))) < $CONF['min_msg_chars'])
		return array('ok'=>false, 'error'=>'Too short message.');

	$msg = strip_tags($msg, $CONF['permitted_tags_msg']);
	$topic->setMsg($msg);

	if ($topic->save()=='ok'){
		//$topic->follow();
		return array('ok'=>true, 'error'=>'');
	}
	else
		return array('ok'=>false, 'error'=>'problems with this topic');
}
Esempio n. 12
0
 public function forumWrite()
 {
     $json = Input::get('json');
     $data = json_decode($json);
     $writer = Student::where('auth', '=', $data->auth)->first();
     $sn = Topic::max('sn') + 1;
     $body = base64_decode($data->body);
     $topic = new Topic();
     $topic->sn = $sn;
     $topic->title = $data->title;
     $topic->stu_id = $writer->id;
     $topic->day = date("Y/m/d");
     $topic->body = $body;
     $topic->view = 0;
     $topic->save();
     return "suc";
 }
Esempio n. 13
0
 public function insertData()
 {
     $gifts = json_decode(file_get_contents(app_path() . '/storage/gifts.txt'));
     $topics = json_decode(file_get_contents(app_path() . '/storage/topics.txt'));
     $gift_posters = json_decode(file_get_contents(app_path() . '/storage/gift_posters.txt'));
     $gift_photo_intros = json_decode(file_get_contents(app_path() . '/storage/gift_photo_intros.txt'));
     foreach ($topics as $topic) {
         $t = new Topic();
         $t->id = $topic->id;
         $t->title = $topic->title;
         $t->content = $topic->content;
         $t->topic_url = $topic->topic_url;
         if (!$t->save()) {
             return 'topic_false';
         }
     }
     foreach ($gifts as $gift) {
         $g = new Gift();
         $g->id = $gift->id;
         $g->topic_id = $gift->topic_id;
         $g->title = $gift->title;
         $g->price = $gift->price;
         $g->content = $gift->content;
         if (!$g->save()) {
             return 'gift_false';
         }
     }
     foreach ($gift_posters as $gift_poster) {
         $tp = new GiftPoster();
         $tp->gift_id = $gift_poster->gift_id;
         $tp->url = $gift_poster->url;
         if (!$tp->save()) {
             return 'gift_poster_false';
         }
     }
     foreach ($gift_photo_intros as $gift_photo_intro) {
         $gpi = new GiftPhotoIntro();
         $gpi->gift_id = $gift_photo_intro->gift_id;
         $gpi->url = $gift_photo_intro->url;
         if (!$gpi->save()) {
             return 'gift_photo_intro_false';
         }
     }
     return Response::json(array('errCode' => 0, 'message' => '插入成功'));
 }
Esempio n. 14
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = array('name' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     // process the login
     if ($validator->fails()) {
         return Redirect::to('topics/create')->withErrors($validator)->withInput(Input::except('password'));
     } else {
         // store
         $topic = new Topic();
         $topic->name = Input::get('name');
         $topic->description = Input::get('description');
         $topic->status = Input::get('status');
         //  $nerd->email      = Input::get('email');
         //  $nerd->nerd_level = Input::get('nerd_level');
         $topic->save();
         // redirect
         Session::flash('message', 'Successfully created topic!');
         return Redirect::to('topics');
     }
 }
Esempio n. 15
0
 /**
  * @param Topic $topic
  * @return boolean
  */
 public function create($topic)
 {
     if ($this->validate()) {
         $user = Yii::$app->getUser()->getIdentity();
         $this->getPost()->topic_id = $topic->id;
         $this->getPost()->message = $this->message;
         $this->getPost()->save();
         $topic->updateCounters(['number_posts' => 1]);
         $topic->last_post_username = $user->username;
         $topic->last_post_created_at = time();
         $topic->last_post_id = $this->getPost()->id;
         $topic->last_post_user_id = $user->id;
         $topic->save();
         $forum = $topic->forum;
         $forum->updateCounters(['number_posts' => 1]);
         $forum->last_post_created_at = time();
         $forum->last_post_user_id = $this->getPost()->id;
         $forum->last_post_username = $user->username;
         $forum->save();
         return true;
     }
     return false;
 }
Esempio n. 16
0
 public function edit($id = 0)
 {
     $obj = new Topic();
     $obj->get_by_id((int) $id);
     if (!$_POST) {
         echo $obj->to_json();
     } else {
         if (isset($_POST['model']) and $model = $_POST['model']) {
             $testid = $this->session->userdata('testid');
             $topic = new Topic();
             $topic->from_json($model);
             $topic->test_id = $testid;
             if ($topic->save()) {
                 echo $topic->to_json();
             } else {
                 echo array('error' => $test->error->string);
             }
         } else {
             if (isset($_POST['_method']) and $_POST['_method'] === 'DELETE') {
                 $obj->delete();
             }
         }
     }
 }
Esempio n. 17
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Topic();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Topic'])) {
         $model->attributes = $_POST['Topic'];
         $start_time = $_POST['Topic']['start_time'];
         $end_time = $_POST['Topic']['end_time'];
         if (!empty($start_time)) {
             $model->start_time = strtotime("{$start_time}");
         }
         if (!empty($end_time)) {
             if ($end_time < $start_time) {
                 $end_time = $start_time;
             }
             $model->end_time = strtotime("{$end_time}");
         }
         $model->create_time = time();
         if ($model->save()) {
             $file = CUploadedFile::getInstance($model, 'img');
             if (isset($file)) {
                 $path = Yii::app()->basePath . '/../images/topic/' . $model->topic_id . '.' . $file->getExtensionName();
                 $file->saveAs($path);
                 $model->img = $model->topic_id . '.' . $file->getExtensionName();
                 $model->saveAttributes(array('img'));
             }
             $users = User::model()->findAll();
             foreach ($users as $user) {
                 Talk::model()->sendMsg(NPC_SYSTEM_USRID, $user->usr_id, "汪汪!宠物星球开展了一个" . $model->topic . "活动!参加的宠物有机会得到礼品哦~羡慕死汪了,快去看看吧~");
             }
             $this->redirect(array('view', 'id' => $model->topic_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Esempio n. 18
0
 /**
  * add
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "topic", "action" => "index"));
     }
     $topic = new Topic();
     $topic->topic = $this->request->getPost("topic");
     $topic->info = $this->request->getPost("info");
     $topic->topictype = $this->request->getPost("topictype");
     $topic->subtime = time();
     $topic->adminname = $this->auth['name'];
     $topic->status = 0;
     if (!$topic->save()) {
         foreach ($topic->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "topic", "action" => "new"));
     }
     $this->flash->success("add success");
     $this->response->redirect("topic/index");
 }
Esempio n. 19
0
    $topic = Topic::find($id);
    $promptrs = $topic->getPromptrs();
    return $app['twig']->render("topic.html.twig", array('topic' => $topic, 'promptrs' => $promptrs));
});
$app->post("/topic/{id}", function ($id) use($app) {
    $topic = Topic::find($id);
    $name = $_POST['name'];
    $promptr = new Promptr($name, $topic->getId());
    $promptr->save();
    $promptrs = Promptr::getAll();
    return $app['twig']->render('topic.html.twig', array('topic' => $topic, 'promptrs' => $promptrs));
});
$app->post("/create-topic", function () use($app) {
    $topic_name = $_POST['topic_name'];
    $topic = new Topic($topic_name);
    $topic->save();
    $promptrs = $topic->getPromptrs();
    return $app['twig']->render("topic.html.twig", array('topic' => $topic, 'promptrs' => $promptrs));
});
$app->get("/promptr/{id}", function ($id) use($app) {
    $promptr = Promptr::find($id);
    $topic_id = $promptr->getTopicId();
    $topic = Topic::find($topic_id);
    return $app['twig']->render('promptr.html.twig', array('promptr' => $promptr, 'questions' => $promptr->getQuestions(), 'topic' => $topic));
});
// PROMPTR.HTML.TWIG
// CONTINUE CREATING NEW PROMPTR ROUTE
$app->post("/promptr/{id}", function ($id) use($app) {
    $promptr = Promptr::find($id);
    $topic = Topic::find($promptr->getTopicId());
    $new_question_text = $_POST['question'];
Esempio n. 20
0
 public function issueTopic()
 {
     if (!Auth::check()) {
         return Response::json(array('errCode' => 1, 'message' => '请登录!'));
     }
     $title = Input::get('title');
     $content = Input::get('content');
     $user_id = Auth::user()->id;
     $validation = Validator::make(array('title' => $title, 'content' => $content), array('title' => 'required', 'content' => 'required'));
     if ($validation->fails()) {
         return Response::json(array('errCode' => 2, 'message' => '信息填写不完整!'));
     }
     //创建用户
     $topic = new Topic();
     $topic->user_id = $user_id;
     $topic->title = $title;
     $topic->content = $content;
     if ($topic->save()) {
         return Response::json(array('errCode' => 0, 'message' => '话题发表成功!'));
     }
     return Response::json(array('errCode' => 2, 'message' => '话题发表失败,请重新发送!'));
 }
 function create($vars, &$errors)
 {
     return Topic::save(0, $vars, $errors);
 }
<?php

include 'admin-config.php';
include 'header.php';
$topic_id = $topic = $active = $error = "";
if (strlen(Request::post("submit"))) {
    $topic_id = Request::post("topic_id");
    $topic = Request::post("topic");
    $active = Validation::getStautsTinyVal(Request::post("active"));
    $topicObj = new Topic();
    $topicObj->set("topic_id", $topic_id);
    $topicObj->set("topic", $topic);
    $topicObj->set("active", $active);
    if ($topicObj->save()) {
        General::redirectUrl("topic.php");
    } else {
        $error = "topic Name alreday exist !";
    }
}
?>

<div class="ch-container">
    <div class="row">
        
        <!-- left menu starts -->
       <?php 
include 'sitebar.php';
?>
        <!--/span-->
        <!-- left menu ends -->
Esempio n. 23
0
 /**
  * Creates a new topic.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     // find forum
     if (isset($_GET['id'])) {
         $forum = Forum::model()->findByPk((int) $_GET['id']);
     }
     if (!isset($forum)) {
         throw new CHttpException(500, 'The requested forum does not exist.');
     }
     $form = new TopicForm();
     if (isset($_POST['TopicForm'])) {
         if ($form->validate()) {
             //die(var_dump(Yii::app()->user->name));
             $user = User::model()->find('username = :username', array('username' => Yii::app()->user->name));
             if ($user === null) {
                 throw new Exception(500, 'You need to login to create a new topic');
             }
             /*$transaction = Topic::model()->dbConnection->beginTransaction();
             		try {
             		*/
             //die(var_dump($_POST['TopicForm']));
             $topic = new Topic();
             $topic->forum_id = $forum->id;
             $topic->user_id = $user->id;
             $topic->title = $_POST['TopicForm']['title'];
             $topic->hits = 1;
             $topic->sticky = 0;
             $topic->locked = 0;
             $topic->created_at = date('Y-m-d H:i:s');
             $topic->updated_at = date('Y-m-d H:i:s');
             if (!$topic->save()) {
                 die(var_dump('<pre>', $topic->getErrors()));
             }
             $post = new Post();
             $post->user_id = $user->id;
             $post->topic_id = $topic->id;
             $post->body = $_POST['TopicForm']['body'];
             // TODO: fix rendering?
             $post->body_html = $post->body;
             $post->created_at = date('Y-m-d H:i:s');
             $post->forum_id = $forum->id;
             if (!$post->save()) {
                 var_dump('<pre>', $post->getErrors());
             }
             /*$user->posts_count++;
             		if(!$user->save()) {
             			var_dump('<pre>', $user->getErrors());
             		}
             		
             		$forum->topics_count++;
             		if(!$forum->save()) {
             			var_dump('<pre>', $forum->getErrors());
             		}*/
             //$transaction->commit();
             /*} catch(Exception $e) {
             			$transaction->rollBack();
             			throw new CHttpException(500, 'Failed to save topic');
             		}*/
             $this->redirect(array('view', 'id' => $topic->id));
         }
         /*if($user->save()) {
         			//var_dump("user saved");
         			
         			//$this->redirect(array('show', 'id' => $users->id ));
         			
         		} else {
         			var_dump($user->getErrors());
         		}*/
     }
     //die(var_dump($_POST['TopicForm']));
     /*$topic = new Topic();
     		if(isset($_POST['Topics']))
     		{
     			$topic->attributes=$_POST['Topics'];
     			if($topic->save())
     				$this->redirect(array('show','id'=>$topic->id));
     		}*/
     $this->render('create', array('form' => $form, 'forum' => $forum));
 }
<?php

require_once 'includes/header.php';
require_once 'includes/topics.php';
$oTopic = new Topic();
$oTopic->load($_GET["TopicID"]);
if (isset($_SESSION["MemberID"]) != 2) {
    header("Location:viewCategories.php");
} else {
    $oTopic->Active = 0;
    $oTopic->save();
    $sHTML = '<div class=
    "mainBackground"><h3>Topic ' . $oTopic->TopicID . ' has been successfully deleted!</h3>
    <a href="viewCategories.php">Continue</a></div>';
    echo $sHTML;
}
require_once 'includes/footer.php';
Esempio n. 25
0
 /**
  * Create a new topic within the group
  * @return void
  */
 private function createTopic()
 {
     if (isset($_POST) && is_array($_POST) && count($_POST) > 0) {
         require_once FRAMEWORK_PATH . 'models/topic.php';
         $topic = new Topic($this->registry, 0);
         $topic->includeFirstPost(true);
         $user = $this->registry->getObject('authenticate')->getUser()->getUserID();
         $topic->setCreator($user);
         $topic->setGroup($this->groupID);
         $topic->setName($this->registry->getObject('db')->sanitizeData($_POST['name']));
         $topic->getFirstPost()->setCreator($user);
         $topic->getFirstPost()->setPost($this->registry->getObject('db')->sanitizeData($_POST['name']));
         $topic->save();
         $this->registry->redirectUser($this->registry->buildURL(array('group', $this->groupID), '', false), 'Topic created', 'Thanks, the topic has been created', false);
     } else {
         $this->group->toTags('group_');
         $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'groups/create-topic.tpl.php', 'footer.tpl.php');
     }
 }
Esempio n. 26
0
 public function postSaveTopic()
 {
     if (Auth::check()) {
         $cre = ['category_id' => Input::get('category'), 'title' => Input::get('title'), 'content' => Input::get('content')];
         $rules = ['category_id' => 'required', 'title' => 'required', 'content' => 'required'];
         $validator = Validator::make($cre, $rules);
         if ($validator->passes()) {
             $topic = new Topic();
             $topic->user_id = Auth::id();
             $topic->category_id = Input::get('category');
             $topic->title = Input::get('title');
             $topic->content = Input::get('content');
             $topic->save();
             return Redirect::to('/forum/' . $topic->topic_id)->with('success', 'Topic is successfully added');
         } else {
             return Redirect::Back()->withErrors($validator)->withInput();
         }
     }
 }
Esempio n. 27
0
 function status()
 {
     $topic = new Topic($_POST['id']);
     $topic->status = $_POST['status'];
     $topic->save();
 }
Esempio n. 28
0
 function actionNew()
 {
     header('Content-type: application/json');
     if (!Yii::app()->request->isPostRequest) {
         IjoyPlusServiceUtils::exportServiceError(Constants::METHOD_NOT_SUPPORT);
         return;
     }
     if (!IjoyPlusServiceUtils::validateAPPKey()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID);
         return;
     }
     if (IjoyPlusServiceUtils::validateUserID()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::USER_ID_INVALID);
         return;
     }
     $topicName = Yii::app()->request->getParam("name");
     if (!isset($topicName) || is_null($topicName)) {
         IjoyPlusServiceUtils::exportServiceError(Constants::PARAM_IS_INVALID);
         return;
     }
     $owner_id = Yii::app()->user->id;
     $topic = Topic::model()->getTopic($owner_id, $topicName);
     if ($topic == null) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $top = new Topic();
             $top->t_flag = 1;
             $top->t_name = $topicName;
             $top->create_date = new CDbExpression('NOW()');
             $top->t_userid = $owner_id;
             $top->t_pic = Yii::app()->request->getParam("pic");
             $top->t_des = Yii::app()->request->getParam("content");
             $top->t_type = Yii::app()->request->getParam("type");
             $top->save();
             User::model()->updateTopBDCount($owner_id, 1);
             $transaction->commit();
             IjoyPlusServiceUtils::exportEntity(array('topic_id' => $top->t_id));
         } catch (Exception $e) {
             Yii::log(CJSON::encode($e), "error");
             $transaction->rollback();
             IjoyPlusServiceUtils::exportServiceError(Constants::SYSTEM_ERROR);
         }
     } else {
         IjoyPlusServiceUtils::exportServiceError(Constants::OBJECT_EXIST);
     }
 }
Esempio n. 29
0
 public function actionUpdatequestion($id)
 {
     $questionModel = Question::model()->findByPk($id);
     if (isset($_POST["Question"])) {
         $questionModel->attributes = $_POST["Question"];
         $questionModel->content = $_POST["Question"]["content"];
         $questionModel->topic_ids = $_POST["Question"]["topic_ids"];
         $questionModel->update_time = time();
         if ($questionModel->save()) {
             $topic_ids = "";
             $topicArray = explode(",", trim($questionModel->topic_ids, ","));
             $topic_ids .= ",";
             for ($i = 0; $i < count($topicArray); $i++) {
                 $model = Topic::model()->find("name='" . $topicArray[$i] . "'");
                 if ($model == NULL) {
                     $newModel = new Topic();
                     $newModel->name = $topicArray[$i];
                     $newModel->create_user = Yii::app()->user->id;
                     $newModel->create_time = time();
                     if ($newModel->save()) {
                         $topic_ids .= $newModel->id . ",";
                     }
                 } else {
                     $topic_ids .= $model->id . ",";
                 }
             }
             Question::model()->updateByPk($id, array("topic_ids" => $topic_ids));
         }
         echo CJSON::encode($questionModel->getErrors());
     }
 }
Esempio n. 30
0
 /**
  * 
  * @param sfWebRequest $request
  * @param sfForm $form
  * @param Room $room
  * @return <bool> false if preview action
  */
 protected function processTopicForm(sfWebRequest $request, sfForm $form, Room $room, User $user)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         if ($this->getRequestParameter('submitAct')) {
             $values = $form->getValues();
             // topic saving
             $topic = new Topic();
             $topic->setTitle($values['title']);
             $topic->setIdRoom($room->getId());
             $topic->setIdUser($user->getId());
             $topic->save();
             // post saving
             $post = new Post();
             $post->setContent($values['post']['content']);
             $post->setIdTopic($topic->getId());
             $post->setIdUser($user->getId());
             $post->save();
             $this->redirect('room_topic_show', $topic);
         } else {
             if ($this->getRequestParameter('prevSubmitAct')) {
                 return;
             } else {
                 return false;
             }
         }
     }
 }