Announcement

Collapse
No announcement yet.

Is there a formula function to get the string representation of a multi-enum field?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a formula function to get the string representation of a multi-enum field?

    I am writing a formula involving a multi-enum field. Is there a way to turn it into a string for further processing ?
    Last edited by tothewine; 01-26-2019, 02:54 PM.

  • #2
    OK I found none so I wrote one, please tell me if this code is the best way to do it.
    Code:
    <?php
    
    namespace Espo\Custom\Core\Formula\Functions\CustomGroup;
    use \Espo\Core\Exceptions\Error;
    
    class ArrayJoinType extends \Espo\Core\Formula\Functions\Base
    {
        public function process(\StdClass $item) {
    
            if (!property_exists($item, 'value') || !is_array($item->value)) {
                throw new Error('Bad \'Custom\\ArrayJoin\' process parameter.');
            }
    
            if (count($item->value) <= 0) {
                throw new Error('Bad \'Custom\\ArrayJoin\' argument count.');
            }
    
            $list = $this->evaluate($item->value[0]);
            if (!is_array($list)) {
                throw new Error('Bad \'Custom\\ArrayJoin\' argument #1 is not array.');
            }
    
            $glue = '; ';
            if (count($item->value) > 1) {
                try {
                    $tmp1 = $this->evaluate($item->value[1]);
                    if (is_string($tmp1)) $glue = $tmp1;
                } catch (\Exception $e) {
                    $glue = '; ';
                }
            }
    
            $ret = implode($glue, $list);
    
            return $ret;
        }
    }

    Comment

    Working...
    X