/** * Create the autocomplete arrays for the little AJAX stuff. */ public static function autoCompleteArrays($project) { $conf = new IDF_Conf(); $conf->setProject($project); $auto = array('auto_status' => '', 'auto_labels' => ''); $auto_raw = array('auto_status' => '', 'auto_labels' => ''); $st = $conf->getVal('labels_issue_open', IDF_Form_IssueTrackingConf::init_open); $st .= "\n" . $conf->getVal('labels_issue_closed', IDF_Form_IssueTrackingConf::init_closed); $auto_raw['auto_status'] = $st; $auto_raw['auto_labels'] = $conf->getVal('labels_issue_predefined', IDF_Form_IssueTrackingConf::init_predefined); foreach ($auto_raw as $key => $st) { $st = preg_split("/\r\n|\r|\n/", $st, -1, PREG_SPLIT_NO_EMPTY); foreach ($st as $s) { $v = ''; $d = ''; $_s = explode('=', $s, 2); if (count($_s) > 1) { $v = trim($_s[0]); $d = trim($_s[1]); } else { $v = trim($_s[0]); } $auto[$key] .= sprintf('{ name: "%s", to: "%s" }, ', Pluf_esc($d), Pluf_esc($v)); } $auto[$key] = substr($auto[$key], 0, -2); } // Get the members/owners $m = $project->getMembershipData(); $auto['_auto_owner'] = $m['members']; $auto['auto_owner'] = ''; foreach ($m['owners'] as $owner) { if (!Pluf_Model_InArray($owner, $auto['_auto_owner'])) { $auto['_auto_owner'][] = $owner; } } foreach ($auto['_auto_owner'] as $owner) { $auto['auto_owner'] .= sprintf('{ name: "%s", to: "%s" }, ', Pluf_esc($owner), Pluf_esc($owner->login)); } $auto['auto_owner'] = substr($auto['auto_owner'], 0, -2); unset($auto['_auto_owner']); return $auto; }
/** * Notify of the update of the review. * * * @param IDF_Conf Current configuration * @param bool Creation (true) */ public function notify($conf, $create = true) { $patch = $this->get_patch(); $review = $patch->get_review(); $prj = $review->get_project(); $to_email = array(); if ('' != $conf->getVal('review_notification_email', '')) { $langs = Pluf::f('languages', array('en')); $to_email[] = array($conf->getVal('issues_notification_email'), $langs[0]); } $current_locale = Pluf_Translation::getLocale(); $reviewers = $review->getReviewers(); if (!Pluf_Model_InArray($review->get_submitter(), $reviewers)) { $reviewers[] = $review->get_submitter(); } $comments = $patch->getFileComments(array('order' => 'id DESC')); $gcomments = $patch->get_comments_list(array('order' => 'id DESC')); $context = new Pluf_Template_Context(array('review' => $review, 'patch' => $patch, 'comments' => $comments, 'gcomments' => $gcomments, 'project' => $prj, 'url_base' => Pluf::f('url_base'))); // build the list of emails and lang foreach ($reviewers as $user) { $email_lang = array($user->email, $user->language); if (!in_array($email_lang, $to_email)) { $to_email[] = $email_lang; } } $tmpl = new Pluf_Template('idf/review/review-updated-email.txt'); foreach ($to_email as $email_lang) { Pluf_Translation::loadSetLocale($email_lang[1]); $email = new Pluf_Mail(Pluf::f('from_email'), $email_lang[0], sprintf(__('Updated Code Review %s - %s (%s)'), $review->id, $review->summary, $prj->shortname)); $email->addTextMessage($tmpl->render($context)); $email->sendMail(); } Pluf_Translation::loadSetLocale($current_locale); }
/** * Return a list of unique models. * * @param array Models with duplicates * @return array Models with duplicates. */ function Pluf_Model_RemoveDuplicates($array) { $res = array(); foreach ($array as $model) { if (!Pluf_Model_InArray($model, $res)) { $res[] = $model; } } return $res; }
/** * 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) { // Add a tag for each label $tags = array(); $tagids = 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]); } $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->issue->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; } } } // Status, summary and owner $status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status'); if ($status->id != $this->issue->status) { $changes['st'] = $status->name; } if (trim($this->issue->summary) != trim($this->cleaned_data['summary'])) { $changes['su'] = trim($this->cleaned_data['summary']); } $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) { $changes['ow'] = is_null($owner) ? '---' : $owner->login; } // Update the issue $this->issue->batchAssoc('IDF_Tag', $tagids); $this->issue->summary = trim($this->cleaned_data['summary']); $this->issue->status = $status; $this->issue->owner = $owner; } // Create the comment $comment = new IDF_IssueComment(); $comment->issue = $this->issue; $comment->content = $this->cleaned_data['content']; $comment->submitter = $this->user; if (!$this->show_full) { $changes = array(); } $comment->changes = $changes; $comment->create(); $this->issue->update(); if ($this->issue->owner != $this->user->id and $this->issue->submitter != $this->user->id) { $this->issue->setAssoc($this->user); // interested user. } $attached_files = array(); for ($i = 1; $i < 4; $i++) { if ($this->cleaned_data['attachment' . $i]) { $file = new IDF_IssueFile(); $file->attachment = $this->cleaned_data['attachment' . $i]; $file->submitter = $this->user; $file->comment = $comment; $file->create(); $attached_files[] = $file; } } /** * [signal] * * IDF_Issue::update * * [sender] * * IDF_Form_IssueUpdate * * [description] * * This signal allows an application to perform a set of tasks * just after the update of an issue. * * [parameters] * * array('issue' => $issue, * 'comment' => $comment, * 'files' => $attached_files); * */ $params = array('issue' => $this->issue, 'comment' => $comment, 'files' => $attached_files); Pluf_Signal::send('IDF_Issue::update', 'IDF_Form_IssueUpdate', $params); return $this->issue; }
public function delete($request, $match) { $prj = $request->project; $upload = Pluf_Shortcuts_GetObjectOr404('IDF_Upload', $match[2]); $prj->inOr404($upload); $title = sprintf(__('Delete Download %s'), $upload->summary); $form = false; $ptags = self::getDownloadTags($prj); $dtag = array_pop($ptags); // The last tag is the deprecated tag. $tags = $upload->get_tags_list(); $deprecated = Pluf_Model_InArray($dtag, $tags); if ($request->method == 'POST') { $fname = $upload->file; @unlink(Pluf::f('upload_path') . '/' . $prj->shortname . '/files/' . $fname); /** * [signal] * * IDF_Upload::delete * * [sender] * * IDF_Form_UpdateUpload * * [description] * * This signal allows an application to perform a set of tasks * just before the deletion of the corresponding object in the * database but just after the deletion from the storage. * * [parameters] * * array('upload' => $upload); * */ $params = array('upload' => $upload); Pluf_Signal::send('IDF_Upload::delete', 'IDF_Views_Download', $params); $upload->delete(); $request->user->setMessage(__('The file has been deleted.')); $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::index', array($prj->shortname)); return new Pluf_HTTP_Response_Redirect($url); } return Pluf_Shortcuts_RenderToResponse('idf/downloads/delete.html', array('file' => $upload, 'deprecated' => $deprecated, 'tags' => $tags, 'page_title' => $title), $request); }
public function view($request, $match) { $prj = $request->project; // Find the page $sql = new Pluf_SQL('project=%s AND title=%s', array($prj->id, $match[2])); $pages = Pluf::factory('IDF_WikiPage')->getList(array('filter' => $sql->gen())); if ($pages->count() != 1) { return new Pluf_HTTP_Response_NotFound($request); } $page = $pages[0]; $oldrev = false; // We grab the old revision if requested. if (isset($request->GET['rev']) and preg_match('/^[0-9]+$/', $request->GET['rev'])) { $oldrev = Pluf_Shortcuts_GetObjectOr404('IDF_WikiRevision', $request->GET['rev']); if ($oldrev->wikipage != $page->id or $oldrev->is_head == true) { return new Pluf_HTTP_Response_NotFound($request); } } $ptags = self::getWikiTags($prj); $dtag = array_pop($ptags); // The last tag is the deprecated tag. $tags = $page->get_tags_list(); $dep = Pluf_Model_InArray($dtag, $tags); $title = $page->title; $revision = $page->get_current_revision(); $false = Pluf_DB_BooleanToDb(false, $page->getDbConnection()); $revs = $page->get_revisions_list(array('order' => 'creation_dtime DESC', 'filter' => 'is_head=' . $false)); return Pluf_Shortcuts_RenderToResponse('idf/wiki/view.html', array('page_title' => $title, 'page' => $page, 'oldrev' => $oldrev, 'rev' => $revision, 'revs' => $revs, 'tags' => $tags, 'deprecated' => $dep), $request); }
/** * 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; }