示例#1
0
文件: DAO.class.php 项目: rmiddle/feg
 /**
  * 
  * @param object $source_ext_id
  * @param object $source_id
  * @param object $values
  * @return 
  */
 public static function formatAndSetFieldValues($source_ext_id, $source_id, $values, $is_blank_unset = true)
 {
     if (empty($source_ext_id) || empty($source_id) || !is_array($values)) {
         return;
     }
     $fields = DAO_CustomField::getBySource($source_ext_id);
     foreach ($values as $field_id => $value) {
         if (!isset($fields[$field_id])) {
             continue;
         }
         $field =& $fields[$field_id];
         /* @var $field Model_CustomField */
         $delta = $field->type == Model_CustomField::TYPE_MULTI_CHECKBOX || $field->type == Model_CustomField::TYPE_MULTI_PICKLIST ? true : false;
         // if the field is blank
         if (0 == strlen($value)) {
             // ... and blanks should unset
             if ($is_blank_unset && !$delta) {
                 self::unsetFieldValue($source_ext_id, $source_id, $field_id);
             }
             // Skip setting
             continue;
         }
         switch ($field->type) {
             case Model_CustomField::TYPE_SINGLE_LINE:
             case Model_CustomField::TYPE_URL:
                 $value = strlen($value) > 255 ? substr($value, 0, 255) : $value;
                 self::setFieldValue($source_ext_id, $source_id, $field_id, $value);
                 break;
             case Model_CustomField::TYPE_MULTI_LINE:
                 self::setFieldValue($source_ext_id, $source_id, $field_id, $value);
                 break;
             case Model_CustomField::TYPE_DROPDOWN:
             case Model_CustomField::TYPE_MULTI_PICKLIST:
             case Model_CustomField::TYPE_MULTI_CHECKBOX:
                 // If we're setting a field that doesn't exist yet, add it.
                 if (!in_array($value, $field->options) && !empty($value)) {
                     $field->options[] = $value;
                     DAO_CustomField::update($field_id, array(DAO_CustomField::OPTIONS => implode("\n", $field->options)));
                 }
                 // If we're allowed to add/remove fields without touching the rest
                 self::setFieldValue($source_ext_id, $source_id, $field_id, $value, $delta);
                 break;
             case Model_CustomField::TYPE_CHECKBOX:
                 $value = !empty($value) ? 1 : 0;
                 self::setFieldValue($source_ext_id, $source_id, $field_id, $value);
                 break;
             case Model_CustomField::TYPE_DATE:
                 @($value = strtotime($value));
                 self::setFieldValue($source_ext_id, $source_id, $field_id, $value);
                 break;
             case Model_CustomField::TYPE_NUMBER:
                 $value = intval($value);
                 self::setFieldValue($source_ext_id, $source_id, $field_id, $value);
                 break;
             case Model_CustomField::TYPE_WORKER:
                 $value = intval($value);
                 self::setFieldValue($source_ext_id, $source_id, $field_id, $value);
                 break;
         }
     }
 }
示例#2
0
文件: config.php 项目: Hildy/cerb5
 function saveFieldsAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     $worker = CerberusApplication::getActiveWorker();
     if (!$worker || !$worker->is_superuser) {
         echo $translate->_('common.access_denied');
         return;
     }
     if (DEMO_MODE) {
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'fields')));
         return;
     }
     // Type of custom fields
     @($ext_id = DevblocksPlatform::importGPC($_POST['ext_id'], 'string', ''));
     // Properties
     @($ids = DevblocksPlatform::importGPC($_POST['ids'], 'array', array()));
     @($names = DevblocksPlatform::importGPC($_POST['names'], 'array', array()));
     @($orders = DevblocksPlatform::importGPC($_POST['orders'], 'array', array()));
     @($options = DevblocksPlatform::importGPC($_POST['options'], 'array', array()));
     @($deletes = DevblocksPlatform::importGPC($_POST['deletes'], 'array', array()));
     if (!empty($ids) && !empty($ext_id)) {
         foreach ($ids as $idx => $id) {
             @($name = $names[$idx]);
             @($order = intval($orders[$idx]));
             @($option = $options[$idx]);
             @($delete = false !== array_search($id, $deletes) ? 1 : 0);
             if ($delete) {
                 DAO_CustomField::delete($id);
             } else {
                 $fields = array(DAO_CustomField::NAME => $name, DAO_CustomField::POS => $order, DAO_CustomField::OPTIONS => !is_null($option) ? $option : '');
                 DAO_CustomField::update($id, $fields);
             }
         }
     }
     // Adding
     @($add_name = DevblocksPlatform::importGPC($_POST['add_name'], 'string', ''));
     @($add_type = DevblocksPlatform::importGPC($_POST['add_type'], 'string', ''));
     @($add_options = DevblocksPlatform::importGPC($_POST['add_options'], 'string', ''));
     if (!empty($add_name) && !empty($add_type)) {
         $fields = array(DAO_CustomField::NAME => $add_name, DAO_CustomField::TYPE => $add_type, DAO_CustomField::GROUP_ID => 0, DAO_CustomField::SOURCE_EXTENSION => $ext_id, DAO_CustomField::OPTIONS => $add_options);
         $id = DAO_CustomField::create($fields);
     }
     // Redraw the form
     $this->_getFieldSource($ext_id);
 }
示例#3
0
文件: groups.php 项目: Hildy/cerb5
 function saveTabFieldsAction()
 {
     @($group_id = DevblocksPlatform::importGPC($_POST['team_id'], 'integer'));
     @($active_worker = CerberusApplication::getActiveWorker());
     if (!$active_worker->isTeamManager($group_id) && !$active_worker->is_superuser) {
         return;
     }
     @($ids = DevblocksPlatform::importGPC($_POST['ids'], 'array', array()));
     @($names = DevblocksPlatform::importGPC($_POST['names'], 'array', array()));
     @($orders = DevblocksPlatform::importGPC($_POST['orders'], 'array', array()));
     @($options = DevblocksPlatform::importGPC($_POST['options'], 'array', array()));
     @($allow_delete = DevblocksPlatform::importGPC($_POST['allow_delete'], 'integer', 0));
     @($deletes = DevblocksPlatform::importGPC($_POST['deletes'], 'array', array()));
     if (!empty($ids)) {
         foreach ($ids as $idx => $id) {
             @($name = $names[$idx]);
             @($order = intval($orders[$idx]));
             @($option = $options[$idx]);
             @($delete = false !== array_search($id, $deletes) ? 1 : 0);
             if ($allow_delete && $delete) {
                 DAO_CustomField::delete($id);
             } else {
                 $fields = array(DAO_CustomField::NAME => $name, DAO_CustomField::POS => $order, DAO_CustomField::OPTIONS => !is_null($option) ? $option : '');
                 DAO_CustomField::update($id, $fields);
             }
         }
     }
     // Add custom field
     @($add_name = DevblocksPlatform::importGPC($_POST['add_name'], 'string', ''));
     @($add_type = DevblocksPlatform::importGPC($_POST['add_type'], 'string', ''));
     @($add_options = DevblocksPlatform::importGPC($_POST['add_options'], 'string', ''));
     if (!empty($add_name) && !empty($add_type)) {
         $fields = array(DAO_CustomField::NAME => $add_name, DAO_CustomField::TYPE => $add_type, DAO_CustomField::GROUP_ID => $group_id, DAO_CustomField::SOURCE_EXTENSION => ChCustomFieldSource_Ticket::ID, DAO_CustomField::OPTIONS => $add_options);
         $id = DAO_CustomField::create($fields);
     }
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('groups', $group_id, 'fields')));
 }