- if (is_null($value) || !is_array($value)) {
- $value = array();
- $res = XDB::iterator("SELECT t.display_tel AS tel, t.tel_type AS type, t.pub, t.comment
- FROM profile_phones AS t
- WHERE t.uid = {?} AND t.link_type = {?}
- ORDER BY t.tel_id",
- $this->id, $this->link_type);
- $value = $res->fetchAllAssoc();
- }
- foreach ($value as $key=>&$phone) {
- if (@$phone['removed']) {
- unset($value[$key]);
- } else {
- unset($phone['removed']);
- $phone['pub'] = $this->pub->value($page, 'pub', $phone['pub'], $s);
- $phone['tel'] = $this->tel->value($page, 'tel', $phone['tel'], $s);
- if(!isset($phone['type']) || ($phone['type'] != 'fixed' && $phone['type'] != 'mobile' && $phone['type'] != 'fax')) {
- $phone['type'] = 'fixed';
- $s = false;
- }
- if (!$s) {
- $phone['error'] = true;
- $success = false;
- }
- if (!isset($phone['comment'])) {
- $phone['comment'] = '';
- }
+ $phones = array();
+
+ if (is_null($value)) {
+ $it = Phone::iterate(array($page->pid()), array(Phone::LINK_PROFILE), array(0));
+ while ($phone = $it->next()) {
+ $success = ($phone->format() && $success);
+ $phones[] = $phone->toFormArray();
+ }
+ if (count($phones) == 0) {
+ $phone = new Phone();
+ $phones[] = $phone->toFormArray();