Support » Plugin: osTicket Connector » Feature request

  • Resolved mosquitou

    (@mosquitou)


    Hey,
    I have another feature request with corresponding syntax changes:
    Let me showcase the syntax on a few examples:

    1. Take the first field that has a value
    I have the help topics
    Problem
    Problem / Outlook
    Problem / Windows
    Suggestion

    In my form I split them up in two multiple choices / dropdowns for top level and lower level. Lets say the top level (Problems & Suggestion) has the field id of #1 and the other field with the specific problems has the id of #2. With wpforms conditional logic I set the field #2 to only be visible, when I select “Problem” at the field #1.
    In the ticket settings I write: “fields|2/fields|1″
    Now if a user enters “Problem” at #1 he has to also enter a value for #2.
    Your plugin first checks #2, sees that it has a value and takes this as the help topic.
    On the other hand if a user selects “Suggestion” at #1 he cannot enter a value for #2 because of wpforms conditional logic. Your plugin sees that there is no value for field #2 and trys the next field (field #1)

    This feature could be really helpful if you have many help topics

    2. Add all field values
    For the full name setting I have made three fields
    First name* #3
    Middle name #4
    Last name* #5

    In the ticket settings I write: “fields|3&fields|4&fields|5″
    Alternatively + would also be an option.
    I think I don’t have to explain any further, do I…
    Please note that a user could leave out the middle name

    One issue that comes with this is about spaces. When should spaces be added between fields.
    For the names it would make sense so that in the end it does not send JesusChrist to the ticket system. But you would also need to handle empty fields so that there aren’t two spaces because of the middle name.
    Maybe another operator would make sense for that? For example:
    field|3&_field|4&_field|5
    You could make this connected to the field, so it only enters a space if the field value is not empty.

    3. Strings that are always included
    For example:
    “My name is “&fields|5&”, “&fields|3&_fields|5
    This could result in: My name is Bond, James Bond

    Maybe at this poit it would make sense to enclose fields in brackets.

    4. Value fragmentation
    WPForms has the issue that for one option in a field you can only assign one value. Maybe you could add the possibility to only take a fraction of the value so I can store and array of data. Example:
    I have a small company of 80 people who use the ticket system. Thats why I have a dropdown “employee abbreviation” #6 where I would like to map their abbreviation to both email and full name. I don’t want them to be able to choose the email address they want to use nor the name. I suggest that you could use a demiliter to do that. For instance:
    “js” has the value “jesus.christ@web.de:Jesus Christ”
    In the ticket settings at Email you could write “fields|6:1” or :0 to access the first part of the value and at Full Name “fields|6:2” or :1 for the second part.

    What I personally need:
    For me point 4 is really important. Point 1 is not a deal breaker for me to using this plugin but I would really appreciate this. 2 and 3 are probably more complicated for you to implement and I don’t really need them, at least not for now.

    Let me know what you think you think about these changes.

    Best regards,
    Florian

    • This topic was modified 10 months, 4 weeks ago by mosquitou.
Viewing 1 replies (of 1 total)
  • Plugin Author SCAND

    (@scandltd)

    Hi Florian.

    This is a special case and we don’t think we need to implement so complicated logic. There is an option to add filters and then you will be able to change values based on your requirements.

    Just change ‘getRequestValue‘ and ‘getTicketValue‘ functions in ‘class-http-api.php‘ file as specified below.

    getRequestValue on the #254 line:

    private function getRequestValue($field_name) {
    	$value = '';
    	$request = $this->getRequest();
    	if (strpos($field_name, '|') !== false) {
    		$arr_keys = explode('|', $field_name);
    		if (isset($request[$arr_keys[0]][$arr_keys[1]])) {
    			$value = $request[$arr_keys[0]][$arr_keys[1]];
    		}
    	} else if (isset($request[$field_name])) {
    		$value = $request[$field_name];
    	}
    
    	return apply_filters('scand_ostc_request_value', $value, $field_name);
    }

    getTicketValue on the #269 line:

    private function getTicketValue($key) {
    	$field_name = $this->getConfig($key);
    	if (strpos($field_name, ',') === false) {
    		// ticket value is single field
    		$ticket_value = $this->getRequestValue($field_name);
    	} else {
    		// ticket value is a combination of multiple fields
    		$value = '';
    		$values = explode(',', $field_name);
    		foreach ($values as $name) {
    			$name = trim($name);
    			$value .= ' ' . $this->getRequestValue($name);
    		}
    		$ticket_value = trim($value);
    	}
    
    	return apply_filters('scand_ostc_ticket_value', $ticket_value, $key);
    }

    Then call ‘add_filter‘ hooks, for example in your theme’s ‘functions.php‘ file, like this:

    add_filter('scand_ostc_request_value', 'my_request_value', 10, 2);
    add_filter('scand_ostc_ticket_value', 'my_ticket_value', 10, 2);
    
    function my_request_value($value, $field_name) {
    	if ('fields|3' == $field_name) {
    		$first_name = $_REQUEST['wpforms']['fields'][3];
    		$last_name = $_REQUEST['wpforms']['fields'][4];
    		$value = "My name is {$last_name}, {$first_name} {$last_name}";
    	}
    
    	return $value;
    }
    
    function my_ticket_value($ticket_value, $key) {
    	// point #4, value 'jesus.christ@web.de:Jesus Christ' in field#6
    	$employee_abbreviation = explode(":", $_REQUEST['wpforms']['fields'][6]);
    	if ('email' == $key) {
    		$ticket_value = $employee_abbreviation[0];
    	}
    	if ('name' == $key) {
    		$ticket_value = $employee_abbreviation[1];
    	}
    
    	return $ticket_value;
    }

    If it will cover your needs we will add ‘apply_filters‘ into next version.

    Thanks.

    Best regards,
    SCAND team

Viewing 1 replies (of 1 total)
  • The topic ‘Feature request’ is closed to new replies.