]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Make phone number save and display from DB
authorZach Copley <zach@status.net>
Fri, 11 Mar 2011 00:57:41 +0000 (16:57 -0800)
committerZach Copley <zach@status.net>
Fri, 11 Mar 2011 00:57:41 +0000 (16:57 -0800)
plugins/ExtendedProfile/extendedprofile.php
plugins/ExtendedProfile/extendedprofilewidget.php

index 908f0bc72146f00c080fd21d9dd27d07106e651d..2a10759d91718880f471c14fb1a0808389da1511 100644 (file)
@@ -37,8 +37,10 @@ class ExtendedProfile
     {
         $this->profile  = $profile;
         $this->user     = $profile->getUser();
-        $this->sections = $this->getSections();
         $this->fields   = $this->loadFields();
+        $this->sections = $this->getSections();
+        //common_debug(var_export($this->sections, true));
+
         //common_debug(var_export($this->fields, true));
     }
 
@@ -96,19 +98,36 @@ class ExtendedProfile
         }
     }
 
-
     function getPhones()
     {
-        return array(
+        $phones  = $this->fields['phone'];
+        $pArrays = array();
+
+        if (empty($phones)) {
+            $pArrays[] = array(
                 'label' => _m('Phone'),
                 'type'  => 'phone',
-                'multi' => true,
-                'index' => 8123,
-                'rel'   => 'home',
-                'value' => '510-528-0079',
-                'vcard' => 'tel'
-
-        );
+                'vcard' => 'tel',
+                'multi' => true
+            );
+        } else {
+            for ($i = 0; $i < sizeof($phones); $i++) {
+                $pa = array(
+                    'label' => _m('Phone'),
+                    'type'  => 'phone',
+                    'index' => $phones[$i]->value_index,
+                    'rel'   => $phones[$i]->rel,
+                    'value' => $phones[$i]->field_value,
+                    'vcard' => 'tel'
+                );
+                // Last phone record should allow adding more
+                if ($i == sizeof($phones) - 1) {
+                    $pa['multi'] = true;
+                }
+               $pArrays[] = $pa;
+            }
+        }
+        return $pArrays;
     }
 
     /**
index f5685e9981a234204e90203f53e9e2173e682c35..d31a34b1e2a41704aa56d68e5155b4050bdcf840 100644 (file)
@@ -101,8 +101,13 @@ class ExtendedProfileWidget extends Form
     {
         $this->out->element('h3', null, $section['label']);
         $this->out->elementStart('table', array('class' => 'extended-profile'));
+
         foreach ($section['fields'] as $fieldName => $field) {
-            $this->showExtendedProfileField($fieldName, $field);
+            if ($fieldName == 'phone') {
+                $this->showPhones($fieldName, $field);
+            } else {
+                $this->showExtendedProfileField($fieldName, $field);
+            }
         }
         $this->out->elementEnd('table');
     }
@@ -151,7 +156,6 @@ class ExtendedProfileWidget extends Form
             $this->out->text($this->ext->getTags());
             break;
         case 'phone':
-            common_debug("GOT a PHONE!");
             $this->showPhone($field);
             break;
         default:
@@ -159,11 +163,19 @@ class ExtendedProfileWidget extends Form
         }
     }
 
+    protected function showPhones($name, $field) {
+        foreach ($field as $phone) {
+            $this->showExtendedProfileField($name, $phone);
+        }
+    }
+
     protected function showPhone($field)
     {
         $this->out->elementStart('div', array('class' => 'phone-display'));
         $this->out->text($field['value']);
-        $this->out->text(' (' . $field['rel'] . ')');
+        if (!empty($field['rel'])) {
+            $this->out->text(' (' . $field['rel'] . ')');
+        }
         $this->out->elementEnd('div');
     }