/**
* The artifact type object.
*
- * @var object $ArtifactType.
+ * @var object $ArtifactType.
*/
var $ArtifactType; //object
/**
* Array of artifact data.
*
- * @var array $data_array.
+ * @var array $data_array.
*/
var $data_array;
/**
* Array of query conditions
*
- * @var array $element_array.
+ * @var array $element_array.
*/
var $element_array;
/**
- * __construct - Constructor
+ * __construct - Constructor
*
- * @param $ArtifactType $ArtifactType c object.
- * @param array|bool $data
+ * @param $ArtifactType $ArtifactType c object.
+ * @param array|bool $data
*/
function __construct(&$ArtifactType, $data = false) {
$this->Error();
/**
* create - create a row in the table that stores a saved query for
- * a tracker.
+ * a tracker.
*
- * @param $name
- * @param $status
- * @param $assignee
- * @param $moddaterange
- * @param $sort_col
- * @param $sort_ord
- * @param $extra_fields
- * @param int $opendaterange
- * @param int $closedaterange
- * @param $summary
- * @param $description
- * @param $followups
- * @param int $query_type
- * @param array $query_options
- * @param string $submitter Name of the saved query.
- * @return bool true on success / false on failure.
+ * @param string $name
+ * @param $status
+ * @param $assignee
+ * @param $moddaterange
+ * @param $sort_col
+ * @param $sort_ord
+ * @param $extra_fields
+ * @param int $opendaterange
+ * @param int $closedaterange
+ * @param string $summary
+ * @param string $description
+ * @param $followups
+ * @param int $query_type
+ * @param array $query_options
+ * @param string $submitter Name of the saved query.
+ * @return bool true on success / false on failure.
*/
function create($name,$status,$assignee,$moddaterange,$sort_col,$sort_ord,$extra_fields,$opendaterange=0,$closedaterange=0,
$summary,$description,$followups,$query_type=0,$query_options=array(),$submitter='') {
}
/**
- * fetchData - re-fetch the data for this ArtifactQuery from the database.
+ * fetchData - re-fetch the data for this ArtifactQuery from the database.
*
- * @param int $id ID of saved query.
- * @return boolean success.
+ * @param int $id ID of saved query.
+ * @return boolean success.
*/
function fetchData($id) {
$res = db_query_params ('SELECT * FROM artifact_query WHERE artifact_query_id=$1',
}
/**
- * getArtifactType - get the ArtifactType Object this ArtifactExtraField is associated with.
+ * getArtifactType - get the ArtifactType Object this ArtifactExtraField is associated with.
*
- * @return object ArtifactType.
+ * @return object ArtifactType.
*/
function &getArtifactType() {
return $this->ArtifactType;
}
/**
+ * insertElements - ???
*
- *
+ * @param int $id
+ * @param $status
+ * @param $submitter
+ * @param $assignee
+ * @param $moddaterange
+ * @param $sort_col
+ * @param $sort_ord
+ * @param $extra_fields
+ * @param $opendaterange
+ * @param $closedaterange
+ * @param string $summary
+ * @param string $description
+ * @param $followups
+ * @return boolean True/false on success or not.
*/
function insertElements($id,$status,$submitter,$assignee,$moddaterange,$sort_col,$sort_ord,$extra_fields,$opendaterange,$closedaterange,$summary,$description,$followups) {
$res = db_query_params ('DELETE FROM artifact_query_fields WHERE artifact_query_id=$1',
}
/**
- * getID - get this ArtifactQuery ID.
+ * getID - get this ArtifactQuery ID.
*
- * @return int The id #.
+ * @return int The id #.
*/
function getID() {
return $this->data_array['artifact_query_id'];
}
/**
- * getName - get the name.
+ * getName - get the name.
*
- * @return string The name.
+ * @return string The name.
*/
function getName() {
return $this->data_array['query_name'];
}
/**
- * getUserId - get the user_id.
+ * getUserId - get the user_id.
*
- * @return string The user_id.
+ * @return string The user_id.
*/
function getUserId() {
return $this->data_array['user_id'];
}
/**
- * getQueryType - get the type of the query
+ * getQueryType - get the type of the query
*
- * @return string type of query (0: private, 1: project, 2: project&default)
+ * @return string type of query (0: private, 1: project, 2: project&default)
*/
function getQueryType() {
return $this->data_array['query_type'];
}
/**
- * getQueryOptions - get the options of the query
+ * getQueryOptions - get the options of the query
*
- * @return array array of all activated options
+ * @return array array of all activated options
*/
function getQueryOptions() {
if (isset($this->data_array['query_options'])) {
}
/**
- * getSortCol - the column that you're sorting on
+ * getSortCol - the column that you're sorting on
*
- * @return string The column name.
+ * @return string The column name.
*/
function getSortCol() {
if (!isset($this->element_array))
}
/**
- * getSortOrd - ASC or DESC
+ * getSortOrd - ASC or DESC
*
- * @return string ASC or DESC
+ * @return string ASC or DESC
*/
function getSortOrd() {
if (!isset($this->element_array))
}
/**
- * getModDateRange - get the range of dates to include in a query
+ * getModDateRange - get the range of dates to include in a query
*
- * @return string mod date range.
+ * @return string mod date range.
*/
function getModDateRange() {
if (!isset($this->element_array))
}
/**
- * getOpenDateRange - get the range of dates to include in a query
+ * getOpenDateRange - get the range of dates to include in a query
*
- * @return string Open date range.
+ * @return string Open date range.
*/
function getOpenDateRange() {
if (!isset($this->element_array))
return false;
- if ($this->element_array[ARTIFACT_QUERY_OPENDATE][0]) {
+ if (isset($this->element_array[ARTIFACT_QUERY_OPENDATE][0])) {
return $this->element_array[ARTIFACT_QUERY_OPENDATE][0];
} else {
return false;
}
/**
- * getCloseDateRange - get the range of dates to include in a query
+ * getCloseDateRange - get the range of dates to include in a query
*
- * @return string Close date range.
+ * @return string Close date range.
*/
function getCloseDateRange() {
if (!isset($this->element_array))
return false;
- if ($this->element_array[ARTIFACT_QUERY_CLOSEDATE][0]) {
+ if (isset($this->element_array[ARTIFACT_QUERY_CLOSEDATE][0])) {
return $this->element_array[ARTIFACT_QUERY_CLOSEDATE][0];
} else {
return false;
}
/**
- * getSummary - get the summary string to include in a query
+ * getSummary - get the summary string to include in a query
*
- * @return string Summary string.
+ * @return string Summary string.
*/
function getSummary() {
if (!isset($this->element_array[ARTIFACT_QUERY_SUMMARY][0])) {
}
/**
- * getDescription - get the description string to include in a query
+ * getDescription - get the description string to include in a query
*
- * @return string Description string.
+ * @return string Description string.
*/
function getDescription() {
if (!isset($this->element_array[ARTIFACT_QUERY_DESCRIPTION][0])) {
}
/**
- * getFollowups - get the followups string to include in a query
+ * getFollowups - get the followups string to include in a query
*
- * @return string Folowups string.
+ * @return string Folowups string.
*/
function getFollowups() {
if (!isset($this->element_array[ARTIFACT_QUERY_FOLLOWUPS][0])) {
}
/**
- * getAssignee
+ * getAssignee
*
- * @return string Assignee ID
+ * @return string Assignee ID
*/
function getAssignee() {
if (!isset($this->element_array[ARTIFACT_QUERY_ASSIGNEE]))
}
/**
- * getSubmitter
+ * getSubmitter
*
- * @return string Submitter ID
+ * @return string Submitter ID
*/
function getSubmitter() {
if (!isset($this->element_array[ARTIFACT_QUERY_SUBMITTER]))
}
/**
- * getStatus
+ * getStatus
*
- * @return string Status ID
+ * @return string Status ID
*/
function getStatus() {
if (!isset($this->element_array))
}
/**
- * getExtraFields - complex multi-dimensional array of extra field IDs/Vals
+ * getExtraFields - complex multi-dimensional array of extra field IDs/Vals
*
- * @return array Complex Array
+ * @return array Complex Array
*/
function getExtraFields() {
if (!isset($this->element_array))
/**
* validateDateRange - validate a date range in this format '1999-05-01 1999-06-01'.
*
- * @param string $daterange A range of two dates (1999-05-01 1999-06-01)
- * @return bool true/false.
+ * @param string $daterange A range of two dates (1999-05-01 1999-06-01)
+ * @return bool true/false.
*/
- function validateDateRange($daterange) {
- return preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{4}-[0-9]{2}-[0-9]{2}/',$daterange);
+ function validateDateRange(&$daterange) {
+ if(! preg_match('/([0-9]{4})-[0-9]{2}-[0-9]{2} ([0-9]{4})-[0-9]{2}-[0-9]{2}/', $daterange, $matches)) {
+ return false;
+ }
+ else {
+ # Hack to avoid exceeding the maximum value for an integer in the database
+ if ($matches[1] > 2037) {
+ $daterange = preg_replace('/[\d]{4}(-[\d]{2}-[\d]{2} [\d]{4}-[\d]{2}-[\d]{2})/', '2037$1', $daterange);
+ }
+ if ($matches[2] > 2037) {
+ $daterange = preg_replace('/([\d]{4}-[\d]{2}-[\d]{2} )[\d]{4}(-[\d]{2}-[\d]{2})/', '${1}2037$2', $daterange);
+ }
+ }
+ return true;
}
/**
- * update - update a row in the table used to query names
- * for a tracker.
+ * update - update a row in the table used to query names
+ * for a tracker.
*
- * @param $name
- * @param $status
- * @param $assignee
- * @param $moddaterange
- * @param $sort_col
- * @param $sort_ord
- * @param $extra_fields
- * @param string $opendaterange
- * @param string $closedaterange
- * @param $summary
- * @param $description
- * @param $followups
- * @param int $query_type Id of the saved query
- * @param array $query_options
- * @param string $submitter
- * @return bool success.
+ * @param $name
+ * @param $status
+ * @param $assignee
+ * @param $moddaterange
+ * @param $sort_col
+ * @param $sort_ord
+ * @param $extra_fields
+ * @param string $opendaterange
+ * @param string $closedaterange
+ * @param $summary
+ * @param $description
+ * @param $followups
+ * @param int $query_type Id of the saved query
+ * @param array $query_options
+ * @param string $submitter
+ * @return bool success.
*/
function update($name,$status,$assignee,$moddaterange,$sort_col,$sort_ord,$extra_fields,$opendaterange='',$closedaterange='',
$summary,$description,$followups,$query_type=0,$query_options=array(),$submitter='') {
$this->setError(_('Must Be Logged In'));
return false;
}
- if (!$this->Exist(htmlspecialchars($name))) {
- $this->setError(_('Query does not exist'));
- return false;
- }
if ($query_type>0 && !forge_check_perm ('tracker', $this->ArtifactType->getID(), 'manager')) {
$this->setError(_('You must have tracker admin rights to set or update a project level query.'));
return false;
}
/**
- * makeDefault - set this as the default query
+ * makeDefault - set this as the default query
*
- * @return boolean success.
+ * @return boolean success.
*/
function makeDefault() {
if (!session_loggedin()) {
}
/**
- * delete - delete query
+ * delete - delete query
*
- * @return boolean success.
+ * @return boolean success.
*/
function delete() {
if (forge_check_perm ('tracker', $this->ArtifactType->getID(), 'manager')) {
$res = db_query_params ('DELETE FROM artifact_query WHERE artifact_query_id=$1 AND (user_id=$2 OR query_type>0)',
array ($this->getID(),
user_getid())) ;
- if (!$res) {
- return false;
- }
+ if (!$res) {
+ return false;
+ }
} else {
$res = db_query_params ('DELETE FROM artifact_query WHERE artifact_query_id=$1 AND user_id=$2',
array ($this->getID(),
user_getid())) ;
- if (!$res) {
- return false;
- }
+ if (!$res) {
+ return false;
+ }
}
db_query_params ('DELETE FROM user_preferences WHERE preference_value=$1 AND preference_name =$2',
array ($this->getID(),
'art_query'.$this->ArtifactType->getID())) ;
unset($this->data_array);
unset($this->element_array);
- return true;
+ return true;
}
/**
* Exist - check if already exist a query with the same name , user_id and artifact_id
*
- * @param string $name Name of query
- * @return bool true if query already exists
+ * @param string $name Name of query
+ * @return bool true if query already exists
*/
function Exist($name) {
$user_id = user_getid();