5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2002-2004, GForge, LLC
7 * Copyright 2009, Roland Mas
8 * Copyright 2009, Alcatel-Lucent
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * Standard Alcatel-Lucent disclaimer for contributing to open source
29 * "The Artifact ("Contribution") has not been tested and/or
30 * validated for release as or in products, combinations with products or
31 * other commercial use. Any use of the Contribution is entirely made at
32 * the user's own responsibility and the user can not rely on any features,
33 * functionalities or performances Alcatel-Lucent has attributed to the
36 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
37 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
38 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
39 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
40 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
41 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
42 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
43 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
44 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
47 require_once $gfcommon.'include/Error.class.php';
48 require_once $gfcommon.'tracker/ArtifactMessage.class.php';
49 require_once $gfcommon.'tracker/ArtifactExtraField.class.php';
50 require_once $gfcommon.'tracker/ArtifactWorkflow.class.php';
52 // This string is used when sending the notification mail for identifying the
54 define('ARTIFACT_MAIL_MARKER', '#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+');
57 * Factory method which creates an Artifact from an artifact ID
59 * @param int The artifact ID
60 * @param array The result array, if it's passed in
61 * @return object Artifact object
63 function &artifact_get_object($artifact_id,$data=false) {
65 if (!isset($ARTIFACT_OBJ["_".$artifact_id."_"])) {
67 //the db result handle was passed in
69 $res = db_query_params ('SELECT * FROM artifact_vw WHERE artifact_id=$1',
70 array ($artifact_id)) ;
71 if (db_numrows($res) <1 ) {
72 $ARTIFACT_OBJ["_".$artifact_id."_"]=false;
75 $data = db_fetch_array($res);
77 $ArtifactType =& artifactType_get_object($data["group_artifact_id"]);
78 $ARTIFACT_OBJ["_".$artifact_id."_"]= new Artifact($ArtifactType,$data);
80 return $ARTIFACT_OBJ["_".$artifact_id."_"];
83 class Artifact extends Error {
88 * @var int $status_res.
93 * Artifact Type object.
95 * @var object $ArtifactType.
100 * Array of artifact data.
102 * @var array $data_array.
107 * Array of artifact data for extra fields defined by Admin.
109 * @var array $extra_field_data.
111 var $extra_field_data;
114 * Array of ArtifactFile objects.
121 * Database result set of related tasks
123 * @var result $relatedtasks
128 * Artifact - constructor.
130 * @param object The ArtifactType object.
131 * @param integer (primary key from database OR complete assoc array)
132 * ONLY OPTIONAL WHEN YOU PLAN TO IMMEDIATELY CALL ->create()
133 * @return boolean success.
135 function __construct(&$ArtifactType, $data=false) {
138 $this->ArtifactType =& $ArtifactType;
140 //was ArtifactType legit?
141 if (!$ArtifactType || !is_object($ArtifactType)) {
142 $this->setError(_('No Valid Artifact Type'));
146 //did ArtifactType have an error?
147 if ($ArtifactType->isError()) {
148 $this->setError($ArtifactType->getErrorMessage());
153 // make sure this person has permission to view artifacts
155 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'read')) {
156 $this->setError(_('Only project members can view private artifact types'));
161 // set up data structures
164 if (is_array($data)) {
165 $this->data_array =& $data;
167 // Should verify ArtifactType ID
171 if (!$this->fetchData($data)) {
181 * create - construct a new Artifact in the database.
183 * @param string The artifact summary.
184 * @param string Details of the artifact.
185 * @param int The ID of the user to which this artifact is to be assigned.
186 * @param int The artifacts priority.
187 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
188 * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
189 * @return id on success / false on failure.
191 function create( $summary, $details, $assigned_to=100, $priority=3, $extra_fields=array(), $importData = array()) {
193 // make sure this person has permission to add artifacts
196 if (!$this->ArtifactType->isPublic()) {
198 // Only admins can post/modify private artifacts
202 // ape: Disabled, private means only restricted to members. So, no special rules #2503.
203 // if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID()) {
204 // $this->setError(_('Only Artifact Admins Can Modify Private Artifact Types'));
212 if(array_key_exists('user', $importData)){
213 $user = $importData['user'];
215 if (session_loggedin()) {
218 if ($this->ArtifactType->allowsAnon()) {
221 $this->setError(_('This Artifact Type Does Not Allow Anonymous Submissions. Please Login.'));
231 $this->setError(_('Message Summary Is Required'));
235 $this->setError(_('Message Body Is Required'));
244 // if (!$status_id) {
245 $status_id=1; // on creation, status is set to "open"
248 // They may be using an extra field "status" box so we have to remap
249 // the status_id based on the extra field - this keeps the counters
252 $status_id=$this->ArtifactType->remapStatus($status_id,$extra_fields);
254 $this->setError(_('Error remapping status'));
259 if (array_key_exists('time',$importData)){
260 $time = $importData['time'];
264 $res = db_query_params ('INSERT INTO artifact
265 (group_artifact_id,status_id,priority,
266 submitted_by,assigned_to,open_date,summary,details)
267 VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
268 array ($this->ArtifactType->getID(),
274 htmlspecialchars($summary),
275 htmlspecialchars($details))) ;
277 $this->setError(db_error());
282 $artifact_id=db_insertid($res,'artifact','artifact_id');
284 if (!$res || !$artifact_id) {
285 $this->setError(db_error());
290 // Now set up our internal data structures
292 if (!$this->fetchData($artifact_id)) {
296 // the changes to the extra fields will be logged in this array.
297 // (we won't use it however)
298 $extra_field_changes = array();
299 if (!$this->updateExtraFields($extra_fields,$extra_field_changes)) {
305 // now send an email if appropriate
307 $this->mailFollowupEx(0, 1);
315 * fetchData - re-fetch the data for this Artifact from the database.
317 * @param int The artifact ID.
318 * @return boolean success.
320 function fetchData($artifact_id) {
321 $res = db_query_params ('SELECT * FROM artifact_vw WHERE artifact_id=$1 AND group_artifact_id=$2',
323 $this->ArtifactType->getID())) ;
324 if (!$res || db_numrows($res) < 1) {
325 $this->setError(_('Invalid Artifact ID'));
328 $this->data_array = db_fetch_array($res);
329 db_free_result($res);
334 * getArtifactType - get the ArtifactType Object this Artifact is associated with.
336 * @return object ArtifactType.
338 function &getArtifactType() {
339 return $this->ArtifactType;
343 * getID - get this ArtifactID.
345 * @return int The artifact_id #.
348 return $this->data_array['artifact_id'];
352 * getStringID - get a string display for this ArtifactID.
354 * @return string The artifact_id #.
356 function getStringID() {
357 return '[#'.$this->data_array['artifact_id'].']';
361 * getStatusID - get open/closed/deleted flag.
363 * @return int Status: (1) Open, (2) Closed, (3) Deleted.
365 function getStatusID() {
366 return $this->data_array['status_id'];
370 * getStatusName - get open/closed/deleted text.
372 * @return string The status name.
374 function getStatusName() {
375 return $this->data_array['status_name'];
379 * getCustomStatusName - get custom status value text.
381 * @return string The custom status name.
383 function getCustomStatusName() {
384 $custom_status_id = $this->ArtifactType->getCustomStatusField();
385 if ($custom_status_id) {
386 $result = db_query_params ('SELECT element_name FROM artifact_extra_field_elements aefe, artifact_extra_field_data aefd
387 WHERE artifact_id=$1 AND aefd.extra_field_id=$2 AND CAST(aefd.field_data AS INTEGER)=aefe.element_id',
388 array ($this->getID(), $custom_status_id)) ;
390 return db_result($result, 0, 'element_name');
393 return $this->data_array['status_name'];
397 * getPriority - get priority flag.
399 * @return int priority.
401 function getPriority() {
402 return $this->data_array['priority'];
406 * getSubmittedBy - get ID of submitter.
408 * @return int user_id of submitter.
410 function getSubmittedBy() {
411 return $this->data_array['submitted_by'];
415 * getSubmittedEmail - get email of submitter.
417 * @return string The email of submitter.
419 function getSubmittedEmail() {
420 return $this->data_array['submitted_email'];
424 * getSubmittedRealName - get real name of submitter.
426 * @return string The real name of submitter.
428 function getSubmittedRealName() {
429 return $this->data_array['submitted_realname'];
433 * getSubmittedUnixName - get login name of submitter.
435 * @return string The unix name of submitter.
437 function getSubmittedUnixName() {
438 return $this->data_array['submitted_unixname'];
442 * getAssignedTo - get ID of assignee.
444 * @return int user_id of assignee.
446 function getAssignedTo() {
447 return $this->data_array['assigned_to'];
451 * getAssignedEmail - get email of assignee.
453 * @return string The email of assignee.
455 function getAssignedEmail() {
456 return $this->data_array['assigned_email'];
460 * getAssignedRealName - get real name of assignee.
462 * @return string The real name of assignee.
464 function getAssignedRealName() {
465 return $this->data_array['assigned_realname'];
469 * getAssignedUnixName - get login name of assignee.
471 * @return string The unix name of assignee.
473 function getAssignedUnixName() {
474 return $this->data_array['assigned_unixname'];
478 * getOpenDate - get unix time of creation.
480 * @return int unix time.
482 function getOpenDate() {
483 return $this->data_array['open_date'];
487 * getCloseDate - get unix time of closure.
489 * @return int unix time.
491 function getCloseDate() {
492 return $this->data_array['close_date'];
496 * getLastModifiedDate - the last_modified_date of this task.
498 * @return int the last_modified_date.
500 function getLastModifiedDate() {
501 return $this->data_array['last_modified_date'];
505 * getSummary - get text summary of artifact.
507 * @return string The summary (subject).
509 function getSummary() {
510 return $this->data_array['summary'];
514 * getDetails - get text body (message) of artifact.
516 * @return string The body (message).
518 function getDetails() {
519 return $this->data_array['details'];
523 * delete - delete this tracker and all its related data.
525 * @param bool I'm Sure.
526 * @return bool true/false;
528 function delete($sure) {
530 $this->setMissingParamsError(_('Please tick all checkboxes.'));
533 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
534 $this->setPermissionDeniedError();
538 $res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
539 array ($this->getID())) ;
541 $this->setError(_('Error deleting extra field data: ').db_error());
545 $res = db_query_params ('DELETE FROM artifact_file WHERE artifact_id=$1',
546 array ($this->getID())) ;
548 $this->setError(_('Error deleting file from db: ').db_error());
552 $res = db_query_params ('DELETE FROM artifact_message WHERE artifact_id=$1',
553 array ($this->getID())) ;
555 $this->setError(_('Error deleting message: ').db_error());
559 $res = db_query_params ('DELETE FROM artifact_history WHERE artifact_id=$1',
560 array ($this->getID())) ;
562 $this->setError(_('Error deleting history: ').db_error());
566 $res = db_query_params ('DELETE FROM artifact_monitor WHERE artifact_id=$1',
567 array ($this->getID())) ;
569 $this->setError(_('Error deleting monitor: ').db_error());
573 $res = db_query_params ('DELETE FROM artifact WHERE artifact_id=$1',
574 array ($this->getID())) ;
576 $this->setError(_('Error deleting artifact: ').db_error());
581 if ($this->getStatusID() == 1) {
582 $res = db_query_params ('UPDATE artifact_counts_agg SET count=count-1,open_count=open_count-1
583 WHERE group_artifact_id=$1',
584 array ($this->getID())) ;
586 $this->setError(_('Error updating artifact counts: ').db_error());
590 } elseif ($this->getStatusID() == 2) {
591 $res = db_query_params ('UPDATE artifact_counts_agg SET count=count-1
592 WHERE group_artifact_id=$1',
593 array ($this->getID())) ;
595 $this->setError(_('Error updating artifact counts: ').db_error());
606 * setMonitor - user can monitor this artifact.
608 * @return false - always false - always use the getErrorMessage() for feedback
610 function setMonitor() {
611 if (session_loggedin()) {
613 $user_id=user_getid();
614 $user =& user_get_object(user_getid());
617 //we don't want to include the "And email=" because
618 //a logged-in user's email may have changed
623 $this->setError(_('Valid Email Address Required'));
628 $res = db_query_params ('SELECT * FROM artifact_monitor WHERE artifact_id=$1 AND user_id=$2',
629 array ($this->getID(),
632 if (!$res || db_numrows($res) < 1) {
634 $res = db_query_params ('INSERT INTO artifact_monitor (artifact_id,user_id) VALUES ($1,$2)',
635 array ($this->getID(),
638 $this->setError(db_error());
641 $this->setError(_('Now Monitoring Artifact'));
645 //already monitoring - remove their monitor
646 db_query_params ('DELETE FROM artifact_monitor
649 array ($this->getID(),
651 $this->setError(_('Artifact Monitoring Deactivated'));
656 function isMonitoring() {
657 if (!session_loggedin()) {
660 $result = db_query_params ('SELECT count(*) AS count FROM artifact_monitor WHERE user_id=$1 AND artifact_id=$2',
663 $row_count = db_fetch_array($result);
664 return $result && $row_count['count'] > 0;
668 * getMonitorIds - array of email addresses monitoring this Artifact.
670 * @return array of email addresses monitoring this Artifact.
672 function getMonitorIds() {
673 $res = db_query_params ('SELECT user_id FROM artifact_monitor WHERE artifact_id=$1',
674 array ($this->getID())) ;
675 return array_unique(array_merge($this->ArtifactType->getMonitorIds(),util_result_column_to_array($res)));
679 * getHistory - returns a result set of audit trail for this support request.
681 * @return database result set.
683 function getHistory() {
684 return db_query_params ('SELECT * FROM artifact_history_user_vw WHERE artifact_id=$1 ORDER BY entrydate DESC, id ASC',
685 array ($this->getID())) ;
689 * getMessages - get the list of messages attached to this artifact.
691 * @return database result set.
693 function getMessages($asc=false) {
694 return db_query_params ('SELECT * FROM artifact_message_user_vw WHERE artifact_id=$1 ORDER BY adddate ' . ($asc ? 'ASC' : 'DESC') . ', id ASC',
695 array ($this->getID())) ;
699 * getMessageObjects - get an array of message objects.
701 * @return array Of ArtifactMessage objects.
703 function &getMessageObjects() {
704 $res=$this->getMessages();
706 while ($arr = db_fetch_array($res)) {
707 //$return[]=new ArtifactMessage($arr['artifact_id'],$arr);
708 $return[] = new ArtifactMessage($this, $arr);
714 * getFiles - get array of ArtifactFile's.
716 * @return array of ArtifactFile's.
718 function &getFiles() {
719 if (!isset($this->files)) {
720 $res = db_query_params ('SELECT id,artifact_id,description,filename,filesize,' .
721 'filetype,adddate,submitted_by,user_name,realname
722 FROM artifact_file_user_vw WHERE artifact_id=$1',
723 array ($this->getID())) ;
724 $rows=db_numrows($res);
726 for ($i=0; $i < $rows; $i++) {
727 $this->files[$i]=new ArtifactFile($this,db_fetch_array($res));
730 $this->files=array();
737 * getRelatedTasks - get array of related tasks
739 * @return Database result set
741 function getRelatedTasks() {
742 if (!$this->relatedtasks) {
743 $this->relatedtasks = db_query_params ('SELECT pt.group_project_id,pt.project_task_id,pt.summary,pt.start_date,pt.end_date,pgl.group_id,pt.status_id,pt.percent_complete,ps.status_name
744 FROM project_task pt, project_group_list pgl, project_status ps
745 WHERE pt.group_project_id = pgl.group_project_id
746 AND ps.status_id = pt.status_id
747 AND EXISTS (SELECT project_task_id FROM project_task_artifact
748 WHERE project_task_id=pt.project_task_id
749 AND artifact_id = $1)',
750 array ($this->getID())) ;
752 return $this->relatedtasks;
756 * addMessage - attach a text message to this Artifact.
758 * @param string The message being attached.
759 * @param string Email address of message creator.
760 * @param bool Whether to email out a followup.
762 * @return boolean success.
764 function addMessage($body,$by=false,$send_followup=false) {
766 $this->setMissingParamsError();
769 if (session_loggedin()) {
770 $user_id=user_getid();
771 $user =& user_get_object($user_id);
772 if (!$user || !is_object($user)) {
773 $this->setError('ERROR - Logged In User But Could Not Get User Object');
776 // we'll store this email even though it will likely never be used -
777 // since we have their correct user_id, we can join the USERS table to get email
778 $by=$user->getEmail();
779 } elseif (!$this->ArtifactType->allowsAnon()) {
780 $this->setError(_('This Artifact Type Does Not Allow Anonymous Submissions. Please Login.'));
784 if (!$by || !validate_email($by)) {
785 $this->setMissingParamsError();
791 $res = db_query_params ('INSERT INTO artifact_message (artifact_id,submitted_by,from_email,adddate,body) VALUES ($1,$2,$3,$4,$5)',
792 array ($this->getID(),
796 htmlspecialchars($body))) ;
798 $this->updateLastModifiedDate();
800 if ($send_followup) {
801 $this->mailFollowupEx($now, 2, false);
807 * addHistory - add an entry to audit trail.
809 * @param string The name of the field in the database being modified.
810 * @param string The former value of this field.
811 * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
813 * @return boolean success.
815 function addHistory($field_name,$old_value, $importData = array()) {
816 if (array_key_exists('user', $importData)){
817 $user = $importData['user'];
819 if (!session_loggedin()) {
825 if (array_key_exists('time',$importData)){
826 $time = $importData['time'];
830 return db_query_params ('INSERT INTO artifact_history(artifact_id,field_name,old_value,mod_by,entrydate) VALUES ($1,$2,$3,$4,$5)',
831 array ($this->getID(),
839 * setStatus - set the status of this artifact.
841 * @param int The artifact status ID.
842 * @param int Closing date if status = 1
844 * @return boolean success.
846 function setStatus($status_id, $closingTime=False) {
848 $qpa = db_construct_qpa (false, 'UPDATE artifact SET status_id=$1', array ($status_id)) ;
849 if ($closingTime && $status_id != 1) {
851 $qpa = db_construct_qpa ($qpa, ', close_date=$1 ', array ($time)) ;
853 $qpa = db_construct_qpa ($qpa,
854 'WHERE artifact_id=$1 AND group_artifact_id=$2',
855 array ($this->getID(), $artifact_type_id)) ;
856 $result=db_query_qpa($qpa);
858 if (!$result || db_affected_rows($result) < 1) {
859 $this->setError('Error - update failed!'.db_error());
863 if (!$this->fetchData($this->getID())) {
876 * update - update the fields in this artifact.
878 * @param int The artifact priority.
879 * @param int The artifact status ID.
880 * @param int The person to which this artifact is to be assigned.
881 * @param string The artifact summary.
882 * @param int The canned response.
883 * @param string Attaching another comment.
884 * @param int Allows you to move an artifact to another type.
885 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
886 * @param string The description.
887 * @return boolean success.
889 function update($priority,$status_id,
890 $assigned_to,$summary,$canned_response,$details,$new_artifact_type_id,
891 $extra_fields=array(), $description='') {
894 Field-level permission checking
896 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'manager')) {
897 // Non-managers cannot modify these fields
898 $priority=$this->getPriority();
899 $summary=htmlspecialchars_decode($this->getSummary());
900 $description=htmlspecialchars_decode($this->getDetails());
901 $canned_response=100;
902 $new_artifact_type_id=$this->ArtifactType->getID();
903 $assigned_to=$this->getAssignedTo();
905 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'tech')) {
906 $this->setPermissionDeniedError();
911 // They may be using an extra field "status" box so we have to remap
912 // the status_id based on the extra field - this keeps the counters
915 if (count($extra_fields) > 0) {
916 $status_id=$this->ArtifactType->remapStatus($status_id,$extra_fields);
918 if (!$this->getID()) {
919 $this->setMissingParamsError('ID');
923 $this->setMissingParamsError(_('Assigned to'));
927 $this->setMissingParamsError(_('State'));
930 if (!$canned_response) {
931 $this->setMissingParamsError(_('Canned Response'));
934 if (!$new_artifact_type_id) {
935 $this->setMissingParamsError(_('Data Type'));
939 // Check that assigned_to is a tech for the tracker
940 if ($assigned_to != 100) {
941 if (!forge_check_perm_for_user ($assigned_to, 'tracker', $this->ArtifactType->getID(), 'tech')) {
942 $this->setError(_("Invalid assigned_to (assigned person is not a technician)"));
947 // Array to record which properties were changed
954 // Get a lock on this row in the database
956 $lock = db_query_params ('SELECT * FROM artifact WHERE artifact_id=$1 FOR UPDATE',
957 array ($this->getID())) ;
958 $artifact_type_id = $this->ArtifactType->getID();
960 // Attempt to move this Artifact to a new ArtifactType
961 // need to instantiate new ArtifactType obj and test perms
963 if ($new_artifact_type_id != $artifact_type_id) {
964 $newArtifactType= new ArtifactType($this->ArtifactType->getGroup(), $new_artifact_type_id);
965 if (!is_object($newArtifactType) || $newArtifactType->isError()) {
966 $this->setError(_('Could not move to new Artifact Type'). $newArtifactType->getErrorMessage());
970 // do they have perms for new ArtifactType?
971 if (!forge_check_perm ('tracker', $newArtifactType->getID(), 'manager')) {
972 $this->setPermissionDeniedError();
977 // Add a message to explain that the tracker was moved.
978 $message = 'Moved from '.$this->ArtifactType->getName().' to '.$newArtifactType->getName();
979 $this->addHistory('type', $this->ArtifactType->getName());
980 $this->addMessage($message,'',0);
982 // Fake change to send a mail when moved.
983 $changes['Type'] = 1;
985 // Try to remap extra_fields values when possible.
986 // If there is an extra_field with the same alias
987 // and if the value exist in the new one, then recode
988 // the value to keep it.
989 $new_extra_fields = array();
990 $ef = $this->ArtifactType->getExtraFields();
991 $ef_new = $newArtifactType->getExtraFields();
992 foreach($extra_fields as $extra_id => $value) {
993 $alias = preg_replace('/^@/', '', $ef[$extra_id]['alias']);
994 $type = $ef[$extra_id]['field_type'];
996 // Search if there is an extra field with the same alias.
998 foreach($ef_new as $id => $arr) {
999 if (preg_replace('/^@/', '', $arr['alias']) == $alias) {
1004 // If we found one, copy for simple fields or
1005 // search if there is the same value.
1007 if ($type == ARTIFACT_EXTRAFIELDTYPE_TEXT ||
1008 $type == ARTIFACT_EXTRAFIELDTYPE_INTEGER ||
1009 $type == ARTIFACT_EXTRAFIELDTYPE_TEXTAREA ||
1010 $type == ARTIFACT_EXTRAFIELDTYPE_RELATION) {
1011 $new_extra_fields[$new_id] = $value;
1013 $values = $newArtifactType->getExtraFieldElements($new_id);
1014 if (is_array($value)) {
1015 foreach($value as $v) {
1016 $v = $this->ArtifactType->getElementName($v);
1017 foreach($values as $ev) {
1018 if ($ev['element_name'] == $v) {
1019 $new_extra_fields[$new_id][] = $ev['element_id'];
1024 $value = $this->ArtifactType->getElementName($value);
1025 foreach($values as $ev) {
1026 if ($ev['element_name'] == $value) {
1027 $new_extra_fields[$new_id] = $ev['element_id'];
1035 // Special case if moving to a tracker with custom status (previous has not).
1036 $custom_status_id = $newArtifactType->getCustomStatusField();
1037 if ($custom_status_id && !$new_extra_fields[$custom_status_id]) {
1038 $atw = new ArtifactWorkflow($newArtifactType, $custom_status_id);
1039 $nodes = $atw->getNextNodes(100);
1041 $new_extra_fields[$custom_status_id] = $nodes[0];
1045 $extra_fields = $new_extra_fields;
1047 $res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
1048 array ($this->getID()));
1050 $this->setError(_('Removal of old artifact_extra_field_data failed: ').db_error());
1055 // Check that assigned_to is a tech in the new tracker
1056 if ($assigned_to != 100) {
1057 if (!forge_check_perm ('tracker', $newArtifactType->getID(), 'tech')) {
1062 //can't send a canned response when changing ArtifactType
1063 $canned_response=100;
1064 $this->ArtifactType =& $newArtifactType;
1068 $qpa = db_construct_qpa();
1069 $qpa = db_construct_qpa($qpa, 'UPDATE artifact SET');
1072 // handle audit trail
1075 if ($this->getStatusID() != $status_id) {
1076 $this->addHistory('status_id',$this->getStatusID());
1077 $qpa = db_construct_qpa($qpa, ' status_id=$1,', array($status_id));
1078 $changes['status'] = 1;
1081 if ($status_id != 1) {
1082 $qpa = db_construct_qpa($qpa, ' close_date=$1,', array($now));
1084 $qpa = db_construct_qpa($qpa, ' close_date=$1,', array(0));
1086 $this->addHistory('close_date', $this->getCloseDate());
1088 if ($this->getPriority() != $priority) {
1089 $this->addHistory('priority',$this->getPriority());
1090 $qpa = db_construct_qpa($qpa, ' priority=$1,', array($priority));
1091 $changes['priority'] = 1;
1095 if ($this->getAssignedTo() != $assigned_to) {
1096 $this->addHistory('assigned_to',$this->getAssignedTo());
1097 $qpa = db_construct_qpa($qpa, ' assigned_to=$1,', array($assigned_to));
1098 $changes['assigned_to'] = 1;
1101 if ($summary && ($this->getSummary() != htmlspecialchars($summary))) {
1102 $this->addHistory('summary', $this->getSummary());
1103 $qpa = db_construct_qpa($qpa, ' summary=$1,', array(htmlspecialchars($summary)));
1104 $changes['summary'] = 1;
1107 if ($description && ($this->getDetails() != htmlspecialchars($description))) {
1108 $this->addHistory('details', $this->getDetails());
1109 $qpa = db_construct_qpa($qpa, ' details=$1,', array(htmlspecialchars($description)));
1110 $changes['details'] = 1;
1114 $this->addMessage($details,'',0);
1115 $changes['details'] = 1;
1120 Finally, update the artifact itself
1123 $qpa = db_construct_qpa($qpa, ' group_artifact_id=$1
1124 WHERE artifact_id=$2 AND group_artifact_id=$3',
1125 array($new_artifact_type_id,
1126 $this->getID(), $artifact_type_id));
1127 $result = db_query_qpa($qpa);
1129 if (!$result || db_affected_rows($result) < 1) {
1130 $this->setError(_('Error - update failed!').db_error());
1134 if (!$this->fetchData($this->getID())) {
1141 //extra field handling
1143 if (!$this->updateExtraFields($extra_fields,$changes)) {
1144 //TODO - see if anything actually did change
1150 handle canned responses
1152 Instantiate ArtifactCanned and get the body of the message
1154 if ($canned_response != 100) {
1155 //don't care if this response is for this group - could be hacked
1156 $acr=new ArtifactCanned($this->ArtifactType,$canned_response);
1157 if (!$acr || !is_object($acr)) {
1158 $this->setError(_('Could Not Create Canned Response Object'));
1159 } elseif ($acr->isError()) {
1160 $this->setError($acr->getErrorMessage());
1162 $body = $acr->getBody();
1164 if (!$this->addMessage(util_unconvert_htmlspecialchars($body),'',0)) {
1171 $this->setError(_('Unable to Use Canned Response'));
1177 if ($update || $send_message){
1178 if (!empty($changes)) {
1179 // Send the email with changes
1180 $this->mailFollowupEx($now, 2, false, $changes);
1185 //nothing changed, so cancel the transaction
1186 $this->setError(_('Nothing Changed - Update Cancelled'));
1194 * updateLastModifiedDate - update the last_modified_date attribute of this artifact.
1196 * @return true on success / false on failure
1198 function updateLastModifiedDate() {
1199 $res = db_query_params ('UPDATE artifact SET last_modified_date=EXTRACT(EPOCH FROM now())::integer WHERE artifact_id=$1',
1200 array ($this->getID()));
1205 * assignToMe - assigns this artifact to current user
1207 * @return true on success / false on failure
1209 function assignToMe() {
1210 if (!session_loggedin() || !($this->ArtifactType->userIsAdmin() || $this->ArtifactType->userIsTechnician())) {
1211 $this->setPermissionDeniedError();
1215 $user_id = user_getid();
1216 $res = db_query_params ('UPDATE artifact SET assigned_to=$1 WHERE artifact_id=$2',
1217 array ($user_id, $this->getID())) ;
1219 $this->setError(_('Error updating assigned_to in artifact: ').db_error());
1222 $this->fetchData($this->getID());
1228 * updateExtraFields - updates the extra data elements for this artifact
1229 * e.g. the extra fields created and defined by the admin.
1231 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
1232 * @param array Array where changes to the extra fields should be logged
1233 * @return true on success / false on failure
1235 function updateExtraFields($extra_fields,&$changes){
1237 This is extremely complex code - we have take the passed array
1238 and see if we need to insert it into the db, and may have to
1239 add history rows for the audit trail
1241 start by getting all the available extra fields from ArtifactType
1242 For each field from ArtifacType, check the passed array -
1243 This prevents someone from passing bogus extra field entries - they will be ignored
1244 if the passed entry is blank, may have to force a default value
1245 if the passed array is different from the existing data in db,
1246 delete old entry and insert new entries, along with possible audit trail
1248 skip it and continue to next item
1253 //get a list of extra fields for this artifact_type
1254 $ef = $this->ArtifactType->getExtraFields();
1255 $efk=array_keys($ef);
1257 if (empty($extra_fields) && empty($ef)) {
1261 // If there is a status field, then check against the workflow.
1262 // Unless if we change type.
1263 if (! isset($changes['Type']) || !$changes['Type']) {
1264 for ($i=0; $i<count($efk); $i++) {
1266 $type=$ef[$efid]['field_type'];
1267 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1268 // Get previous value.
1269 $res = db_query_params ('SELECT field_data FROM artifact_extra_field_data
1270 WHERE artifact_id=$1 AND extra_field_id=$2',
1271 array($this->getID(),
1273 $old = (db_numrows($res)>0) ? db_result($res,0,'field_data') : 100;
1274 if ($old != $extra_fields[$efid]) {
1275 $atw = new ArtifactWorkflow($this->ArtifactType, $efid);
1276 if (!$atw->checkEvent($old, $extra_fields[$efid])) {
1277 $this->setError('Workflow error: You are not authorized to change the Status ('.$old.' => '.$extra_fields[$efid].')');
1285 //now we'll update this artifact for each extra field
1286 for ($i=0; $i<count($efk); $i++) {
1288 $type=$ef[$efid]['field_type'];
1290 // check required fields
1291 if ($ef[$efid]['is_required']) {
1292 if (!array_key_exists($efid, $extra_fields)) {
1293 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1294 $this->setError(_('Status Custom Field Must Be Set'));
1297 $this->setMissingParamsError($ef[$efid]['field_name']);
1302 if ($extra_fields[$efid] === '') {
1303 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1304 $this->setError(_('Status Custom Field Must Be Set'));
1307 $this->setMissingParamsError($ef[$efid]['field_name']);
1312 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT || $type == ARTIFACT_EXTRAFIELDTYPE_RADIO) &&
1313 $extra_fields[$efid] == '100') {
1314 $this->setMissingParamsError($ef[$efid]['field_name']);
1317 elseif (($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT || $type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) &&
1318 (count($extra_fields[$efid]) == 1 && $extra_fields[$efid][0] == '100')) {
1319 $this->setMissingParamsError($ef[$efid]['field_name']);
1326 // Force each field to have some value if it is a numeric field
1327 // text fields will just be purged and skipped
1329 if (!array_key_exists($efid, $extra_fields) || $extra_fields[$efid] === '') {
1330 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_RADIO)) {
1331 $extra_fields[$efid]='100';
1332 } elseif (($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX)) {
1333 $extra_fields[$efid]=array('100');
1335 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1336 array ($this->getID(),
1343 // get the old rows of data
1345 $resd = db_query_params ('SELECT * FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1346 array ($this->getID(),
1348 $rows=db_numrows($resd);
1349 if ($resd && $rows) {
1351 //POTENTIAL PROBLEM - no entry was there before, but adding one now - may need history
1354 // Compare for history purposes
1357 // these types have arrays associated to them, so they need
1358 // special handling to check for differences
1359 if ($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT || $type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) {
1360 // check the differences between the old values and the new values
1361 $old_values = util_result_column_to_array($resd,"field_data");
1363 $added_values = array_diff($extra_fields[$efid], $old_values);
1364 $deleted_values = array_diff($old_values, $extra_fields[$efid]);
1366 if (!empty($added_values) || !empty($deleted_values)) { // there are differences...
1367 $field_name = $ef[$efid]['field_name'];
1368 if (!preg_match('/^@/', $ef[$efid]['alias'])) {
1369 $changes["extra_fields"][$efid] = 1;
1372 $this->addHistory($field_name, $this->ArtifactType->getElementName(array_reverse($old_values)));
1375 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1376 array ($this->getID(),
1381 } elseif (db_result($resd,0,'field_data') == htmlspecialchars($extra_fields[$efid])) {
1382 //element did not change
1385 //element DID change - do a history entry
1386 $field_name = $ef[$efid]['field_name'];
1387 if (!preg_match('/^@/', $ef[$efid]['alias'])) {
1388 $changes["extra_fields"][$efid] = 1;
1390 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1391 array ($this->getID(),
1394 // Adding history with previous value.
1395 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_RADIO) || ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS)) {
1396 $this->addHistory($field_name,$this->ArtifactType->getElementName(db_result($resd,0,'field_data')));
1398 $this->addHistory($field_name, db_result($resd,0,'field_data'));
1404 //no history for this extra field exists
1409 // Some rewrite & consistency checks on the relation type field.
1411 // 1) Convert syntax [#NNN] to NNN
1412 // 2) Allow multiple spaces as separator.
1413 // 3) Ensure that only integers are given.
1414 // 4) Ensure that id corresponds to valid tracker id.
1416 if ($type == ARTIFACT_EXTRAFIELDTYPE_RELATION) {
1417 $value = preg_replace('/\[\#(\d+)\]/', "\\1", trim($extra_fields[$efid]));
1418 $value = preg_replace('/\\s+/', ' ', $value);
1420 foreach (explode(' ',$value) as $id) {
1421 if (preg_match('/^(\d+)$/', $id)) {
1422 // Control that the id is present in the db
1424 $res = db_query_params ('SELECT artifact_id FROM artifact WHERE artifact_id=$1',
1426 if (db_numrows($res) == 1) {
1429 $this->setError('Illegal id '.$id.', it\'s not a valid tracker id for field: '.$ef[$efid]['field_name'].'.'); // @todo: lang
1433 $this->setError('Illegal value '.$id.', only trackers id are allowed for field: '.$ef[$efid]['field_name'].'.'); // @todo: lang
1437 $extra_fields[$efid] = trim($new);
1440 // Ensure that only integer are allowed for type ARTIFACT_EXTRAFIELDTYPE_INTEGER
1441 if ($type == ARTIFACT_EXTRAFIELDTYPE_INTEGER) {
1442 $extra_fields[$efid] = trim($extra_fields[$efid]);
1443 if (!preg_match('/^[-+]?(\d+)$/', $extra_fields[$efid])) {
1444 $this->setError('Illegal value '.$extra_fields[$efid].' for field '.$ef[$efid]['field_name'].': Only integer is allowed.');
1447 if ($extra_fields[$efid] < -2147483648 || $extra_fields[$efid] > 2147483647) {
1448 $this->setError('Illegal value '.$extra_fields[$efid].' for field '.$ef[$efid]['field_name'].': Integer out of range (-2147483648 to +2147483647).');
1451 $extra_fields[$efid] = intval($extra_fields[$efid]);
1455 // See if anything was even passed for this extra_field_id
1457 if ($extra_fields[$efid] === '') {
1458 //nothing in field to update - text fields may be blank
1460 //determine the type of field and whether it should have multiple rows supporting it
1461 $type=$ef[$efid]['field_type'];
1462 if (($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($type==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
1464 $count=count($extra_fields[$efid]);
1465 for ($fin=0; $fin<$count; $fin++) {
1466 $res = db_query_params ('INSERT INTO artifact_extra_field_data (artifact_id,extra_field_id,field_data) VALUES ($1,$2,$3)',
1467 array ($this->getID(),
1469 $extra_fields[$efid][$fin])) ;
1471 $this->setError(db_error());
1478 $res = db_query_params ('INSERT INTO artifact_extra_field_data (artifact_id,extra_field_id,field_data) VALUES ($1,$2,$3)',
1479 array ($this->getID(),
1481 htmlspecialchars($extra_fields[$efid]))) ;
1483 $this->setError(db_error());
1490 unset($this->extra_field_data);
1493 $this->updateLastModifiedDate();
1499 * getExtraFieldData - get an array of data for the extra fields associated with this artifact
1501 * @return array array of data
1503 function &getExtraFieldData() {
1504 if (!isset($this->extra_field_data)) {
1505 $this->extra_field_data = array();
1506 $res = db_query_params ('SELECT * FROM artifact_extra_field_data WHERE artifact_id=$1 ORDER BY extra_field_id',
1507 array ($this->getID())) ;
1508 $ef = $this->ArtifactType->getExtraFields();
1509 while ($arr = db_fetch_array($res)) {
1510 $type=$ef[$arr['extra_field_id']]['field_type'];
1511 if (($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($type==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
1512 //accumulate a sub-array of values in cases where you may have multiple rows
1513 if (!array_key_exists($arr['extra_field_id'], $this->extra_field_data) || !is_array($this->extra_field_data[$arr['extra_field_id']])) {
1514 $this->extra_field_data[$arr['extra_field_id']] = array();
1516 $this->extra_field_data[$arr['extra_field_id']][]=$arr['field_data'];
1518 $this->extra_field_data[$arr['extra_field_id']]=$arr['field_data'];
1522 return $this->extra_field_data;
1526 * marker - adds the > symbol to fields that have been modified for the email message
1530 function marker($prop_name,$changes,$extra_field_id=0) {
1531 if ($prop_name == 'extra_fields' && isset($changes[$prop_name][$extra_field_id])) {
1533 } else if ($prop_name != 'extra_fields' && isset($changes[$prop_name])) {
1541 * mailFollowupEx - send out an email update for this artifact.
1543 * @param time_t Time of the change
1544 * @param int (1) initial/creation (2) update.
1545 * @param array Array of additional addresses to mail to.
1546 * @param array Array of fields changed in this update .
1548 * @return boolean success.
1550 function mailFollowupEx($tm,$type,$more_addresses=false,$changes='') {
1552 $monitor_ids = array();
1558 $sess = session_get_user() ;
1559 if ($type == 1) { // Initial opening
1561 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() ." item #". $this->getID() .", was opened at ". date( _('Y-m-d H:i'), $this->getOpenDate() ) . " by " . $sess->getRealName () ;
1563 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() ." item #". $this->getID() .", was opened at ". date( _('Y-m-d H:i'), $this->getOpenDate() ) ;
1567 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() .
1568 " item #" . $this->getID() .
1569 " was changed at " .
1570 date(_('Y-m-d H:i'), $tm) . " by " .
1571 $sess->getRealName();
1573 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() .
1574 " item #" . $this->getID() .
1575 " was changed at " .
1576 date(_('Y-m-d H:i'), $tm);
1581 $body .= "\nYou can respond by visiting: ".
1582 "\n".util_make_url ('/tracker/?func=detail&atid='. $this->ArtifactType->getID() .
1583 "&aid=". $this->getID() .
1584 "&group_id=". $this->ArtifactType->Group->getID()) .
1585 "\nOr by replying to this e-mail entering your response between the following markers: ".
1586 "\n".ARTIFACT_MAIL_MARKER.
1587 "\n(enter your response here, only in plain text format)".
1588 "\n".ARTIFACT_MAIL_MARKER.
1590 $this->marker('status',$changes).
1591 "Status: ". $this->getStatusName() ."\n".
1592 $this->marker('priority',$changes).
1593 "Priority: ". $this->getPriority() ."\n".
1594 "Submitted By: ". $this->getSubmittedRealName() .
1595 " (". $this->getSubmittedUnixName(). ")"."\n".
1596 $this->marker('assigned_to',$changes).
1597 "Assigned to: ". $this->getAssignedRealName() .
1598 " (". $this->getAssignedUnixName(). ")"."\n".
1599 $this->marker('summary',$changes).
1600 "Summary: ". util_unconvert_htmlspecialchars( $this->getSummary() )." \n";
1602 // Now display the extra fields
1603 $efd = $this->getExtraFieldDataText();
1604 foreach ($efd as $efid => $ef) {
1605 $body .= $this->marker('extra_fields', $changes, $efid);
1606 $body .= $ef["name"].": ".$ef["value"]."\n";
1609 $subject='['. $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() . '][' . $this->getID() .'] '. util_unconvert_htmlspecialchars( $this->getSummary() );
1612 // get all the email addresses that are monitoring this request or the ArtifactType
1613 $monitor_ids = $this->getMonitorIds();
1615 // initial creation, we just get the users monitoring the ArtifactType
1616 $monitor_ids = $this->ArtifactType->getMonitorIds();
1620 if ($more_addresses) {
1621 $emails[] = $more_addresses;
1623 //we don't email the current user
1624 if ($this->getAssignedTo() != user_getid()) {
1625 $monitor_ids[] = $this->getAssignedTo();
1627 if ($this->getSubmittedBy() != user_getid()) {
1628 $monitor_ids[] = $this->getSubmittedBy();
1630 //initial submission
1632 //if an email is set for this ArtifactType
1633 //add that address to the BCC: list
1634 if ($this->ArtifactType->getEmailAddress()) {
1635 $emails[] = $this->ArtifactType->getEmailAddress();
1639 if ($this->ArtifactType->emailAll()) {
1640 $emails[] = $this->ArtifactType->getEmailAddress();
1644 $body .= "\n\nInitial Comment:".
1645 "\n".util_unconvert_htmlspecialchars( $this->getDetails() ) .
1646 "\n\n----------------------------------------------------------------------";
1650 Now include the followups
1652 $result2=$this->getMessages();
1654 $rows=db_numrows($result2);
1656 if ($result2 && $rows > 0) {
1657 for ($i=0; $i<$rows; $i++) {
1659 // for messages posted by non-logged-in users,
1660 // we grab the email they gave us
1662 // otherwise we use the confirmed one from the users table
1664 if (db_result($result2,$i,'user_id') == 100) {
1665 $emails[] = db_result($result2,$i,'from_email');
1667 $monitor_ids[] = db_result($result2,$i,'user_id');
1673 $body .= $this->marker('details',$changes);
1675 $body .= "Comment By: ". db_result($result2,$i,'realname') . " (".db_result($result2,$i,'user_name').")".
1676 "\nDate: ". date( _('Y-m-d H:i'),db_result($result2,$i,'adddate') ).
1678 "\n".util_unconvert_htmlspecialchars( db_result($result2,$i,'body') ).
1679 "\n\n----------------------------------------------------------------------";
1685 $body .= "\n\nYou can respond by visiting: ".
1686 "\n".util_make_url ('/tracker/?func=detail&atid='. $this->ArtifactType->getID() .
1687 "&aid=". $this->getID() .
1688 "&group_id=". $this->ArtifactType->Group->getID());
1690 //only send if some recipients were found
1691 if (count($emails) < 1 && count($monitor_ids) < 1) {
1695 if (count($monitor_ids) < 1) {
1696 $monitor_ids=array();
1698 $monitor_ids=array_unique($monitor_ids);
1701 $from = $this->ArtifactType->getReturnEmailAddress();
1702 $extra_headers = 'Reply-to: '.$from;
1704 // load the e-mail addresses of the users
1705 $users =& user_get_objects($monitor_ids);
1706 if (count($users) > 0) {
1707 foreach ($users as $user) {
1708 if ($user->getStatus() == "A") { //we are only sending emails to active users
1709 $emails[] = $user->getEmail();
1714 //now remove all duplicates from the email list
1715 if (count($emails) > 0) {
1716 $BCC=implode(',',array_unique($emails));
1717 util_send_message('',$subject,$body,$from,$BCC,'',$extra_headers);
1720 $this->sendSubjectMsg = $subject;
1721 $this->sendBodyMsg = $body;
1723 //util_handle_message($monitor_ids,$subject,$body,$BCC);
1729 * getExtraFieldDataText - Return the extra fields' data in a human-readable form.
1731 * @return array Array containing field ID => field name and value associated to it for
1734 function getExtraFieldDataText() {
1735 // First we get the list of extra fields and the data
1736 // associated to the fields
1737 $efs = $this->ArtifactType->getExtraFields();
1738 $efd = $this->getExtraFieldData();
1742 foreach ($efs as $efid => $ef) {
1743 $name = $ef["field_name"];
1744 $type = $ef["field_type"];
1746 // Get the value according to the type
1749 // for these types, the associated value comes straight
1750 case ARTIFACT_EXTRAFIELDTYPE_TEXT:
1751 case ARTIFACT_EXTRAFIELDTYPE_TEXTAREA:
1752 case ARTIFACT_EXTRAFIELDTYPE_RELATION:
1753 case ARTIFACT_EXTRAFIELDTYPE_INTEGER:
1754 if (isset($efd[$efid])) {
1755 $value = $efd[$efid];
1761 // the other types have and ID or an array of IDs associated to them
1763 if (isset($efd[$efid])) {
1764 $value = $this->ArtifactType->getElementName($efd[$efid]);
1770 $return[$efid] = array("name" => $name, "value" => $value, 'type' => $type);
1777 class ArtifactComparator {
1778 var $criterion = 'artifact_id' ;
1779 var $order = 'ASC' ;
1781 function Compare ($a, $b) {
1782 if ($this->order == 'DESC') {
1783 $c = $a ; $a = $b ; $b = $c ;
1785 switch ($this->criterion) {
1787 $namecmp = strcoll ($a->getSummary(),
1789 if ($namecmp != 0) {
1794 $namecmp = strcoll (user_get_object($a->getAssignedTo())->getRealName(),
1795 user_get_object($b->getAssignedTo())->getRealName()) ;
1796 if ($namecmp != 0) {
1800 case 'submitted_by':
1801 $namecmp = strcoll (user_get_object($a->getSubmittedBy())->getRealName(),
1802 user_get_object($b->getSubmittedBy())->getRealName()) ;
1803 if ($namecmp != 0) {
1808 $a_date = $a->getOpenDate() ;
1809 $b_date = $b->getOpenDate() ;
1810 return ($a_date < $b_date) ? -1 : 1;
1813 $a_date = $a->getCloseDate() ;
1814 $b_date = $b->getCloseDate() ;
1815 return ($a_date < $b_date) ? -1 : 1;
1817 case 'last_modified_date':
1818 $a_date = $a->getLastModifiedDate() ;
1819 $b_date = $b->getLastModifiedDate() ;
1820 return ($a_date < $b_date) ? -1 : 1;
1823 $a_prority = $a->getPriority() ;
1824 $b_prority = $b->getPriority() ;
1825 return ($a_prority < $b_prority) ? -1 : 1;
1828 $aa=$a->getExtraFieldDataText();
1829 $ba=$b->getExtraFieldDataText();
1830 $af=$aa[$this->criterion]['value'];
1831 $bf=$ba[$this->criterion]['value'];
1832 $namecmp = strcoll ($af,$bf) ;
1833 if ($namecmp != 0) {
1839 // When in doubt, sort on artifact ID
1840 $aid = $a->getID() ;
1841 $bid = $b->getID() ;
1845 return ($aid < $bid) ? -1 : 1;
1849 function sortArtifactList (&$list, $criterion='name', $order='ASC') {
1850 $cmp = new ArtifactComparator () ;
1851 $cmp->criterion = $criterion ;
1852 $cmp->order = $order ;
1854 return usort ($list, array ($cmp, 'Compare')) ;
1859 // c-file-style: "bsd"