]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Extended profile - show and edit experience
authorZach Copley <zach@status.net>
Mon, 14 Mar 2011 22:29:11 +0000 (15:29 -0700)
committerZach Copley <zach@status.net>
Mon, 14 Mar 2011 22:29:11 +0000 (15:29 -0700)
plugins/ExtendedProfile/extendedprofile.php
plugins/ExtendedProfile/extendedprofilewidget.php
plugins/ExtendedProfile/js/profiledetail.js
plugins/ExtendedProfile/profiledetailsettingsaction.php

index 711fdcf1bb59a1aaba8669804b95b863f4cdd9d0..2277e4d7697244a7f8db13307c8e7f69f993a45c 100644 (file)
@@ -129,6 +129,29 @@ class ExtendedProfile
         return $pArrays;
     }
 
+    function getExperiences()
+    {
+        $companies = (isset($this->fields['companies'])) ? $this->fields['company'] : null;
+        $start = (isset($this->fields['start'])) ? $this->fields['start'] : null;
+        $end   = (isset($this->fields['end'])) ? $this->fields['end'] : null;
+
+        $cArrays = array();
+
+        if (empty($experiences)) {
+            $eArrays[] = array(
+                'label'   => _m('Employer'),
+                'type'    => 'experience',
+                'company' => "Bozotronix",
+                'start'   => '1/5/10',
+                'end'     => '2/3/11',
+                'current' => true,
+                'index'   => 0
+            );
+        }
+
+        return $eArrays;
+    }
+
     /**
      *  Return all the sections of the extended profile
      *
@@ -206,10 +229,7 @@ class ExtendedProfile
             'experience' => array(
                 'label' => _m('Work experience'),
                 'fields' => array(
-                    'experience' => array(
-                        'type' => 'experience',
-                        'label' => _m('Employer'),
-                    ),
+                    'experience' => $this->getExperiences(),
                 ),
             ),
             'education' => array(
index d8c42df6a3d39ba3ee0806e2fc18ca59defda59a..9dfbaa716e23a39d6efa6eae29a44e987ff3173a 100644 (file)
@@ -103,9 +103,13 @@ class ExtendedProfileWidget extends Form
         $this->out->elementStart('table', array('class' => 'extended-profile'));
 
         foreach ($section['fields'] as $fieldName => $field) {
-            if ($fieldName == 'phone') {
-                $this->showPhones($fieldName, $field);
-            } else {
+
+            switch($fieldName) {
+            case 'phone':
+            case 'experience':
+                $this->showMultiple($fieldName, $field);
+                break;
+            default:
                 $this->showExtendedProfileField($fieldName, $field);
             }
         }
@@ -135,37 +139,9 @@ class ExtendedProfileWidget extends Form
         $this->out->elementEnd('tr');
     }
 
-    /**
-     * Outputs the value of a field
-     *
-     * @param string $name  name of the field
-     * @param array  $field set of key/value pairs for the field
-     */
-    protected function showFieldValue($name, $field)
-    {
-        $type = strval(@$field['type']);
-
-        switch($type)
-        {
-        case '':
-        case 'text':
-        case 'textarea':
-            $this->out->text($this->ext->getTextValue($name));
-            break;
-        case 'tags':
-            $this->out->text($this->ext->getTags());
-            break;
-        case 'phone':
-            $this->showPhone($name, $field);
-            break;
-        default:
-            $this->out->text("TYPE: $type");
-        }
-    }
-
-    protected function showPhones($name, $field) {
-        foreach ($field as $phone) {
-            $this->showExtendedProfileField($name, $phone);
+    protected function showMultiple($name, $fields) {
+        foreach ($fields as $field) {
+            $this->showExtendedProfileField($name, $field);
         }
     }
 
@@ -210,6 +186,74 @@ class ExtendedProfileWidget extends Form
             isset($field['rel']) ? $field['rel'] : null
         );
 
+        $this->showMultiControls();
+        $this->out->elementEnd('div');
+    }
+
+    protected function showExperience($name, $field)
+    {
+        $this->out->elementStart('div', array('class' => 'experience-display'));
+        $this->out->text($field['company']);
+        $this->out->elementStart('dl', 'experience-start-and-end');
+        $this->out->element('dt', null, _m('Start'));
+        $this->out->element('dd', null, $field['start']);
+        $this->out->element('dt', null, _m('End'));
+        if ($field['current']) {
+            $this->out->element('dd', null, '(' . _m('Current') . ')');
+        } else {
+            $this->out->element('dd', null, $field['end']);
+        }
+        $this->out->elementEnd('dl');
+        $this->out->elementEnd('div');
+    }
+
+    protected function showEditableExperience($name, $field)
+    {
+        $index = isset($field['index']) ? $field['index'] : 0;
+        $id    = "extprofile-$name-$index";
+        $this->out->elementStart(
+            'div', array(
+                'id' => $id . '-edit',
+                'class' => 'experience-edit'
+            )
+        );
+
+        $this->out->input(
+            $id,
+            null,
+            isset($field['company']) ? $field['company'] : null
+        );
+
+        $this->out->elementStart('ul', 'experience-start-and-end');
+        $this->out->elementStart('li');
+        $this->out->input(
+            $id . '-start',
+            _m('Start'),
+            isset($field['start']) ? $field['start'] : null
+        );
+        $this->out->elementEnd('li');
+
+        $this->out->elementStart('li');
+        $this->out->input(
+            $id . '-end',
+            _m('End'),
+            isset($field['end']) ? $field['end'] : null
+        );
+        $this->out->elementEnd('li');
+        $this->out->elementStart('li');
+        $this->out->checkbox(
+            $id . '-current',
+            _m('Current'),
+            $field['current']
+        );
+        $this->out->elementEnd('li');
+        $this->out->elementEnd('ul');
+        $this->showMultiControls();
+        $this->out->elementEnd('div');
+    }
+
+    function showMultiControls()
+    {
         $this->out->element(
             'a',
             array(
@@ -229,8 +273,37 @@ class ExtendedProfileWidget extends Form
             ),
             '-'
         );
+    }
 
