/** * Link the price set with the specified table and id * * @param string $entityTable * @param integer $entityId * @param integer $priceSetId * * @return bool */ public static function addTo($entityTable, $entityId, $priceSetId) { // verify that the price set exists $dao = new CRM_Price_DAO_Set(); $dao->id = $priceSetId; if (!$dao->find()) { return FALSE; } unset($dao); $dao = new CRM_Price_DAO_SetEntity(); // find if this already exists $dao->entity_id = $entityId; $dao->entity_table = $entityTable; $dao->find(TRUE); // add or update price_set_id $dao->price_set_id = $priceSetId; return $dao->save(); }
/** * Find a price_set_id associatied with the given table and id * * @param string $entityTable * @param integer $entityId * @return integer|false price_set_id, or false if none found */ public static function getFor($entityTable, $entityId) { if (!$entityTable || !$entityId) { return false; } require_once 'CRM/Price/DAO/SetEntity.php'; $dao = new CRM_Price_DAO_SetEntity(); $dao->entity_table = $entityTable; $dao->entity_id = $entityId; $dao->find(true); return isset($dao->price_set_id) ? $dao->price_set_id : false; }