浏览代码

BxDolProfile::getInstanceByContentAndType method

Alex Trofimov 13 年之前
父节点
当前提交
9d7a21ab26
共有 2 个文件被更改,包括 24 次插入 和 1 次删除
  1. 13 0
      inc/classes/BxDolProfile.php
  2. 11 1
      inc/classes/BxDolProfileQuery.php

+ 13 - 0
inc/classes/BxDolProfile.php

@@ -68,6 +68,19 @@ class BxDolProfile extends BxDol implements iBxDolProfile {
         return self::getInstance($aProfile['id']);
     }
 
+    /**
+     * Get singleton instance of Profile by content id and type
+     */
+    public static function getInstanceByContentAndType($iContent, $sType) {
+        if (!$iAccountId)
+            $iAccountId = getLoggedId();
+        $oQuery = BxDolProfileQuery::getInstance();
+        $aProfile = $oQuery->getProfileByContentAndType($iContent, $sType);
+        if (!$aProfile)
+            return false;
+        return self::getInstance($aProfile['id']);
+    }
+
     /**
      * Get singleton instance of Profile by profile id
      */

+ 11 - 1
inc/classes/BxDolProfileQuery.php

@@ -51,7 +51,7 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton {
     }
 
     /**
-     * Get profile by account id.
+     * Get profile by content id, type and account.
      * @param string $iAccountId account id
      * @return array if aprofile ids, key is profile id
      */
@@ -60,6 +60,16 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton {
         return $this->getRow($sSql);
     }
 
+    /**
+     * Get profile by content id and type.
+     * @param string $iAccountId account id
+     * @return array if aprofile ids, key is profile id
+     */
+    public function getProfileByContentAndType ($iContentId, $sType) {
+        $sSql = $this->prepare("SELECT * FROM `sys_profiles` WHERE `content_id` = ? AND `type` = ?", $iContentId, $sType);
+        return $this->getRow($sSql);
+    }
+
     /**
      * Insert account and content id association. Also if currect profile id is not defined - it updates current profile id in account.
      * @param $iAccountId account id