gforge-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gforge-commits] gforge/common/tracker Artifact.class, 1.21, 1.22 Artifa


From: tperdue
Subject: [Gforge-commits] gforge/common/tracker Artifact.class, 1.21, 1.22 ArtifactExtraField.class, NONE, 1.1 ArtifactSelectionBox.class, 1.2, NONE ArtifactType.class, 1.26, 1.27
Date: Thu, 07 Oct 2004 14:30:52 -0500

Update of /cvsroot/gforge/gforge/common/tracker
In directory db.perdue.net:/home/tperdue/share/dev.gforge.org/common/tracker

Modified Files:
        Artifact.class ArtifactType.class 
Added Files:
        ArtifactExtraField.class 
Removed Files:
        ArtifactSelectionBox.class 
Log Message:
Massive tracker reorg and cleanup

Index: Artifact.class
===================================================================
RCS file: /cvsroot/gforge/gforge/common/tracker/Artifact.class,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- Artifact.class      6 Oct 2004 16:27:11 -0000       1.21
+++ Artifact.class      7 Oct 2004 19:30:49 -0000       1.22
@@ -77,9 +77,9 @@
        /**
         * Array of artifact data for extra fields defined by Admin.
         *
-        * @var         array   $data_extra_field_array.
+        * @var         array   $extra_field_data.
         */
-       var $data_extra_field_array;
+       var $extra_field_data;
 
        /**
         * Array of ArtifactFile objects.
@@ -152,10 +152,10 @@
         *      @param  string  Details of the artifact.
         *      @param  int             The ID of the user to which this 
artifact is to be assigned.
         *      @param  int             The artifacts priority.
-        *      @param  string  An email address to add to the monitoring queue.
+        *      @param  array   Array of extra fields like: 
array(15=>'foobar',22=>'1');
         *  @return id on success / false on failure.
         */
-       function create($category_id, $artifact_group_id, $summary, $details, 
$assigned_to=100, $priority=5, $monitor_email=false) {
+       function create($category_id, $artifact_group_id, $summary, $details, 
$assigned_to=100, $priority=5, $extra_fields=array()) {
                global $Language;
                
                //
@@ -268,8 +268,12 @@
                        if (!$this->fetchData($artifact_id)) {
                                db_rollback();
                                return false;
+                       } else {
+                               if (!$this->updateExtraFields($extra_fields)) {
+                                       db_rollback();
+                                       return false;
+                               }
                        }
-
                        //
                        //      now send an email if appropriate
                        //
@@ -279,34 +283,6 @@
                        return $artifact_id;
                }
        }
-       /**
-        *
-        *      createExtraFields - adds a row in the table used to 
-        *      store the id of a value for an artifact field.
-        *      This function is only used for data that 
-        *      applies to additional fields and boxes configured by the admin.
-        *
-        *      @param  int     id of the field that contains the data
-        *      @return         id on success / false on failure
-        */
-       function createExtraFields($choice_id){
-               $this->choice_id=$choice_id;
-               $res=db_query("INSERT INTO artifact_extra_field_data
-                       (artifact_id, choice_id)
-                       VALUES
-                       ('".$this->getID()."',$this->choice_id)");
-                                       
-               if (!$res) {
-                       $this->setError('Artifact: '.db_error());
-                       db_rollback();
-                       return false;
-               }
-
-               return $choice_id;
-       
-       }
-       
-
        
        /**
         *      fetchData - re-fetch the data for this Artifact from the 
database.
@@ -390,15 +366,6 @@
        }
 
        /**
-        *      getExtraFieldID - get choice_id flag.
-        *
-        *      @return int choice_id.
-        */
-       function getExtraFieldID() {
-               return $this->data_extra_field_array['choice_id'];
-       }
-
-       /**
         *      getCategoryName - get category text name.
         *
         *      @return string  The category name.
@@ -748,10 +715,11 @@
         *      @param  int             The canned response.
         *      @param  string  Attaching another comment.
         *      @param  int             Allows you to move an artifact to 
another type.
+        *      @param  array   Array of extra fields like: 
array(15=>'foobar',22=>'1');
         *      @return boolean success.
         */
        function 
update($priority,$status_id,$category_id,$artifact_group_id,$resolution_id,
-               
$assigned_to,$summary,$canned_response,$details,$new_artifact_type_id) {
+               
$assigned_to,$summary,$canned_response,$details,$new_artifact_type_id,$extra_fields=array())
 {
 
                global $Language;
                if (!$this->getID() 
@@ -908,10 +876,17 @@
                                return false;
                        } else {
                                $this->fetchData($this->getID());
-//error check the data fetching??
+//TODO error check the data fetching??
                        }
                }
 
+               //extra field handling
+               $update=true;
+               if (!$this->updateExtraFields($extra_fields)) {
+//TODO - see if anything actualyl did change
+                       db_rollback();
+                       return false;
+               }
                /*
                        handle canned responses
 
@@ -957,65 +932,81 @@
        }
 
        /**
-        *      updateExtraFields - updates the id of a value in the 
-        *      table used to store the id's of values for artifact fields. 
-        *      This function is only used for data that 
-        *      applies to additional fields and boxes configured by the admin.
+        *      updateExtraFields - updates the extra data elements for this 
artifact
+        *      e.g. the extra fields created and defined by the admin.
         *
-        *      @param  int     id of the artifact
-        *      @param  int     id of the field that contains the data 
+        *      @param  array   Array of extra fields like: 
array(15=>'foobar',22=>'1');
         *      @return true on success / false on failure
-        *
         */
-       function updateExtraFields($id,$choice_id){
-                       
-               $res=db_query("UPDATE artifact_extra_field_data
-                       SET
-                       choice_id='$choice_id'
-                       WHERE
-                       id='$id'");
-       
-                       
-               if (!$res) {
-                       $this->setError('Artifact: '.db_error());
-                       db_rollback();
-                       return false;
+       function updateExtraFields($extra_fields){
+               if (empty($extra_fields)) {
+                       return true;
                }
+               //get a list of extra fields for this artifact_type
+               $ef =& $this->ArtifactType->getExtraFields();
 
+               //now we'll update this artifact for each extra field
+               for ($i=0; $i<count($ef); $i++) {
+                       //
+                       //      First we want to get old value of this element
+                       //
+                       $res=db_query("SELECT field_data FROM 
artifact_extra_field_data
+                               WHERE
+                               artifact_id='".$this->getID()."'
+                               AND 
extra_field_id='".$ef[$i]['extra_field_id']."'");
+                       //      make sure we have a corresponding row in 
+                       //      artifact_extra_field_data - if not we'll create 
one
+                       if ($res && db_numrows($res) > 0) {
+
+                               // if this field changed, update the db
+                               if (addslashes(db_result($res,0,'field_data')) 
!= htmlspecialchars($extra_fields[$ef[$i]['extra_field_id']])) {
+//TODO add history
+                                       $res=db_query("UPDATE 
artifact_extra_field_data
+                                               SET
+                                               
field_data='".$extra_fields[$ef[$i]['extra_field_id']]."'
+                                               WHERE
+                                               artifact_id='".$this->getID()."'
+                                               AND 
extra_field_id='".$ef[$i]['extra_field_id']."'");
+                                       if (!$res) {
+                                               
$this->setError('Artifact::updateExtraFields:: '.db_error());
+                                               return false;
+                                       }
+                               }
+                       } else {
+                               //insert a fresh row since one does not exist 
for this extra field yet
+                               $res=db_query("INSERT INTO 
artifact_extra_field_data (artifact_id,extra_field_id,field_data) 
+                                       values 
('".$this->getID()."','".$ef[$i]['extra_field_id']."','".htmlspecialchars($extra_fields[$ef[$i]['extra_field_id']])."')");
+                                       if (!$res) {
+                                               
$this->setError('Artifact::updateExtraFields:: '.db_error());
+                                               return false;
+                                       }
+                       }
+               }
+               unset($this->extra_field_data);
                return true;
        }
 
        /**
+        *      getExtraFieldData - get an array of data for the extra fields 
associated with this artifact
         *
-        *      nullExtraFields - deletes a row in the table used to    
-        *      store the id's of values for artifact fields.  This function
-        *      applies to additional fields and boxes configured by the admin.
-        *
-        *      @param  int     id of the artifact
-        *      @return         true on success / false on failure
+        *      @return array   array of data
         */
-       function  nullExtraFields($artifact_id){
-                       
-               $res=db_query("DELETE  
-                       FROM
-                       artifact_extra_field_data
-                       WHERE
-                       artifact_id='$artifact_id'");
-       
-                       
-               if (!$res) {
-                       $this->setError('Artifact: '.db_error());
-                       db_rollback();
-                       return false;
+       function &getExtraFieldData() {
+               if (!isset($this->extra_field_data)) {
+                       $res=db_query("SELECT * FROM artifact_extra_field_data 
+                               WHERE artifact_id='".$this->getID()."'");
+                       while ($arr =& db_fetch_array($res)) {
+                               
$this->extra_field_data[$arr['extra_field_id']]=$arr['field_data'];
+                       }
                }
-
-               return true;
+               return $this->extra_field_data;
        }
 
-       
-
-
-       // function which returns proper marker for changed properties
+       /**
+        *      marker - adds the > symbol to fields that have been modified 
for the email message
+        *
+        *
+        */
        function marker($prop_name,$changes) {
                if ($changes[$prop_name]) {
                        return '>';

--- NEW FILE: ArtifactExtraField.class ---
<?php
/**
 * ArtifactExtraField.class - Class to handle user defined artifacts
 *
 * Copyright 2004 (c) Anthony J. Pugliese
 *
 * @version   $Id: ArtifactExtraField.class,v 1.1 2004/10/07 19:30:49 tperdue 
Exp $
 *
 * This file is part of GForge.
 *
 * GForge 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.
 *
 * GForge 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 GForge; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  US
 */
require_once('common/include/Error.class');

define('ARTIFACT_EXTRAFIELDTYPE_SELECT',1);
define('ARTIFACT_EXTRAFIELDTYPE_RADIO',3);
define('ARTIFACT_EXTRAFIELDTYPE_TEXT',4);
//define('ARTIFACT_EXTRAFIELDTYPE_CHECKBOX',2);
//define('ARTIFACT_EXTRAFIELDTYPE_MULTISELECT',5);
define('ARTIFACT_EXTRAFIELDTYPE_TEXTAREA',6);

class ArtifactExtraField extends Error {

        /** 
         * The artifact type object.
         *
         * @var         object  $ArtifactType.
         */
        var $ArtifactType; //object

        /**
         * Array of artifact data.
         *
         * @var         array   $data_array.
         */
        var $data_array;

        /**
         *      ArtifactExtraField - Constructer
         *
         *      @param  object  ArtifactType object.
         *  @param      array   (all fields from artifact_file_user_vw) OR id 
from database.
         *  @return     boolean success.
         */
        function ArtifactExtraField(&$ArtifactType, $data=false) {
                $this->Error(); 

                //was ArtifactType legit?
                if (!$ArtifactType || !is_object($ArtifactType)) {
                        $this->setError('ArtifactExtraField: No Valid 
ArtifactType');
                        return false;
                }
                //did ArtifactType have an error?
                if ($ArtifactType->isError()) {
                        $this->setError('ArtifactExtraField: 
'.$Artifact->getErrorMessage());
                        return false;
                }
                $this->ArtifactType =& $ArtifactType;

                if ($data) {
                        if (is_array($data)) {
                                $this->data_array =& $data;
                                return true;
                        } else {
                                if (!$this->fetchData($data)) {
                                        return false;
                                } else {
                                        return true;
                                }
                        }
                }
        }

        /**
         *      create - create a row in the table that stores box names for a
         *      a tracker.  This function is only used to create rows for boxes 
         *      configured by the admin.
         *
         *      @param  string  Name of the box.
         *  @return     true on success / false on failure.
         */
        function create($name) {
                global $Language;
                
                //
                //      data validation
                //
                if (!$name) {
                        
$this->setError($Language->getText('tracker_admin_build_boxes','required_box_name'));
                        return false;
                }
                if (!$this->ArtifactType->userIsAdmin()) {
                        $this->setPermissionDeniedError();
                        return false;
                }
                $sql="INSERT INTO artifact_extra_field_list 
(group_artifact_id,field_name) 
                        VALUES 
('".$this->ArtifactType->getID()."','".htmlspecialchars($name)."')";

                $result=db_query($sql);

                if ($result && db_affected_rows($result) > 0) {
                        $this->clearError();
                        return true;
                } else {
                        $this->setError(db_error());
                        return false;
                }
                        //
                        //      Now set up our internal data structures
                        //
                        if (!$this->fetchData($id)) {
                                return false;
                        } 

        }
        /**
         *      fetchData - re-fetch the data for this ArtifactExtraField from 
the database.
         *
         *      @param  int             ID of the Box.
         *      @return boolean success.
         */
        function fetchData($id) {
                $this->id=$id;
                $res=db_query("SELECT * FROM artifact_extra_field_list WHERE 
extra_field_id='$id'");
                
                if (!$res || db_numrows($res) < 1) {
                        $this->setError('ArtifactExtraField: Invalid 
ArtifactExtraField ID');
                        return false;
                }
                $this->data_array =& db_fetch_array($res);
                db_free_result($res);
                return true;
        }

        /**
         *      getArtifactType - get the ArtifactType Object this 
ArtifactExtraField is associated with.
         *
         *      @return object  ArtifactType.
         */
        function &getArtifactType() {
                return $this->ArtifactType;
        }
        
        /**
         *      getID - get this ArtifactExtraField ID.
         *
         *      @return int     The id #.
         */
        function getID() {
                return $this->data_array['extra_field_id'];
        }

        /**
         *      getName - get the name.
         *
         *      @return string  The name.
         */
        function getName() {
                return $this->data_array['field_name'];
        }

        /**
         *  update - update a row in the table used to store box names 
         *  for a tracker.  This function is only to update rowsf
         *  for boxes configured by
         *  the admin.
         *
         *  @param      string  Name of the box.
         *  @return     boolean success.
         */
        function update($name) {
                if (!$this->ArtifactType->userIsAdmin()) {
                        $this->setPermissionDeniedError();
                        return false;
                }   
                $sql="UPDATE artifact_extra_field_list 
                        SET field_name='".htmlspecialchars($name)."' 
                        WHERE extra_field_id='". $this->getID() ."' 
                        AND 
group_artifact_id='".$this->ArtifactType->getID()."'";
                $result=db_query($sql);
                if ($result && db_affected_rows($result) > 0) {
                        return true;
                } else {
                        $this->setError(db_error());
                        return false;
                }
        }
}

?>

--- ArtifactSelectionBox.class DELETED ---

Index: ArtifactType.class
===================================================================
RCS file: /cvsroot/gforge/gforge/common/tracker/ArtifactType.class,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- ArtifactType.class  6 Oct 2004 16:27:11 -0000       1.26
+++ ArtifactType.class  7 Oct 2004 19:30:49 -0000       1.27
@@ -63,18 +63,18 @@
        var $Group; //group object
 
        /**
-        * Selection boxes db resource ID.
+        * extra_fields 3d array - the IDs and Names of the extra fields
         *
-        * @var         int             $selection_boxes_res.
+        * @var         array extra_fields;
         */
-       var $selection_boxes_res;
+       var $extra_fields;
 
        /**
-        * Box options  db resource ID.
+        * extra_field[extra_field_id] array - the IDs and Names of elements on 
the extra fields
         *
-        * @var         int             $box_options_res.
+        * @var         array   extra_field
         */
-       var $box_options_res;
+       var $extra_field;
        
        /**
         * Options      db resource ID.
@@ -454,148 +454,75 @@
        }
 
        /**
-        *      getSelectionBoxes - List of possible user built selection 
-        *      boxes set up for this artifact type.
+        *      getExtraFields - List of possible user built extra fields
+        *      set up for this artifact type.
         *
         *      @return database result set.
         */
-       function getSelectionBoxes() {
-               if (!isset($this->selection_boxes_res)) {
-                       $sql="select id,selection_box_name
-                               FROM artifact_group_selection_box_list 
+       function getExtraFields() {
+               if (!isset($this->extra_fields)) {
+                       $sql="select *
+                               FROM artifact_extra_field_list 
                                WHERE group_artifact_id='".$this->getID() ."'
-                               ORDER BY id";
-                       $this->selection_boxes_res=db_query($sql);
+                               ORDER BY field_type ASC";
+                       $res=db_query($sql);
+                       $i=0;
+                       while($arr =& db_fetch_array($res)) {
+                               $this->extra_fields[$i++] = $arr;
+                       }
                }
-               return $this->selection_boxes_res;
+               return $this->extra_fields;
        }
 
        /**
-        *      getBoxName - Get a box name using the box ID 
+        *      getExtraFieldName - Get a box name using the box ID 
         *
-        *      @param  int     id of a box
-        *      @return database result set.
+        *      @param  int     id of an extra field.
+        *      @return string  name of extra field.
         */
-       function getBoxName($box_id) {
-               $this->box=$box_id;
-               if (!isset($this->selection_boxes_res)) {
-                       $sql="select selection_box_name
-                               FROM artifact_group_selection_box_list 
-                               WHERE id='".$this->box."'
-                               AND group_artifact_id='".$this->getID()."'";
-                       $this->selection_boxes_res=db_query($sql);
-               }
-               return $this->selection_boxes_res;
+       function getExtraFieldName($box_id) {
+               $arr =& $this->getExtraFields();
+               return $arr['extra_field_id']['field_name'];
        }
 
-
        /**
-        *      getBoxEntry - Get a box fields using the box ID 
+        *      getExtraFieldElements - List of possible admin configured 
+        *      extra field elements. This function is used to 
+        *      present the boxes and choices on the main Add/Update page.
         *
-        *      @param  int     id of a box
-        *      @return database result set.
+        *      @param  int     id of the extra field
+        *      @return array of elements for this extra field.
         */
-       function getBoxEntry($box_id) {
-               $this->box=$box_id;
-               if (!isset($this->selection_boxes_res)) {
-                       $sql="SELECT *
-                               FROM artifact_group_selection_box_list 
-                               WHERE id='".$this->box."'
-                               ";
-                       $this->selection_boxes_res=db_query($sql);
+       function getExtraFieldElements($id) {
+//TODO validate $id
+               if (!$id) {
+                       return false;
                }
-               return $this->selection_boxes_res;
-       }
-
-
-       /**
-        *      getSelectionBoxOptions - List of possible admin configured 
-        *      choices for a selection box. This function is used to 
-        *      present the boxes 
-        *      and choices on the main Add/Update page.
-        *
-        *      @param  int     id of the selection box
-        *      @return database result set.
-        */
-       function getSelectionBoxOptions($box) {
-               $this->box=$box;
-               $sql="select id,box_options_name
-                       FROM artifact_group_selection_box_options
-                       WHERE artifact_box_id ='".$this->box."'  
-                       ORDER BY box_options_name";
-               $this->box_options_res=db_query($sql);
-               return $this->box_options_res;
-       }       
-
-       /**
-        *      getBoxOptions - List of possible admin configured selection 
-        *      choices for a single selection box.  This function is used
-        *      to display choices when updating.
-        *
-        *      @return database result set.
-        */
-       function getBoxOptions() {
-               $sql="select id,artifact_box_id,box_options_name
-                       FROM artifact_group_selection_box_options
-                       WHERE EXISTS (SELECT id FROM 
artifact_group_selection_box_list 
-                       WHERE group_artifact_id='".$this->getID()."'
-                       AND artifact_group_selection_box_list.id = 
artifact_group_selection_box_options.artifact_box_id)
-                       ORDER BY box_options_name";
-               $this->box_options_res=db_query($sql);
-               return $this->box_options_res;
-       
-       }
-
-
-       /**
-        *      getBoxOptionName - List the name admin configured selection 
-        *      choices for a single selection box.  This function is used
-        *      copying choices.
-        *
-        *      @return database result set.
-        */
-       function getBoxOptionName($choiceid) {
-               $this->choiceid = $choiceid;
-               $sql="select id,artifact_box_id,box_options_name
-                       FROM artifact_group_selection_box_options
-                       WHERE id ='".$this->choiceid."'";
-               $this->box_options_res=db_query($sql);
-               return $this->box_options_res;
-       
-       }
-
-       /**
-        *      getArtifactChoices - This function is used to get a list the 
-        *      fields in an artifact from the table of choices that is build 
-        *      by submiting/updating new artifacts.
-        *      
-        *      @param  int     id of the artifact.
-        *      @return         databse result set.
-        */
-       function getArtifactChoices($artifact_id){
-               $this->choice=$artifact_id;
-               $sql="select id,artifact_id,choice_id
-                       FROM artifact_extra_field_data
-                       WHERE artifact_id='".$this->choice."'
-                       ORDER BY id";
-               $this->choice_res=db_query($sql);
-               return $this->choice_res;
+               if (!isset($this->extra_field[$id])) {
+                       $sql="select element_id,element_name
+                               FROM artifact_extra_field_elements
+                               WHERE extra_field_id ='".$id."'  
+                               ORDER BY element_name";
+                       $res=db_query($sql);
+                       $i=0;
+                       while($arr =& db_fetch_array($res)) {
+                               $this->extra_field[$id][$i++] = $arr;
+                       }
+               }
+               return $this->extra_field[$id];
        }
 
        /**
-        *      getBoxOptionName - This function is used to get a name of 
-        *      a choice for a box.
+        *      getElementName - get the name of a particular element.
         *
-        *      @param  int     id of the choice.
-        *      @return         database result set.
+        *      @return string  The name.
         */
-       function getBoxOptionsName($choice_id) {
-               $this->choice = $choice_id;
-               $sql="select id, box_options_name
-                       FROM artifact_group_selection_box_options 
-                       WHERE id = '".$this->choice."'";
-               $this->options_res=db_query($sql);
-               return $this->options_res;
+       function getElementName($choiceid) {
+               $sql="select element_id,extra_field_id,element_name
+                       FROM artifact_extra_field_elements
+                       WHERE element_id ='$choiceid'";
+               $res=db_query($sql);
+               return db_result($res,0,'element_name');
        }
 
        /**
@@ -619,15 +546,12 @@
                        WHERE EXISTS (SELECT artifact_id FROM artifact 
                        WHERE group_artifact_id='".$this->getID()."'
                        AND 
artifact.artifact_id=artifact_extra_field_data.artifact_id)");
-                       
-               db_query("DELETE FROM artifact_group_selection_box_options
-                       WHERE EXISTS (SELECT id FROM 
artifact_group_selection_box_list 
+               db_query("DELETE FROM artifact_extra_field_elements
+                       WHERE EXISTS (SELECT extra_field_id FROM 
artifact_extra_field_list 
                        WHERE group_artifact_id='".$this->getID()."'
-                       AND artifact_group_selection_box_list.id = 
artifact_group_selection_box_options.artifact_box_id)");
-
-               db_query ("DELETE FROM artifact_group_selection_box_list
+                       AND artifact_extra_field_list.extra_field_id = 
artifact_extra_field_elements.extra_field_id)");
+               db_query ("DELETE FROM artifact_extra_field_list
                        WHERE group_artifact_id='".$this->getID()."'");
-
                db_query("DELETE FROM artifact_canned_responses 
                        WHERE group_artifact_id='".$this->getID()."'");
 //echo '1'.db_error();





reply via email to

[Prev in Thread] Current Thread [Next in Thread]