update new email and phone fields with php api

Answered

Comments

6 comments

  • Alex White

    to resolve the issues I had to update the PodioItemField.php in the following places:

    added case statements to the
    public function set_type_from_class_name()
    case 'PodioPhoneItemField':
    $this->type = 'work';
    break;
    case 'PodioEmailItemField':
    $this->type = 'work';
    `break;

    and then add the two additional classes to the file

    /**
    * phone field
    */
    class PodioPhoneItemField extends PodioItemField {

    /**
     * Override __set to use field specific method for setting values property
     */
    public function __set($name, $value) {
        if ($name == 'values' && $value !== null) {
            return $this->set_value($value);
        }
        elseif ($name == 'value') {
            if ($value === null) {
                return parent::__set('values', null);
            }
            $type = !empty($this->values['type']) ? $this->values['type'] : '';
            return $this->set_value(array('type' => $type, 'value' => $value));
        }
        elseif ($name == 'type') {
            if ($value === null) {
                return parent::__set('values', null);
            }
            $phone = !empty($this->values['value']) ? $this->values['value'] : '0';
            return $this->set_value(array('type' => $value, 'value' => $phone));
        }
        return parent::__set($name, $value);
    }
    
    /**
     * Override __get to provide values as an integer
     */
    public function __get($name) {
        $attribute = parent::__get($name);
        if ($name == 'values' && $attribute) {
            return $attribute[0];
        }
        elseif ($name == 'value') {
            return $this->values ? $this->values['value'] : null;
        }
        elseif ($name == 'type') {
            return $this->values ? $this->values['type'] : null;
        }
        return $attribute;
    }
    
    public function set_value($values) {
        parent::__set('values', $values ? array($values) : array());
    }
    
    public function api_friendly_values() {
        return $this->values ? $this->values : null;
    }
    

    }

    /**
    * email field
    */
    class PodioEmailItemField extends PodioItemField {

    /**
     * Override __set to use field specific method for setting values property
     */
    public function __set($name, $value) {
        if ($name == 'values' && $value !== null) {
            return $this->set_value($value);
        }
        elseif ($name == 'value') {
            if ($value === null) {
                return parent::__set('values', null);
            }
            $type = !empty($this->values['type']) ? $this->values['type'] : '';
            return $this->set_value(array('type' => $type, 'value' => $value));
        }
        elseif ($name == 'type') {
            if ($value === null) {
                return parent::__set('values', null);
            }
            $email = !empty($this->values['value']) ? $this->values['value'] : '0';
            return $this->set_value(array('type' => $value, 'value' => $email));
        }
        return parent::__set($name, $value);
    }
    
    /**
     * Override __get to provide values as an integer
     */
    public function __get($name) {
        $attribute = parent::__get($name);
        if ($name == 'values' && $attribute) {
            return $attribute[0];
        }
        elseif ($name == 'value') {
            return $this->values ? $this->values['value'] : null;
        }
        elseif ($name == 'type') {
            return $this->values ? $this->values['type'] : null;
        }
        return $attribute;
    }
    
    public function set_value($values) {
        parent::__set('values', $values ? array($values) : array());
    }
    
    public function api_friendly_values() {
        return $this->values ? $this->values : null;
    }
    

    }

    hopefully this will help others

    0
    Comment actions Permalink
  • AVA
    1
    Comment actions Permalink
  • Tim Stiffler-Dean

    Any chance a Podio team member could update the PHP Client Documentation to show these two field examples?

    http://podio.github.io/podio-php/fields/

    1
    Comment actions Permalink
  • onica andreea

    Hello, I have the same issue, please give an example of how you gave values to $item->fields[###] -> values

     

    is it like this : $item->fields['email'] -> values= array("type"=>"work","value"=>"a@a.com"); Thank you!

    1
    Comment actions Permalink
  • David Thomson

    Has there ever been an update on this? how come the API documentation can't be updated?

    1
    Comment actions Permalink
  • Stefan Falkboman

    +1 to add this to PHP Library. Podio?

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk