Initial commit.
This commit is contained in:
261
src/IDF/Form/IssueCreate.php
Normal file
261
src/IDF/Form/IssueCreate.php
Normal file
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of InDefero, an open source project management application.
|
||||
# Copyright (C) 2008 Céondo Ltd and contributors.
|
||||
#
|
||||
# InDefero is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# InDefero is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Create a new issue.
|
||||
*
|
||||
* This create the issue entry and the first comment corresponding to
|
||||
* the description and the attached files.
|
||||
*
|
||||
* It is possible to tag the issue following some rules. For example
|
||||
* you cannot put several "status" or "priority" tags.
|
||||
*
|
||||
*/
|
||||
class IDF_Form_IssueCreate extends Pluf_Form
|
||||
{
|
||||
public $user = null;
|
||||
public $project = null;
|
||||
public $show_full = false;
|
||||
|
||||
public function initFields($extra=array())
|
||||
{
|
||||
$this->user = $extra['user'];
|
||||
$this->project = $extra['project'];
|
||||
if ($this->user->hasPerm('IDF.project-owner', $this->project)
|
||||
or $this->user->hasPerm('IDF.project-member', $this->project)) {
|
||||
$this->show_full = true;
|
||||
}
|
||||
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => true,
|
||||
'label' => __('Summary'),
|
||||
'initial' => '',
|
||||
'widget_attrs' => array(
|
||||
'maxlength' => 200,
|
||||
'size' => 67,
|
||||
),
|
||||
));
|
||||
$this->fields['content'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => true,
|
||||
'label' => __('Description'),
|
||||
'initial' => '',
|
||||
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||
'widget_attrs' => array(
|
||||
'cols' => 58,
|
||||
'rows' => 13,
|
||||
),
|
||||
));
|
||||
if ($this->show_full) {
|
||||
$this->fields['status'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => true,
|
||||
'label' => __('Status'),
|
||||
'initial' => 'New',
|
||||
'widget_attrs' => array(
|
||||
'maxlength' => 20,
|
||||
'size' => 15,
|
||||
),
|
||||
));
|
||||
$this->fields['owner'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => false,
|
||||
'label' => __('Owner'),
|
||||
'initial' => '',
|
||||
'widget_attrs' => array(
|
||||
'maxlength' => 20,
|
||||
'size' => 15,
|
||||
),
|
||||
));
|
||||
for ($i=1;$i<7;$i++) {
|
||||
$initial = '';
|
||||
switch ($i) {
|
||||
case 1:
|
||||
$initial = 'Type:Defect';
|
||||
break;
|
||||
case 2:
|
||||
$initial = 'Priority:Medium';
|
||||
break;
|
||||
}
|
||||
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => false,
|
||||
'label' => __('Labels'),
|
||||
'initial' => $initial,
|
||||
'widget_attrs' => array(
|
||||
'maxlength' => 50,
|
||||
'size' => 20,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the interconnection in the form.
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
// We need to check that no label with the 'Status' class is
|
||||
// given.
|
||||
if (!$this->show_full) {
|
||||
return $this->cleaned_data;
|
||||
}
|
||||
$conf = new IDF_Conf();
|
||||
$conf->setProject($this->project);
|
||||
$onemax = array();
|
||||
foreach (split(',', $conf->getVal('labels_issue_one_max', IDF_Form_IssueTrackingConf::init_one_max)) as $class) {
|
||||
if (trim($class) != '') {
|
||||
$onemax[] = mb_strtolower(trim($class));
|
||||
}
|
||||
}
|
||||
$count = array();
|
||||
for ($i=1;$i<7;$i++) {
|
||||
$this->cleaned_data['label'.$i] = trim($this->cleaned_data['label'.$i]);
|
||||
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||
list($class, $name) = array(mb_strtolower(trim($class)),
|
||||
trim($name));
|
||||
} else {
|
||||
$class = 'other';
|
||||
$name = $this->cleaned_data['label'.$i];
|
||||
}
|
||||
if ($class == 'status') {
|
||||
if (!isset($this->errors['label'.$i])) $this->errors['label'.$i] = array();
|
||||
$this->errors['label'.$i][] = __('You cannot add a label with the "Status" prefix to an issue.');
|
||||
throw new Pluf_Form_Invalid(__('You provided an invalid label.'));
|
||||
}
|
||||
if (!isset($count[$class])) $count[$class] = 1;
|
||||
else $count[$class] += 1;
|
||||
if (in_array($class, $onemax) and $count[$class] > 1) {
|
||||
if (!isset($this->errors['label'.$i])) $this->errors['label'.$i] = array();
|
||||
$this->errors['label'.$i][] = sprintf(__('You cannot provide more than label from the %s class to an issue.'), $class);
|
||||
throw new Pluf_Form_Invalid(__('You provided an invalid label.'));
|
||||
}
|
||||
}
|
||||
return $this->cleaned_data;
|
||||
}
|
||||
|
||||
function clean_status()
|
||||
{
|
||||
// Check that the status is in the list of official status
|
||||
$tags = $this->project->getTagsFromConfig('labels_issue_open',
|
||||
IDF_Form_IssueTrackingConf::init_open,
|
||||
'Status');
|
||||
$tags = array_merge($this->project->getTagsFromConfig('labels_issue_closed',
|
||||
IDF_Form_IssueTrackingConf::init_closed,
|
||||
'Status')
|
||||
, $tags);
|
||||
$found = false;
|
||||
foreach ($tags as $tag) {
|
||||
if ($tag->name == trim($this->cleaned_data['status'])) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
throw new Pluf_Form_Invalid(__('You provided an invalid status.'));
|
||||
}
|
||||
return $this->cleaned_data['status'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()) {
|
||||
// Add a tag for each label
|
||||
$tags = array();
|
||||
if ($this->show_full) {
|
||||
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[] = IDF_Tag::add($name, $this->project, $class);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$tags[] = IDF_Tag::add('Medium', $this->project, 'Priority');
|
||||
$tags[] = IDF_Tag::add('Defect', $this->project, 'Type');
|
||||
}
|
||||
// Create the issue
|
||||
$issue = new IDF_Issue();
|
||||
$issue->project = $this->project;
|
||||
$issue->submitter = $this->user;
|
||||
if ($this->show_full) {
|
||||
$issue->status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status');
|
||||
$issue->owner = self::findUser($this->cleaned_data['owner']);
|
||||
} else {
|
||||
$_t = $this->project->getTagIdsByStatus('open');
|
||||
$issue->status = new IDF_Tag($_t[0]); // first one is the default
|
||||
$issue->owner = null;
|
||||
}
|
||||
$issue->summary = trim($this->cleaned_data['summary']);
|
||||
$issue->create();
|
||||
foreach ($tags as $tag) {
|
||||
$issue->setAssoc($tag);
|
||||
}
|
||||
$issue->setAssoc($this->user); // the user is
|
||||
// automatically
|
||||
// interested.
|
||||
// add the first comment
|
||||
$comment = new IDF_IssueComment();
|
||||
$comment->issue = $issue;
|
||||
$comment->content = $this->cleaned_data['content'];
|
||||
$comment->submitter = $this->user;
|
||||
$comment->create();
|
||||
return $issue;
|
||||
}
|
||||
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the given string, try to find the matching user.
|
||||
*
|
||||
* Search order is: email, login, last_name.
|
||||
*
|
||||
* If no user found, simply returns null.
|
||||
*
|
||||
* @param string User
|
||||
* @return Pluf_User or null
|
||||
*/
|
||||
public static function findUser($string)
|
||||
{
|
||||
$string = trim($string);
|
||||
if (strlen($string) == 0) return null;
|
||||
$guser = new Pluf_User();
|
||||
foreach (array('email', 'login', 'last_name') as $what) {
|
||||
$sql = new Pluf_SQL($what.'=%s', $string);
|
||||
$users = $guser->getList(array('filter' => $sql->gen()));
|
||||
if ($users->count() > 0) {
|
||||
return $users[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
107
src/IDF/Form/IssueTrackingConf.php
Normal file
107
src/IDF/Form/IssueTrackingConf.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of InDefero, an open source project management application.
|
||||
# Copyright (C) 2008 Céondo Ltd and contributors.
|
||||
#
|
||||
# InDefero is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# InDefero is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
/**
|
||||
* Configuration of the labels etc.
|
||||
*/
|
||||
class IDF_Form_IssueTrackingConf extends Pluf_Form
|
||||
{
|
||||
/**
|
||||
* Defined as constants to easily access the value in the
|
||||
* IssueUpdate/Create form in the case nothing is in the db yet.
|
||||
*/
|
||||
const init_open = 'New = Issue has not had initial review yet
|
||||
Accepted = Problem reproduced / Need acknowledged
|
||||
Started = Work on this issue has begun';
|
||||
const init_closed = 'Fixed = Developer made requested changes, QA should verify
|
||||
Verified = QA has verified that the fix worked
|
||||
Invalid = This was not a valid issue report
|
||||
Duplicate = This report duplicates an existing issue
|
||||
WontFix = We decided to not take action on this issue';
|
||||
const init_predefined = 'Type:Defect = Report of a software defect
|
||||
Type:Enhancement = Request for enhancement
|
||||
Type:Task = Work item that doesn\'t change the code or docs
|
||||
Type:Patch = Source code patch for review
|
||||
Type:Other = Some other kind of issue
|
||||
Priority:Critical = Must resolve in the specified milestone
|
||||
Priority:High = Strongly want to resolve in the specified milestone
|
||||
Priority:Medium = Normal priority
|
||||
Priority:Low = Might slip to later milestone
|
||||
OpSys:All = Affects all operating systems
|
||||
OpSys:Windows = Affects Windows users
|
||||
OpSys:Linux = Affects Linux users
|
||||
OpSys:OSX = Affects Mac OS X users
|
||||
Milestone:Release1.0 = All essential functionality working
|
||||
Component:UI = Issue relates to program UI
|
||||
Component:Logic = Issue relates to application logic
|
||||
Component:Persistence = Issue relates to data storage components
|
||||
Component:Scripts = Utility and installation scripts
|
||||
Component:Docs = Issue relates to end-user documentation
|
||||
Security = Security risk to users
|
||||
Performance = Performance issue
|
||||
Usability = Affects program usability
|
||||
Maintainability = Hinders future changes';
|
||||
const init_one_max = 'Type, Priority, Milestone';
|
||||
|
||||
public function initFields($extra=array())
|
||||
{
|
||||
$this->fields['labels_issue_open'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => true,
|
||||
'label' => __('Open issue status values'),
|
||||
'initial' => self::init_open,
|
||||
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||
'widget_attrs' => array('rows' => 5,
|
||||
'cols' => 75),
|
||||
));
|
||||
$this->fields['labels_issue_closed'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => true,
|
||||
'label' => __('Closed issue status values'),
|
||||
'initial' => self::init_closed,
|
||||
'widget_attrs' => array('rows' => 7,
|
||||
'cols' => 75),
|
||||
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||
));
|
||||
|
||||
$this->fields['labels_issue_predefined'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => true,
|
||||
'label' => __('Predefined issue labels'),
|
||||
'initial' => self::init_predefined,
|
||||
'widget_attrs' => array('rows' => 7,
|
||||
'cols' => 75),
|
||||
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||
));
|
||||
|
||||
$this->fields['labels_issue_one_max'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => false,
|
||||
'label' => __('Each issue may have at most one label with each of these classes'),
|
||||
'initial' => self::init_one_max,
|
||||
'widget_attrs' => array('size' => 60),
|
||||
));
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
260
src/IDF/Form/IssueUpdate.php
Normal file
260
src/IDF/Form/IssueUpdate.php
Normal file
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of InDefero, an open source project management application.
|
||||
# Copyright (C) 2008 Céondo Ltd and contributors.
|
||||
#
|
||||
# InDefero is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# InDefero is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Update an issue.
|
||||
*
|
||||
* We extend IDF_Form_IssueCreate to reuse the validation logic.
|
||||
*/
|
||||
class IDF_Form_IssueUpdate extends IDF_Form_IssueCreate
|
||||
{
|
||||
public $issue = null;
|
||||
|
||||
public function initFields($extra=array())
|
||||
{
|
||||
$this->user = $extra['user'];
|
||||
$this->project = $extra['project'];
|
||||
$this->issue = $extra['issue'];
|
||||
if ($this->user->hasPerm('IDF.project-owner', $this->project)
|
||||
or $this->user->hasPerm('IDF.project-member', $this->project)) {
|
||||
$this->show_full = true;
|
||||
}
|
||||
if ($this->show_full) {
|
||||
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => true,
|
||||
'label' => __('Summary'),
|
||||
'initial' => $this->issue->summary,
|
||||
'widget_attrs' => array(
|
||||
'maxlength' => 200,
|
||||
'size' => 67,
|
||||
),
|
||||
));
|
||||
}
|
||||
$this->fields['content'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => false,
|
||||
'label' => __('Comment'),
|
||||
'initial' => '',
|
||||
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||
'widget_attrs' => array(
|
||||
'cols' => 58,
|
||||
'rows' => 9,
|
||||
),
|
||||
));
|
||||
if ($this->show_full) {
|
||||
$this->fields['status'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => true,
|
||||
'label' => __('Status'),
|
||||
'initial' => $this->issue->get_status()->name,
|
||||
'widget_attrs' => array(
|
||||
'maxlength' => 20,
|
||||
'size' => 15,
|
||||
),
|
||||
));
|
||||
$initial = ($this->issue->get_owner() == null) ? '' : $this->issue->get_owner()->login;
|
||||
$this->fields['owner'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => false,
|
||||
'label' => __('Owner'),
|
||||
'initial' => $initial,
|
||||
'widget_attrs' => array(
|
||||
'maxlength' => 20,
|
||||
'size' => 15,
|
||||
),
|
||||
));
|
||||
$tags = $this->issue->get_tags_list();
|
||||
for ($i=1;$i<7;$i++) {
|
||||
$initial = '';
|
||||
if (isset($tags[$i-1])) {
|
||||
if ($tags[$i-1]->class != 'Other') {
|
||||
$initial = (string) $tags[$i-1];
|
||||
} else {
|
||||
$initial = $tags[$i-1]->name;
|
||||
}
|
||||
}
|
||||
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => false,
|
||||
'label' => __('Labels'),
|
||||
'initial' => $initial,
|
||||
'widget_attrs' => array(
|
||||
'maxlength' => 50,
|
||||
'size' => 20,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()) {
|
||||
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();
|
||||
return $this->issue;
|
||||
}
|
||||
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||
}
|
||||
}
|
86
src/IDF/Form/MembersConf.php
Normal file
86
src/IDF/Form/MembersConf.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of InDefero, an open source project management application.
|
||||
# Copyright (C) 2008 Céondo Ltd and contributors.
|
||||
#
|
||||
# InDefero is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# InDefero is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
/**
|
||||
* Configuration of the members.
|
||||
*
|
||||
* To simplify the management. Instead of being obliged to go through
|
||||
* a list of people and then select the rights member/owner, I am
|
||||
* using the same approach as googlecode, that is, asking for the
|
||||
* login. This makes the interface simpler and simplicity is king.
|
||||
*
|
||||
* In background, the row permission framework is used to give the
|
||||
* member/owner permission to the given project to the users.
|
||||
*/
|
||||
class IDF_Form_MembersConf extends Pluf_Form
|
||||
{
|
||||
public $project = null;
|
||||
|
||||
public function initFields($extra=array())
|
||||
{
|
||||
$this->project = $extra['project'];
|
||||
|
||||
$this->fields['owners'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => false,
|
||||
'label' => __('Project owners'),
|
||||
'initial' => '',
|
||||
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||
'widget_attrs' => array('rows' => 5,
|
||||
'cols' => 40),
|
||||
));
|
||||
$this->fields['members'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => false,
|
||||
'label' => __('Project members'),
|
||||
'widget_attrs' => array('rows' => 7,
|
||||
'cols' => 40),
|
||||
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||
));
|
||||
}
|
||||
|
||||
public function save($commit=true)
|
||||
{
|
||||
if (!$this->isValid()) {
|
||||
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||
}
|
||||
// remove all the permissions
|
||||
$cm = $this->project->getMembershipData();
|
||||
$def = array('owners' => Pluf_Permission::getFromString('IDF.project-owner'),
|
||||
'members' => Pluf_Permission::getFromString('IDF.project-member'));
|
||||
$guser = new Pluf_User();
|
||||
foreach ($def as $key=>$perm) {
|
||||
foreach ($cm[$key] as $user) {
|
||||
Pluf_RowPermission::remove($user, $this->project, $perm);
|
||||
}
|
||||
foreach (preg_split("/\015\012|\015|\012|\,/", $this->cleaned_data[$key], -1, PREG_SPLIT_NO_EMPTY) as $login) {
|
||||
$sql = new Pluf_SQL('login=%s', array(trim($login)));
|
||||
$users = $guser->getList(array('filter'=>$sql->gen()));
|
||||
if ($users->count() == 1) {
|
||||
Pluf_RowPermission::add($users[0], $this->project, $perm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user