/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } // Add a tag for each label $tags = array(); if ($this->show_full) { for ($i = 1; $i < 4; $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[] = IDF_Tag::add($name, $this->project, $class); } } } // Create the page $page = new IDF_WikiPage(); $page->project = $this->project; $page->submitter = $this->user; $page->summary = trim($this->cleaned_data['summary']); $page->title = trim($this->cleaned_data['title']); $page->create(); foreach ($tags as $tag) { $page->setAssoc($tag); } // add the first revision $rev = new IDF_WikiRevision(); $rev->wikipage = $page; $rev->content = $this->cleaned_data['content']; $rev->submitter = $this->user; $rev->summary = __('Initial page creation'); $rev->create(); $rev->notify($this->project->getConf()); return $page; }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } if ($this->show_full) { $tagids = array(); $tags = array(); for ($i = 1; $i < 4; $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]); } $tag = IDF_Tag::add($name, $this->project, $class); $tags[] = $tag; $tagids[] = $tag->id; } } // Compare between the old and the new data $changes = array(); $oldtags = $this->page->get_tags_list(); foreach ($tags as $tag) { if (!Pluf_Model_InArray($tag, $oldtags)) { if (!isset($changes['lb'])) { $changes['lb'] = array(); } if ($tag->class != 'Other') { $changes['lb'][] = (string) $tag; //new tag } else { $changes['lb'][] = (string) $tag->name; } } } foreach ($oldtags as $tag) { if (!Pluf_Model_InArray($tag, $tags)) { if (!isset($changes['lb'])) { $changes['lb'] = array(); } if ($tag->class != 'Other') { $changes['lb'][] = '-' . (string) $tag; //new tag } else { $changes['lb'][] = '-' . (string) $tag->name; } } } if (trim($this->page->summary) != trim($this->cleaned_data['summary'])) { $changes['su'] = trim($this->cleaned_data['summary']); } // Update the page $this->page->batchAssoc('IDF_Tag', $tagids); $this->page->summary = trim($this->cleaned_data['summary']); $this->page->title = trim($this->cleaned_data['title']); } else { $changes = array(); } $this->page->update(); // add the new revision $rev = new IDF_WikiRevision(); $rev->wikipage = $this->page; $rev->content = $this->cleaned_data['content']; $rev->submitter = $this->user; $rev->summary = $this->cleaned_data['comment']; $rev->changes = $changes; $rev->create(); $rev->notify($this->project->getConf(), false); return $this->page; }