-        $this->out->elementEnd('div');
+    /**
+     * Outputs the value of a field
+     *
+     * @param string $name  name of the field
+     * @param array  $field set of key/value pairs for the field
+     */
+    protected function showFieldValue($name, $field)
+    {
+        $type = strval(@$field['type']);
+
+        switch($type)
+        {
+        case '':
+        case 'text':
+        case 'textarea':
+            $this->out->text($this->ext->getTextValue($name));
+            break;
+        case 'tags':
+            $this->out->text($this->ext->getTags());
+            break;
+        case 'phone':
+            $this->showPhone($name, $field);
+            break;
+        case 'experience':
+            $this->showExperience($name, $field);
+            break;
+        default:
+            $this->out->text("TYPE: $type");
+        }
     }
 
     /**
@@ -262,6 +335,9 @@ class ExtendedProfileWidget extends Form
         case 'phone':
             $this->showEditablePhone($name, $field);
             break;
+        case 'experience':
+            $this->showEditableExperience($name, $field);
+            break;
         default:
             $out->input($id, null, "TYPE: $type");
         }
index 7d7eceddc107ebe4db27eea85d6c5498618046a3..4dc2faf2aa5dc44d172059123cf49b378e7fa220 100644 (file)
@@ -82,6 +82,7 @@ var removeRow = function() {
 
 var init = function() {
     reorder('phone-edit');
+    reorder('experience-edit');
 }
 
 $(document).ready(
index 89b8d61cf9af267be88822a84c6ae09c7fec23f0..5e505f6c28588d59fdaedd137675251df99b295c 100644 (file)
@@ -113,6 +113,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
         }
 
         $this->savePhoneNumbers($user);
+        $this->saveExperiences($user);
 
         $this->showForm(_('Details saved.'), true);
 
@@ -141,17 +142,12 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
         $phoneParams = $this->findMultiParams('phone');
         ksort($phoneParams); // this sorts them into pairs
         $phones = $this->arraySplit($phoneParams, sizeof($phoneParams) / 2);
-
         $phoneTuples = array();
 
-        foreach($phones as $phone) {
-            $firstkey           = current(array_keys($phone));
-            $index              = substr($firstkey, strrpos($firstkey, '-') + 1);
+        foreach ($phones as $phone) {
             list($number, $rel) = array_values($phone);
-
             $phoneTuples[] = array(
                 'value' => $number,
-                'index' => $index,
                 'rel'   => $rel
             );
         }
@@ -159,6 +155,86 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
         return $phoneTuples;
     }
 
+    function findExperiences() {
+
+        // Form vals look like this:
+        // 'extprofile-experience-0'         => 'Bozotronix',
+        // 'extprofile-experience-0-current' => 'true'
+        // 'extprofile-experience-0-start'   => '1/5/10',
+        // 'extprofile-experience-0-end'     => '2/3/11',
+
+        $experiences = array();
+        $expParams = $this->findMultiParams('experience');
+        ksort($expParams);
+        $experiences = $this->arraySplit($expParams, sizeof($expParams) / 4);
+        $expArray = array();
+
+        foreach ($experiences as $exp) {
+            list($company, $current, $start, $end) = array_values($exp);
+            $expArray[] = array(
+                'company' => $company,
+                'start'   => $start,
+                'end'     => $end,
+                'current' => $current,
+            );
+        }
+
+        return $expArray;
+    }
+
+    function saveExperiences($user) {
+        common_debug('save experiences');
+        $experiences = $this->findExperiences();
+
+        $this->removeAll($user, 'company');
+        $this->removeAll($user, 'start');
+        $this->removeAll($user, 'end'); // also stores 'current'
+
+        $i = 0;
+        foreach($experiences as $experience) {
+            if (!empty($experience['company'])) {
+                ++$i;
+                $this->saveField(
+                    $user,
+                    'company',
+                    $experience['company'],
+                    null,
+                    $i
+                );
+           /*
+                $this->saveField(
+                    $user,
+                    'start',
+                    null,
+                    null,
+                    $i,
+                    $experience['start']
+                );
+
+                // Save "current" employer indicator in rel
+                if ($experience['current']) {
+                    $this->saveField(
+                        $user,
+                        'end',
+                        null,
+                        'current', // rel
+                        $i
+                    );
+                } else {
+                    $this->saveField(
+                        $user,
+                        'end',
+                        null,
+                        null,
+                        $i,
+                        $experience['end']
+                    );
+                }
+                */
+            }
+        }
+    }
+
     function arraySplit($array, $pieces)
     {
         if ($pieces < 2) {
@@ -191,8 +267,9 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
      * @param string $value   field value
      * @param string $rel     field rel (type)
      * @param int    $index   index (fields can have multiple values)
+     * @param date   $date    related date
      */
-    function saveField($user, $name, $value, $rel = null, $index = null)
+    function saveField($user, $name, $value, $rel = null, $index = null, $date = null)
     {
         $profile = $user->getProfile();
         $detail  = new Profile_detail();
@@ -207,6 +284,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
             $detial->value_index = $index;
             $detail->rel         = $rel;
             $detail->field_value = $value;
+            $detail->date        = $date;
             $detail->created     = common_sql_now();
             $result = $detail->insert();
             if (empty($result)) {
@@ -218,6 +296,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
 
             $detail->field_value = $value;
             $detail->rel         = $rel;
+            $detail->date        = $date;
 
             $result = $detail->update($orig);
             if (empty($result)) {