本文整理汇总了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();
}
示例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));
}
示例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"));
}