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


PHP Survey::create方法代码示例

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


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

示例1: post

 public function post()
 {
     if (!Session::$user['id']) {
         $this->message = "Unauthorized";
         $this->status = 403;
         return;
     }
     if (!isset($this->post['name'])) {
         $this->message = "Missing one or more required parameters";
         $this->status = 400;
         return;
     }
     $surveyID = Survey::create($this->post['name'], Session::$user['id']);
     $survey = new Survey($surveyID);
     $this->response[$this->slug][] = $survey->apiData();
 }
开发者ID:nickyleach,项目名称:OSTSurvey,代码行数:16,代码来源:SurveysAPIController.php

示例2: post

 /**
  * Create a survey
  * 
  * @param string $id survey id to created sub-resource into
  * @param string $property
  * 
  * If creating a survey request body must be an object with properties :
  *   * title
  *   * description (optionnal)
  *   * type : "date" or "text"
  *   * choices : array of mixed
  *   * guests : optionnal array of guests
  *   * rules : rules object
  * 
  * If adding a choice to a survey (/survey/<id>/choice) request body must be an object with properties :
  *   * value : mixed depending on survey type
  *   * before : optionnal other choice key before which to add the new choice
  * 
  * @return array
  * 
  * @throws RestBadParameterException
  * @throws RestMissingParameterException
  * @throws RestNotAllowedException
  */
 public static function post($id = null, $property = null)
 {
     // Get creation data
     $data = RestServer::getRequest()->input;
     if ($id) {
         // Add new something to an existing survey
         if (!$property) {
             throw new RestBadParameterException('property');
         }
         // Get survey and update data
         $survey = Survey::fromId($id);
         // Check permissions
         if (!Auth::isAdmin() || !$survey->owner->is(Auth::user())) {
             throw new RestNotAllowedException('update survey ' . $survey->id);
         }
         $key = null;
         if ($property == 'choice') {
             if (!is_object($data) || !property_exists($data, 'value')) {
                 throw new RestBadParameterException('choice');
             }
             $before = property_exists($data, 'before') ? $data->before : null;
             $key = $survey->insertChoice($data->value, $before);
         }
         if ($property == 'guest') {
             $survey->addGuest($data);
             $key = $data;
         }
         $survey->save();
         return array('path' => '/survey/' . $survey->id . '/' . $property . '/' . $key, 'data' => self::cast($survey));
     }
     // Create survey
     if (!is_object($data)) {
         throw new RestBadParameterException('survey');
     }
     // Check permissions
     if (!Survey::canCreate()) {
         throw new RestNotAllowedException('create survey');
     }
     if (!property_exists($data, 'type') || !$data->type) {
         throw new RestMissingParameterException('survey.type');
     }
     $survey = Survey::create($data->type);
     if (!property_exists($data, 'title') || !$data->title) {
         throw new RestMissingParameterException('survey.title');
     }
     $survey->title = $data->title;
     if (property_exists($data, 'description') && $data->description) {
         $survey->description = $data->description;
     }
     if (!property_exists($data, 'choices')) {
         throw new RestMissingParameterException('survey.choices');
     }
     if (!is_array($data->choices)) {
         throw new RestBadParameterException('survey.choices');
     }
     $survey->choices = $data->choices;
     // throws if anything wrong
     if (property_exists($data, 'guests')) {
         $survey->guests = $data->guests;
     }
     if (property_exists($data, 'rules')) {
         $survey->rules = $data->rules;
     }
     $survey->save();
     return array('path' => '/survey/' . $survey->id, 'data' => self::cast($survey));
 }
开发者ID:eheb,项目名称:renater-decide,代码行数:90,代码来源:SurveyEndpoint.class.php

示例3: getStringFromRequest

}
if (getStringFromRequest('post') == "Y") {
    if (!form_key_is_valid(getStringFromRequest('form_key'))) {
        exit_form_double_submit();
    }
    $survey_title = getStringFromRequest('survey_title');
    $to_add = getStringFromRequest('to_add');
    $to_del = getStringFromRequest('to_del');
    $is_active = getStringFromRequest('is_active');
    if ($survey_id) {
        /* Modify */
        $s->update($survey_title, $to_add, $to_del, $is_active);
        $feedback = _('UPDATE SUCCESSFUL');
    } else {
        /* Add */
        $s->create($survey_title, $to_add, $is_active);
        $feedback = _('Survey Inserted');
    }
}
/* Order changes */
if (getStringFromRequest('updown') == "Y") {
    $question_id = getIntFromRequest('question_id');
    $is_up = getStringFromRequest('is_up');
    $s->updateOrder($question_id, $is_up);
    $feedback = _('UPDATE SUCCESSFUL');
}
/* Error on previous transactions? */
if ($s->isError()) {
    $feedback = $s->getErrorMessage();
    form_release_key(getStringFromRequest("form_key"));
}
开发者ID:neymanna,项目名称:fusionforge,代码行数:31,代码来源:survey.php


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