Просмотр исходного кода

Ticket #3029 - Orgs: ability to move org to another owner.

AntonLV 2 лет назад
Родитель
Сommit
a42a7b0d2b

+ 14 - 0
inc/classes/BxDolProfile.php

@@ -589,6 +589,20 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
         return $this->changeStatus(BX_PROFILE_STATUS_PENDING, 'disapprove', $iAction, $iProfileId, $bSendEmailNotification);
     }
 
+    /**
+     * Move profile to another account
+     */
+    public function move($iAccountId, $iProfileId = 0)
+    {
+        if (!$iProfileId)
+            $iProfileId = $this->_iProfileID;
+
+        if($this->getAccountId($iProfileId) == $iAccountId)
+            return true;
+
+        return $this->_oQuery->changeAccountId($iProfileId, $iAccountId) !== false;
+    }
+
     public function doAudit($sAction, $aData = array())
     {
         bx_audit(

+ 11 - 0
inc/classes/BxDolProfileQuery.php

@@ -207,6 +207,17 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
         return $iProfileId;
     }
 
+    /**
+     * Update profile's account id
+     * @param $iProfileId profile id
+     * @param $iAccountId new Account ID
+     * @return true on success or false otherwise
+     */
+    public function changeAccountId ($iProfileId, $iAccountId)
+    {
+        return $this->_updateField ($iProfileId, 'account_id', $iAccountId);
+    }
+
     /**
      * Update profile's status
      * @param $iProfileId profile id

+ 17 - 0
modules/boonex/organizations/classes/BxOrgsFormEntry.php

@@ -21,6 +21,23 @@ class BxOrgsFormEntry extends BxBaseModGroupsFormEntry
         $this->MODULE = 'bx_organizations';
         parent::__construct($aInfo, $oTemplate);
     }
+    
+    public function update ($iContentId, $aValsToAdd = [], &$aTrackTextFieldsChanges = null)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
+
+        $mixedResult = parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
+        if($mixedResult && ($iAuthorId = (int)$this->getCleanValue($CNF['FIELD_AUTHOR'])) && (int)$aContentInfo[$CNF['FIELD_AUTHOR']] != $iAuthorId) {
+            $oProfileAuthor = BxDolProfile::getInstance($iAuthorId);
+            $oProfileContent = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
+            if($oProfileAuthor !== false && $oProfileContent !== false)
+                $oProfileContent->move($oProfileAuthor->getAccountId());
+        }
+
+        return $mixedResult;
+    }
 }
 
 /** @} */