Beispiel #1
0
 public function create($request, $match, $api = false)
 {
     $prj = $request->project;
     $title = __('Submit a new issue');
     $params = array('project' => $prj, 'user' => $request->user);
     $preview = isset($request->POST['preview']) ? $request->POST['content'] : false;
     if ($request->method == 'POST') {
         $form = new IDF_Form_IssueCreate(array_merge($request->POST, $request->FILES), $params);
         if (!isset($request->POST['preview']) and $form->isValid()) {
             $issue = $form->save();
             $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', array($prj->shortname, $issue->id));
             $issue->notify($request->conf);
             if ($api) {
                 return $issue;
             }
             $request->user->setMessage(sprintf(__('<a href="%s">Issue %d</a> has been created.'), $url, $issue->id));
             return new Pluf_HTTP_Response_Redirect($url);
         }
     } else {
         $form = new IDF_Form_IssueCreate(null, $params);
     }
     $params = array_merge(array('project' => $prj, 'form' => $form, 'page_title' => $title, 'preview' => $preview), self::autoCompleteArrays($prj));
     if ($api == true) {
         return $params;
     }
     return Pluf_Shortcuts_RenderToResponse('idf/issues/create.html', $params, $request);
 }
Beispiel #2
0
 /**
  * We check that something is really changed.
  */
 public function clean()
 {
     $this->cleaned_data = parent::clean();
     // As soon as we know that at least one change was done, we
     // return the cleaned data and do not go further.
     if (strlen(trim($this->cleaned_data['content']))) {
         return $this->cleaned_data;
     }
     if ($this->show_full) {
         $status = $this->issue->get_status();
         if (trim($this->cleaned_data['status']) != $status->name) {
             return $this->cleaned_data;
         }
         if (trim($this->issue->summary) != trim($this->cleaned_data['summary'])) {
             return $this->cleaned_data;
         }
         $owner = self::findUser($this->cleaned_data['owner']);
         if (is_null($owner) and !is_null($this->issue->get_owner()) or !is_null($owner) and is_null($this->issue->get_owner()) or !is_null($owner) and !is_null($this->issue->get_owner()) and $owner->id != $this->issue->get_owner()->id) {
             return $this->cleaned_data;
         }
         $tags = array();
         for ($i = 1; $i < 7; $i++) {
             if (strlen($this->cleaned_data['label' . $i]) > 0) {
                 if (strpos($this->cleaned_data['label' . $i], ':') !== false) {
                     list($class, $name) = explode(':', $this->cleaned_data['label' . $i], 2);
                     list($class, $name) = array(trim($class), trim($name));
                 } else {
                     $class = 'Other';
                     $name = trim($this->cleaned_data['label' . $i]);
                 }
                 $tags[] = array($class, $name);
             }
         }
         $oldtags = $this->issue->get_tags_list();
         foreach ($tags as $tag) {
             $found = false;
             foreach ($oldtags as $otag) {
                 if ($otag->class == $tag[0] and $otag->name == $tag[1]) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 // new tag not found in the old tags
                 return $this->cleaned_data;
             }
         }
         foreach ($oldtags as $otag) {
             $found = false;
             foreach ($tags as $tag) {
                 if ($otag->class == $tag[0] and $otag->name == $tag[1]) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 // old tag not found in the new tags
                 return $this->cleaned_data;
             }
         }
     }
     // no changes!
     throw new Pluf_Form_Invalid(__('No changes were entered.'));
 }