本文整理汇总了PHP中Poll::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::save方法的具体用法?PHP Poll::save怎么用?PHP Poll::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poll
的用法示例。
在下文中一共展示了Poll::save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Poll();
$choices = array();
//$this->performAjaxValidation($model);
if (isset($_POST['Poll'])) {
$model->attributes = $_POST['Poll'];
// Setup poll choices
if (isset($_POST['PollChoice'])) {
foreach ($_POST['PollChoice'] as $id => $choice) {
$pollChoice = new PollChoice();
$pollChoice->attributes = $choice;
$choices[$id] = $pollChoice;
}
}
if ($model->save()) {
// Save any poll choices too
foreach ($choices as $choice) {
$choice->poll_id = $model->id;
$choice->save();
}
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model, 'choices' => $choices));
}
示例2: save
public static function save()
{
self::check_logged_in();
$curruser = self::get_user_logged_in();
if (!$curruser->admin) {
Redirect::to('/user/' . $curruser->id, array('warning' => 'Pääsy kielletty ilman ylläpito-oikeutta!'));
}
$p = $_POST;
$poll = new Poll(array('name' => $p['name'], 'description' => $p['description'], 'start_time' => $p['start_time'], 'end_time' => $p['end_time']));
// Search the input array for Option model attributes and build an array
// out of them:
$poll_options = array();
foreach ($p as $key => $value) {
$matches = array();
if (preg_match("/^option_name_new_([0-9]+)\$/", $key, $matches)) {
$poll_options[$matches[1]]['name'] = $p[$matches[0]];
$poll_options[$matches[1]]['description'] = $p['option_description_new_' . $matches[1]];
}
}
$errors = $poll->errors();
$polloptions = array();
if (count($errors) == 0) {
$poll->save();
if ($poll->id) {
foreach ($poll_options as $option) {
$polloption = new PollOption(array('polls_id' => $poll->id, 'name' => $option['name'], 'description' => $option['description']));
$errors = $polloption->errors();
if (count($errors) == 0) {
$polloption->save();
} else {
$polloptions[] = $polloption;
}
}
}
if (empty($polloptions)) {
Redirect::to('/poll/' . $poll->id, array('message' => 'Lisättiin uusi äänestys ' . $poll->name . '.'));
} else {
// The poll was saved successfully but options weren't. Edit the poll.
$errors[] = 'Lisättiin uusi äänestys ' . $poll->name . ', mutta äänestyksen vaihtoehtoja ei saatu tallennettua. Tarkista virheet';
View::make('poll/edit.html', array('errors' => $errors, 'poll' => $poll, 'polloptions' => $polloptions));
}
} else {
// The actual poll wasn't saved.
foreach ($poll_options as $option) {
// We don't have the poll id.
$polloption = new PollOption(array('name' => $option['name'], 'description' => $option['description']));
$optionerrors = $polloption->errors();
if (!empty($optionerrors)) {
$errors = array_merge($errors, $optionerrors);
}
$polloptions[] = $polloption;
}
View::make('poll/edit.html', array('errors' => $errors, 'poll' => $poll, 'polloptions' => $polloptions));
}
}
示例3: actionCreate
public function actionCreate()
{
if (isset($_POST['pollName'])) {
$poll = new Poll();
$poll->name = trim($_POST['pollName']);
$poll->save();
$this->redirect($this->url('poll.edit', array('id' => $poll->id)));
} else {
$this->redirect($this->url('poll.index'));
}
}
示例4: Poll
// Initialise a new Poll
$poll = new Poll();
// Set its owner to the current user
$poll->owner_guid = $user->guid;
$poll->container_guid = $container_guid;
// Success message
$message = elgg_echo("poll:added");
}
$poll->access_id = $access_id;
$poll->question = $question;
$poll->title = $question;
$poll->description = $description;
$poll->open_poll = $open_poll ? 1 : 0;
$poll->close_date = empty($close_date) ? null : $close_date;
$poll->tags = string_to_tag_array($tags);
if (!$poll->save()) {
register_error(elgg_echo("poll:error"));
forward(REFERER);
}
$poll->setChoices($new_choices);
poll_manage_front_page($poll, $front_page);
elgg_clear_sticky_form('poll');
if ($new) {
$poll_create_in_river = elgg_get_plugin_setting('create_in_river', 'poll');
if ($poll_create_in_river != 'no') {
elgg_create_river_item(array('view' => 'river/object/poll/create', 'action_type' => 'create', 'subject_guid' => $user->guid, 'object_guid' => $poll->guid));
}
}
system_message($message);
// Forward to the poll page
forward($poll->getURL());
示例5: forward
forward(REFERER);
}
$new_entity = true;
if (!empty($guid)) {
elgg_entity_gatekeeper($guid, 'object', Poll::SUBTYPE);
$entity = get_entity($guid);
if (!$entity->canEdit()) {
register_error(elgg_echo('poll:edit:error:cant_edit'));
forward(REFERER);
}
$new_entity = false;
} else {
$entity = new Poll();
$entity->container_guid = $container_guid;
$entity->access_id = $access_id;
if (!$entity->save()) {
register_error(elgg_echo('save:fail'));
forward(REFERER);
}
}
$entity->title = $title;
$entity->description = $description;
$entity->access_id = $access_id;
$entity->tags = $tags;
$entity->comments_allowed = $comments_allowed;
$entity->results_output = $results_output;
if (empty($close_date)) {
unset($entity->close_date);
} else {
$date = getdate($close_date);
$new_close_date = mktime(23, 59, 59, $date['mon'], $date['mday'], $date['year']);
示例6: arraytoupper
require_once "../classes/poll.php";
require_once "../classes/question_file.php";
require_once "../classes/question_insert.php";
if ($_SERVER['REQUEST_METHOD'] == 'POST' && logged_in()) {
$question = fix_string($_POST['question']);
$answers = fix_input_array($_POST['answer']);
$categories = fix_input_array($_POST['categories']);
arraytoupper($categories);
// ensure that all strings in array are uppercase to avoid unnessasary duplicates
$user = $_SESSION['user'];
if (!question_valid($question) && !input_array_valid($answers) && !input_array_valid($categories)) {
go_home();
}
// failed to create new question
$conn = get_conn();
$poll_question = new Poll($conn);
$poll_question->set_question($question);
$poll_question->set_categories($categories);
$poll_question->set_answers($answers);
$poll_question->set_user($user);
$result = $poll_question->save();
$conn->close();
if (!$result) {
// question not unique or something went wrong
go_create();
}
// go back to create page
go_find($poll_question->get_href());
} else {
go_home();
}
示例7: action_edit
public static function action_edit($id = null)
{
if (!IS_ADMIN) {
Redirect::to(Url::get('admin@login', null, 'redirect-to=' . urlencode(Url::current())));
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($id === 'delete-answer') {
if (($answer_id = Param::post('answer_id')) && is_numeric($answer_id)) {
$answer = Answer::get((int) $answer_id);
Answer::find((int) $answer_id)->delete();
$votes = Vote::where('answer_id', '=', $answer_id)->count();
if ($votes) {
Poll::find($answer->poll_id)->set(array('nofilter:total_votes' => "`total_votes` - {$votes}"));
}
return Response::json(array('status' => 200, 'deleted' => true));
} else {
return Response::json(array('status' => 0, 'deleted' => false));
}
} elseif ($id) {
return Response::error(404);
} else {
$id = Param::post('id');
if ($answer_id = Param::post('remove_answer')) {
Answer::find((int) $answer_id)->and_where('poll_id', '=', $id)->delete();
$votes = Vote::where('answer_id', '=', $answer_id)->count();
if ($votes) {
Poll::find($id)->set(array('nofilter:total_votes' => "`total_votes` - {$votes}"));
}
Redirect::to(Url::get('admin@edit', $id, 'answer_deleted=true'));
}
if (Param::post('remove_poll')) {
Poll::find($id)->delete();
Redirect::to(Url::get('admin', null, 'poll_deleted=true'));
}
if (is_numeric($id) && ($poll = Poll::get((int) $id))) {
foreach ($_POST as $key => $value) {
if (isset($poll->{$key}) && (!empty($_POST[$key]) || $_POST[$key] === "0")) {
$poll->{$key} = is_numeric($_POST[$key]) ? intval($_POST[$key], 10) : $_POST[$key];
} elseif (false !== strpos($key, 'answer-')) {
$answer_id = explode('-', $key);
$answer_id = $answer_id[1];
if (is_numeric($answer_id)) {
Answer::find((int) $answer_id)->set(array('text' => $value));
}
} elseif ($key === 'new_answers') {
foreach ($value as $new_answer) {
if (!empty($new_answer)) {
Answer::create(array('poll_id' => (int) $poll->id, 'text' => $new_answer));
}
}
}
}
Poll::save($poll);
Redirect::to(Url::get('admin', null, 'success=' . $_POST['id'] . '&updated=true'));
} else {
return Response::error(500);
}
}
}
if (!$id || !is_numeric($id) || !($poll = Poll::get((int) $id))) {
return Response::error(404);
} else {
$answers = Answer::where('poll_id', '=', $poll->id)->get();
return View::make('admin.edit')->add_var('answers', $answers)->add_var('poll', $poll);
}
}
示例8: Poll
}
} else {
$poll_user = $users[0]->id;
}
}
$vote = var_export($data, true);
// file_put_contents(Yii::getPathOfAlias('webroot')."/upload/poll01.log",$a,FILE_APPEND);
$poll = new Poll();
$test = $poll->findAllByAttributes(array(), "u_id=:u_id", array(":u_id" => $poll_user));
if (count($test)) {
$canvote = 0;
} else {
$poll->poll = "poll01";
$poll->u_id = $poll_user;
$poll->vote = $vote;
$poll->save();
$canvote = 2;
}
}
if ($canvote == 1) {
$this->widget('application.widgets.poll.Poll01');
} elseif ($canvote == 2) {
if (Yii::app()->getLanguage() == "ru") {
echo "<h3><i>Спасибо, Ваш голос учтен!</i></h3>";
} else {
echo "<h3><i>Дякуемо, Ваш голос зараховано!</i></h3>";
}
echo CHtml::link(CHtml::tag('span', array(), Yii::t('template', 'ADD_DEFECT')), array('/holes/add'));
} else {
if (Yii::app()->getLanguage() == "ru") {
echo "<h3><i>Извините, но Вы не можете голосовать дважды!</i></h3>";
示例9: postStore
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postStore()
{
if (Session::get('user_level') < Config::get('cms.editPolls')) {
return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning');
}
$rules = array('question' => 'Required', 'options' => 'Required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to(_l(URL::action('PollController@getCreate')))->withErrors($validator)->withInput();
} else {
try {
$poll = new Poll();
if (Input::get('createdAt')) {
$poll->created_at = date("Y-m-d H:i:s", strtotime(Input::get('createdAt')));
} else {
$poll->created_at = date("Y-m-d H:i:s", strtotime('now'));
}
$poll->title = Input::get('question');
if (Input::get('endDate')) {
$poll->end_date = date("Y-m-d H:i:s", strtotime(Input::get('endDate')));
} else {
$poll->end_date = date("Y-m-d H:i:s", strtotime('1.1.1970'));
}
$poll->published = Input::get('published');
$poll->save();
$votes = Input::get('voteCount');
foreach (Input::get('options') as $key => $option) {
$pollOption = new PollOption();
$pollOption->poll_id = $poll->id;
$pollOption->title = $option;
if (isset($votes[$key]) && $votes[$key] != 0) {
$pollOption->vote_count = $votes[$key];
} else {
$pollOption->vote_count = 0;
}
$pollOption->save();
}
return Redirect::to(_l(URL::action('PollController@getEdit') . "/" . $poll->id))->with('message', Lang::get('admin.pollSaved'))->with('notif', 'success');
} catch (Exception $e) {
return Redirect::to(_l(URL::action('PollController@getIndex')))->with('message', Lang::get('admin.noSuchPoll'))->with('notif', 'danger');
}
}
}