コード例 #1
0
ファイル: custom_fields.php プロジェクト: dasklney/traq
 /**
  * New field page.
  */
 public function action_new()
 {
     // Create field
     $field = new CustomField(array('type' => 'text', 'regex' => '^(.*)$'));
     // Check if the form has been submitted
     if (Request::method() == 'post') {
         $data = array();
         // Loop over properties
         foreach (CustomField::properties() as $property) {
             // Check if it's set and not empty
             if (isset(Request::$post[$property])) {
                 $data[$property] = Request::$post[$property];
             }
         }
         // Is required?
         if (!isset(Request::$post['is_required'])) {
             $data['is_required'] = 0;
         }
         // Project ID
         $data['project_id'] = $this->project->id;
         // Set field properties
         $field->set($data);
         // Save and redirect
         if ($field->save()) {
             if ($this->is_api) {
                 return \API::response(1, array('field' => $field));
             } else {
                 Request::redirectTo($this->project->href('settings/custom_fields'));
             }
         }
     }
     // Send field object to view
     View::set(compact('field'));
 }