Post

6 followers Follow
0
Avatar

update new email and phone fields with php api

How do I update the new email and phone fields through the podio PHP API?

I have been attempting top use both the:
PodioItemField::update
and the
$item = PodioItem::get_basic( ### );
$item->fields[###] -> values ... ;
$item->save();

options and keep getting errors and warnings without any update success.

Alex White Answered

Please sign in to leave a comment.

6 comments

0
Avatar

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

Alex White 0 votes
1
Avatar

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!

onica andreea 1 vote