//define('ARTIFACT_EXTRAFIELDTYPE_ASSIGNEE',8);
define('ARTIFACT_EXTRAFIELDTYPE_RELATION',9);
define('ARTIFACT_EXTRAFIELDTYPE_INTEGER',10);
+/* reserved for aljeux extension, for merge into FusionForge */
+define('ARTIFACT_EXTRAFIELDTYPE_FORMULA',11);
+/* reserved for Evolvis extension, for merge into FusionForge */
+define('ARTIFACT_EXTRAFIELDTYPE_DATETIME',12);
class ArtifactExtraField extends Error {
- /**
+ /**
* The artifact type object.
*
* @var object $ArtifactType.
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.
+ * @param $ArtifactType
+ * @param bool $data
*/
- function ArtifactExtraField(&$ArtifactType, $data=false) {
- $this->Error();
+ function __construct(&$ArtifactType, $data=false) {
+ $this->Error();
//was ArtifactType legit?
if (!$ArtifactType || !is_object($ArtifactType)) {
$this->setError('ArtifactExtraField: No Valid ArtifactType');
- return false;
+ return;
}
//did ArtifactType have an error?
if ($ArtifactType->isError()) {
$this->setError('ArtifactExtraField: '.$ArtifactType->getErrorMessage());
- return false;
+ return;
}
$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;
- }
+ $this->fetchData($data);
}
}
}
/**
* 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
+ * a tracker. This function is only used to create rows for boxes
* configured by the admin.
*
* @param string Name of the extra field.
}
if (!$field_type) {
$this->setError(_('Type of custom field not selected'));
- return false;
+ return false;
}
if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
$this->setPermissionDeniedError();
return false;
}
}
-
+
if ($is_required) {
$is_required=1;
} else {
$is_required=0;
- }
-
+ }
+
if (!($alias = $this->generateAlias($alias,$name))) {
return false;
}
-
+
db_begin();
- $result = db_query_params ('INSERT INTO artifact_extra_field_list (group_artifact_id,field_name,field_type,attribute1,attribute2,is_required,alias)
+ $result = db_query_params ('INSERT INTO artifact_extra_field_list (group_artifact_id,field_name,field_type,attribute1,attribute2,is_required,alias)
VALUES ($1,$2,$3,$4,$5,$6,$7)',
array ($this->ArtifactType->getID(),
htmlspecialchars($name),
//
// Must insert some default 100 rows for the data table so None queries will work right
//
- $resdefault = db_query_params ('INSERT INTO artifact_extra_field_data(artifact_id,field_data,extra_field_id)
+ $resdefault = db_query_params ('INSERT INTO artifact_extra_field_data(artifact_id,field_data,extra_field_id)
SELECT artifact_id,100,$1 FROM artifact WHERE group_artifact_id=$2',
array ($id,
$this->ArtifactType->getID())) ;
/**
* fetchData - re-fetch the data for this ArtifactExtraField from the database.
*
- * @param int ID of the Box.
+ * @param int $id ID of the Box.
* @return boolean success.
*/
function fetchData($id) {
$this->id=$id;
$res = db_query_params ('SELECT * FROM artifact_extra_field_list WHERE extra_field_id=$1',
array ($id)) ;
-
+
if (!$res || db_numrows($res) < 1) {
$this->setError('ArtifactExtraField: Invalid ArtifactExtraField ID');
return false;
function &getArtifactType() {
return $this->ArtifactType;
}
-
+
/**
* getID - get this ArtifactExtraField ID.
*
10=>_('Integer')
);
}
-
+
/**
* getAlias - the alias that is used for this field
*
function getAlias() {
return $this->data_array['alias'];
}
-
+
/**
* getAvailableValues - Get the list of available values for this extra field
*
}
/**
- * update - update a row in the table used to store box names
+ * 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.
$this->setError(_('a field name is required'));
return false;
}
- $res = db_query_params ('SELECT field_name FROM artifact_extra_field_list
+ $res = db_query_params ('SELECT field_name FROM artifact_extra_field_list
WHERE field_name=$1 AND group_artifact_id=$2 AND extra_field_id !=$3',
array($name,
$this->ArtifactType->getID(),
} else {
$is_required=0;
}
-
+
if (!($alias = $this->generateAlias($alias,$name))) {
return false;
- }
+ }
- $result = db_query_params ('UPDATE artifact_extra_field_list
+ $result = db_query_params ('UPDATE artifact_extra_field_list
SET field_name=$1,
attribute1=$2,
attribute2=$3,
}
}
-
+
/**
* Validate an alias.
* Note that this function does not check for conflicts.
// invalid chars?
if (preg_match("/[^[:alnum:]_@\\-]/", $alias)) {
- $this->setError(_('The alias contains invalid characters. Only letters, numbers, hypens (-), arobase (@) and underscores (_) allowed.'));
+ $this->setError(_('The alias contains invalid characters. Only letters, numbers, hypens (-), at sign (@) and underscores (_) allowed.'));
return false;
- } else if (in_array($alias, $reserved_alias)) { // alias is reserved?
+ } elseif (in_array($alias, $reserved_alias)) { // alias is reserved?
$this->setError(sprintf(_('\'%1$s\' is a reserved alias. Please provide another name.'), $alias));
return false;
}
-
+
return true;
}
-
+
/**
* Generate an alias for this field. The alias can be entered by the user or
* be generated automatically from the name of the field.
- * @param string Alias entered by the user
- * @param string Name of the field entered by the user (it'll be used when $alias is empty)
+ * @param string $alias Alias entered by the user
+ * @param string $name Name of the field entered by the user (it'll be used when $alias is empty)
* @return string
*/
function generateAlias($alias, $name) {
$alias = strtolower(trim($alias));
if (strlen($alias) == 0) { // no alias was entered, generate alias from $name
$name = strtolower(trim($name));
- // Convert the original name to a valid alias (i.e., if the extra field is
+ // Convert the original name to a valid alias (i.e., if the extra field is
// called "Quality test", make an alias called "quality_test").
// The alias can be seen as a "unix name" for this field
$alias = preg_replace("/ /", "_", $name);
} elseif (!$this->validateAlias($alias)) {
// alias is invalid...
return false;
- }
+ }
// check if the name conflicts with another alias in the same artifact type
// in that case append a serial number to the alias
$serial = 1;
- $conflict = false;
+ $conflict = false;
do {
if ($this->data_array['extra_field_id']) {
$res = db_query_params ('SELECT * FROM artifact_extra_field_list
if (!$res) {
$this->setError(db_error());
return false;
- } else if (db_numrows($res) > 0) { // found another field with the same alias
+ } elseif (db_numrows($res) > 0) { // found another field with the same alias
$conflict = true;
$serial++;
$alias = $alias.$serial;
return false;
}
$i = 1;
+ $data = array();
while ($i <= $max) {
if ($i == $new_pos) {
$data[] = $element_id;
// mode: php
// c-file-style: "bsd"
// End:
-
-?>