public static function action_new($id = null) { if ($id) { return Response::error(404); } if ($_SERVER['REQUEST_METHOD'] === 'POST' && Param::post('question')) { $pregunta = Param::post('question'); $description = Param::post('description'); $various_answers = Param::post('various_answers'); $slug = Param::post('slug'); $answers = Param::post('new_answers'); if (empty($pregunta) || empty($description) || empty($slug) || count($answers) < 2) { Redirect::to(Url::get('admin', null, 'poll_creation_error=true')); } $poll_id = Poll::create(array('question' => $pregunta, 'description' => $description, 'slug' => $slug, 'various_answers' => $various_answers)); foreach ($answers as $answer) { Answer::create(array('poll_id' => $poll_id, 'text' => $answer)); } Redirect::to(Url::get('admin', null, 'success=' . $poll_id . '&created=true')); } return View::make('admin.new'); }
$poll->setProperty('date_end', $f_date_end); $poll->setProperty('votes_per_user', $f_votes_per_user); $poll->setProperty('nr_of_answers', $f_nr_of_answers); $poll->setProperty('is_extended', $f_is_extended); foreach ($f_answers as $nr_answer => $text) { if ($text !== '__undefined__') { $answer = new PollAnswer($f_fk_language_id, $f_poll_nr, $nr_answer); if ($answer->exists()) { $answer->setProperty('answer', $text); } else { $answer->create($text); } } } PollAnswer::SyncNrOfAnswers($f_fk_language_id, $f_poll_nr); } else { // create new poll $poll = new Poll($f_fk_language_id); $success = $poll->create($f_title, $f_question, $f_date_begin, $f_date_end, $f_nr_of_answers, $f_votes_per_user); if ($success) { $poll->setProperty('is_extended', $f_is_extended); foreach ($f_answers as $nr_answer => $text) { if ($text !== '__undefined__') { $answer = new PollAnswer($f_fk_language_id, $poll->getNumber(), $nr_answer); $success = $answer->create($text); } } } } $f_from = Input::Get('f_from', 'string', 'index.php'); camp_html_goto_page($f_from);
/** * @return void */ public function show() { if (!TwitterAuth::isLogged()) { ?> Sólo los administradores pueden ver esta página. <a href="<?=HTMLResponse::getRoute()?>?authenticate=1"> Inicia sesión. </a><br> <? return; } else if (!Team::isAdmin()) { ?> Sólo los administradores pueden ver esta página.<br> <? return; } else { $title = trim(HTMLResponse::fromPOST('title', '')); $description = trim(HTMLResponse::fromPOST('description', '')); $options = []; for ($i=1; $i<6; $i++) { $value = trim(HTMLResponse::fromPOST('option'.$i, '')); if (strlen($value)) { $options[] = $value; } } if (strlen($title) && count($options)>=2) { $poll = Poll::create(); $poll->title = $title; $poll->description = $description; $poll->isvisible = true; $poll->isopen = true; $poll->username = TwitterAuth::getUserName(); $poll->userid = TwitterAuth::getUserId(); $poll->dateline = time(); $poll->avatar = TwitterAuth::getAvatar(); $poll->save(); foreach($options as $index => $option) { $pollOption = PollOption::create(); $pollOption->pollid = $poll->pollid; $pollOption->userid = TwitterAuth::getUserId(); $pollOption->username = TwitterAuth::getUserName(); $pollOption->title = $option; $pollOption->save(); } HTMLResponse::exitWithRoute("/votaciones/{$poll->pollid}/"); } ?> <form action="<?=HTMLResponse::getRoute()?>" method="post"> <div style="padding:3px"> <div class="inblock middle" style="width:120px"> Título </div> <input name="title" value="<?=htmlentities($title)?>"> </div> <div style="padding:3px"> <div class="inblock middle" style="width:120px"> Descripción </div> <input name="description" value="<?=htmlentities($description)?>"> </div> <? for ($i=1; $i<=6; $i++) { ?> <div style="padding:3px"> <div class="inblock middle" style="width:120px"> Opción <?=$i?> </div> <input name="option<?=$i?>" value="<?=htmlentities($options[$i-1])?>"> </div> <? } ?> <div style="padding:3px"> <div class="inblock middle" style="width:120px"> </div> <input type="submit" value="Crear votación"> </div> </form> <? } }
public function newPoll() { $title = Input::get('title'); $already_created = Poll::where('title', 'like', '%' . $title . '%'); if (!($already_created->count() > 0)) { if (isset($title)) { $poll = Poll::create(array('title' => $title, 'created_by' => Auth::user()->id)); $poll->save(); return null; } } else { return Response::json(array('title' => $already_created->first()->title)); } //return Response::json($return); }
public function makeAction() { $gender = array(1, 2); $age = array(1, 2, 3, 4, 5, 6); $modern = array(1, 2); $authors = array('local', 'abroad'); $genre = array('drama', 'tradegy', 'comedy', 'detective', 'adventures', 'fy', 'fantasy', 'horror', 'cyber', 'ero', 'bio'); $method = array('pc', 'tablet', 'mobile', 'ebook', 'book'); for ($i = 0; $i < 5000; $i++) { $poll = new Poll(); $poll->gender = $this->rnd($gender); $poll->age = $this->rnd($age); $poll->read_modern = $this->rnd($modern); $poll->authors = $this->rnd($authors, true); $poll->genre = $this->rnd($genre, true); $poll->method = $this->rnd($method, true); $poll->hash = md5(time() . rand()); $poll->timestamp = time(); $poll->create(); //echo '<br>---<br>'; } }