当前位置: 首页>>代码示例>>PHP>>正文


PHP Poll::update方法代码示例

本文整理汇总了PHP中Poll::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::update方法的具体用法?PHP Poll::update怎么用?PHP Poll::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Poll的用法示例。


在下文中一共展示了Poll::update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update

 public static function update()
 {
     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('id' => $p['id'], '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_([0-9]+)\$/", $key, $matches)) {
             $poll_options[$matches[1]]['id'] = $p['option_' . $matches[1]];
             $poll_options[$matches[1]]['name'] = $p[$matches[0]];
             $poll_options[$matches[1]]['description'] = $p['option_description_' . $matches[1]];
         } else {
             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->update();
         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) {
                 if (isset($option['id'])) {
                     $polloption->id = $option['id'];
                     $polloption->update();
                 } else {
                     $polloption->save();
                 }
             } else {
                 $polloptions[] = $polloption;
             }
         }
         if (empty($polloptions)) {
             Redirect::to('/poll/' . $poll->id, array('message' => 'Tallennettiin äänestys ' . $poll->name . '.'));
         } else {
             // The poll was saved successfully but options weren't. Edit the poll.
             $errors[] = 'Tallennettiin ää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) {
             $polloption = new PollOption(array('polls_id' => $poll->id, 'name' => $option['name'], 'description' => $option['description']));
             if (isset($option['id'])) {
                 $polloption->id = $option['id'];
             }
             $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));
     }
 }
开发者ID:pinjaliina,项目名称:aanestys,代码行数:66,代码来源:poll_controller.php


注:本文中的Poll::update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。