Notifies profile's owner when profile modified by a third party (Closes #1038).
[platal.git] / modules / profile / decos.inc.php
index 36a27d4..a6cfabc 100644 (file)
@@ -19,7 +19,7 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-class ProfileDeco implements ProfileSetting
+class ProfileSettingDeco implements ProfileSetting
 {
     public function value(ProfilePage &$page, $field, $value, &$success)
     {
@@ -38,8 +38,8 @@ class ProfileDeco implements ProfileSetting
             }
 
             // Fetch not yet validated medals
-            require_once('validations.inc.php');
-            $medals = Validate::get_typed_requests(S::i('uid'), 'medal');
+            require_once 'validations.inc.php';
+            $medals = ProfileValidate::get_typed_requests($page->pid(), 'medal');
             foreach ($medals as &$medal) {
                 $value[$medal->mid] = array('grade' => $medal->gid,
                                             'valid' => '0');
@@ -53,7 +53,7 @@ class ProfileDeco implements ProfileSetting
 
     public function save(ProfilePage &$page, $field, $value)
     {
-        require_once('validations.inc.php');
+        require_once 'validations.inc.php';
 
         $orig =& $page->orig[$field];
 
@@ -65,7 +65,7 @@ class ProfileDeco implements ProfileSetting
                                         WHERE  pid = {?} AND mid = {?}",
                                  $page->pid(), $id);
                 } else {
-                    $req = MedalReq::get_request(S::i('uid'), $id);
+                    $req = MedalReq::get_request($page->pid(), $id);
                     if ($req) {
                         $req->clean();
                     }
@@ -76,23 +76,32 @@ class ProfileDeco implements ProfileSetting
         // Add new ones
         foreach ($value as $id=>&$val) {
             if (!isset($orig[$id]) || $orig[$id]['grade'] != $val['grade']) {
-                $req = new MedalReq(S::user(), $id, $val['grade']);
+                $req = new MedalReq(S::user(), $page->profile, $id, $val['grade']);
                 $req->submit();
                 sleep(1);
             }
         }
     }
+
+    public function getText($value) {
+        $medalsList = DirEnum::getOptions(DirEnum::MEDALS);
+        $medals = array();
+        foreach ($value as $id => $medal) {
+            $medals[] = $medalsList[$id];
+        }
+        return implode(', ', $medals);
+    }
 }
 
-class ProfileDecos extends ProfilePage
+class ProfileSettingDecos extends ProfilePage
 {
     protected $pg_template = 'profile/deco.tpl';
 
     public function __construct(PlWizard &$wiz)
     {
         parent::__construct($wiz);
-        $this->settings['medals'] = new ProfileDeco();
-        $this->settings['medals_pub'] = new ProfilePub();
+        $this->settings['medals'] = new ProfileSettingDeco();
+        $this->settings['medals_pub'] = new ProfileSettingPub();
         $this->watched['medals'] = true;
     }