コード例 #1
0
 /**
  *	Delete a FieldSet
  *
  *  @param int $field_set_id the field set id to delete
  *	@return	boolean true if the deletion happen without problems, false otherwise
  */
 function deleteFieldSet($field_set_id)
 {
     global $Language;
     // Check if the field set contains no field
     $sql = "SELECT field_id, label \n                FROM artifact_field \n                WHERE group_artifact_id='" . db_ei($this->ArtifactType->getID()) . "' AND\n                      field_set_id='" . db_ei($field_set_id) . "'";
     $result = db_query($sql);
     $num_rows = db_numrows($result);
     if ($num_rows != 0) {
         $this->setError($Language->getText('tracker_common_fieldset_factory', 'delete_only_empty_fieldset') . ' ' . db_error());
         return false;
     } else {
         // Delete the FieldSet
         $sql = "DELETE FROM artifact_field_set \n                    WHERE field_set_id=" . db_ei($field_set_id);
         $result = db_query($sql);
         if (!$result || db_affected_rows($result) <= 0) {
             $this->setError('Error: deleteArtifactFieldSet ' . db_error());
             return false;
         }
     }
     return true;
 }
コード例 #2
0
ファイル: tracker.php プロジェクト: nterray/tuleap
 /**
  * artifacttype_to_soap : return the soap ArtifactType structure giving an PHP ArtifactType Object.
  * @access private
  * 
  * WARNING : We check the permissions here : only the readable trackers and the readable fields are returned.
  *
  * @param Object{ArtifactType} $at the artifactType to convert.
  * @return the SOAPArtifactType corresponding to the ArtifactType Object
  */
 function artifacttype_to_soap($at)
 {
     global $ath;
     $user_id = UserManager::instance()->getCurrentUser()->getId();
     $return = array();
     // number of opend artifact are not part of ArtifactType, so we have to get it with ArtifactTypeFactory (could need some refactoring maybe)
     $atf = new ArtifactTypeFactory($at->getGroup());
     $arr_count = $atf->getStatusIdCount($at->getID());
     if ($arr_count) {
         $open_count = array_key_exists('open_count', $arr_count) ? $arr_count['open_count'] : -1;
         $count = array_key_exists('count', $arr_count) ? $arr_count['count'] : -1;
     } else {
         $open_count = -1;
         $count = -1;
     }
     $field_sets = array();
     $ath = new ArtifactType($at->getGroup(), $at->getID());
     if (!$ath || !is_object($ath)) {
         return new SoapFault(get_artifact_type_fault, 'ArtifactType could not be created', 'getArtifactTypes');
     }
     if ($ath->isError()) {
         return new SoapFault(get_artifact_type_fault, $ath->getErrorMessage(), 'getArtifactTypes');
     }
     // Check if this tracker is valid (not deleted)
     if (!$ath->isValid()) {
         return new SoapFault(get_artifact_type_fault, 'This tracker is no longer valid.', 'getArtifactTypes');
     }
     // Check if the user can view this tracker
     if ($ath->userCanView($user_id)) {
         $art_fieldset_fact = new ArtifactFieldSetFactory($at);
         if (!$art_fieldset_fact || !is_object($art_fieldset_fact)) {
             return new SoapFault(get_artifact_field_factory_fault, 'Could Not Get ArtifactFieldSetFactory', 'getFieldSets');
         } elseif ($art_fieldset_fact->isError()) {
             return new SoapFault(get_artifact_field_factory_fault, $art_fieldset_fact->getErrorMessage(), 'getFieldSets');
         }
         $result_fieldsets = $art_fieldset_fact->getAllFieldSetsContainingUsedFields();
         foreach ($result_fieldsets as $fieldset_id => $result_fieldset) {
             $fields = array();
             $fields_in_fieldset = $result_fieldset->getAllUsedFields();
             $group_id = $at->Group->getID();
             $group_artifact_id = $at->getID();
             while (list($key, $field) = each($fields_in_fieldset)) {
                 if ($field->userCanRead($group_id, $group_artifact_id, $user_id)) {
                     $availablevalues = array();
                     $result = $field->getFieldPredefinedValues($at->getID(), false, false, false, false);
                     $rows = db_numrows($result);
                     $cols = db_numfields($result);
                     for ($j = 0; $j < $rows; $j++) {
                         $field_status = $cols > 2 ? db_result($result, $j, 6) : '';
                         // we don't send hidden values (status == 'H')
                         if ($field_status != 'H') {
                             $availablevalues[] = array('field_id' => $field->getID(), 'group_artifact_id' => $at->getID(), 'value_id' => db_result($result, $j, 0), 'value' => SimpleSanitizer::unsanitize(db_result($result, $j, 1)), 'description' => SimpleSanitizer::unsanitize($cols > 2 ? db_result($result, $j, 4) : ''), 'order_id' => $cols > 2 ? db_result($result, $j, 5) : 0, 'status' => $field_status);
                         }
                     }
                     // For bound-values select boxes, we add the none value.
                     if (($field->isMultiSelectBox() || $field->isSelectBox()) && $field->isBound()) {
                         $availablevalues[] = array('field_id' => $field->getID(), 'group_artifact_id' => $at->getID(), 'value_id' => 100, 'value' => 'None', 'description' => '', 'order_id' => 10, 'status' => 'P');
                     }
                     if ($field->isMultiSelectBox()) {
                         $defaultvalue = implode(",", $field->getDefaultValue());
                     } else {
                         $defaultvalue = $field->getDefaultValue();
                     }
                     $fields[] = array('field_id' => $field->getID(), 'group_artifact_id' => $at->getID(), 'field_set_id' => $field->getFieldSetID(), 'field_name' => SimpleSanitizer::unsanitize($field->getName()), 'data_type' => $field->getDataType(), 'display_type' => $field->getDisplayType(), 'display_size' => $field->getDisplaySize(), 'label' => SimpleSanitizer::unsanitize($field->getLabel()), 'description' => SimpleSanitizer::unsanitize($field->getDescription()), 'scope' => $field->getScope(), 'required' => $field->getRequired(), 'empty_ok' => $field->getEmptyOk(), 'keep_history' => $field->getKeepHistory(), 'special' => $field->getSpecial(), 'value_function' => implode(",", $field->getValueFunction()), 'available_values' => $availablevalues, 'default_value' => $defaultvalue, 'user_can_submit' => $field->userCanSubmit($group_id, $group_artifact_id, $user_id), 'user_can_read' => $field->userCanRead($group_id, $group_artifact_id, $user_id), 'user_can_update' => $field->userCanUpdate($group_id, $group_artifact_id, $user_id), 'is_standard_field' => $field->isStandardField());
                 }
             }
             $field_sets[] = array('field_set_id' => $result_fieldset->getID(), 'group_artifact_id' => $result_fieldset->getArtifactTypeID(), 'name' => SimpleSanitizer::unsanitize($result_fieldset->getName()), 'label' => SimpleSanitizer::unsanitize($result_fieldset->getLabel()), 'description' => SimpleSanitizer::unsanitize($result_fieldset->getDescription()), 'description_text' => SimpleSanitizer::unsanitize($result_fieldset->getDescriptionText()), 'rank' => $result_fieldset->getRank(), 'fields' => $fields);
         }
         // We add the field dependencies
         $field_dependencies = artifactrules_to_soap($at);
         $sql = "SELECT COALESCE(sum(af.filesize) / 1024,NULL,0) as total_file_size" . " FROM artifact_file af, artifact a, artifact_group_list agl" . " WHERE (af.artifact_id = a.artifact_id)" . " AND (a.group_artifact_id = agl.group_artifact_id)" . " AND (agl.group_artifact_id =" . db_ei($at->getID()) . ")";
         $result = db_query($sql);
         $return = array('group_artifact_id' => $at->data_array['group_artifact_id'], 'group_id' => $at->data_array['group_id'], 'name' => SimpleSanitizer::unsanitize($at->data_array['name']), 'description' => SimpleSanitizer::unsanitize($at->data_array['description']), 'item_name' => $at->data_array['item_name'], 'open_count' => $at->userHasFullAccess() ? $open_count : -1, 'total_count' => $at->userHasFullAccess() ? $count : -1, 'total_file_size' => db_result($result, 0, 0), 'field_sets' => $field_sets, 'field_dependencies' => $field_dependencies);
     }
     return $return;
 }