X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FPseudoConstant.php;h=26000e203b02138b5663afd2d08a17cbedd8dfae;hb=a13f3d8c01e114b11c381b6ac3e64becae9380b1;hp=dfed28d604be8a32e22f85593ff2a7ab1b69a46c;hpb=e01a5ffed559ccb3a64fba29f0ca8964e00d3178;p=civicrm-core.git diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index dfed28d604..26000e203b 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -1,7 +1,7 @@ label format if false * if true, the results are reversed @@ -221,7 +228,7 @@ class CRM_Core_PseudoConstant { * - orderColumn string the column to use for sorting, defaults to 'weight' column if one exists, else defaults to labelColumn * - onlyActive boolean return only the action option values * - fresh boolean ignore cache entries and go back to DB - * @param String $context: Context string + * @param string $context: Context string * * @return Array|bool - array on success, FALSE on error. * @@ -436,9 +443,9 @@ class CRM_Core_PseudoConstant { /** * Fetch the translated label for a field given its key * - * @param String $baoName - * @param String $fieldName - * @param String|Int $key + * @param string $baoName + * @param string $fieldName + * @param string|Int $key * * TODO: Accept multivalued input? * @@ -447,7 +454,7 @@ class CRM_Core_PseudoConstant { * NULL if the given key has no corresponding option * String if label is found */ - static function getLabel($baoName, $fieldName, $key) { + public static function getLabel($baoName, $fieldName, $key) { $values = $baoName::buildOptions($fieldName, 'get'); if ($values === FALSE) { return FALSE; @@ -458,16 +465,16 @@ class CRM_Core_PseudoConstant { /** * Fetch the machine name for a field given its key * - * @param String $baoName - * @param String $fieldName - * @param String|Int $key + * @param string $baoName + * @param string $fieldName + * @param string|Int $key * * @return bool|null|string * FALSE if the given field has no associated option list * NULL if the given key has no corresponding option * String if label is found */ - static function getName($baoName, $fieldName, $key) { + public static function getName($baoName, $fieldName, $key) { $values = $baoName::buildOptions($fieldName, 'validate'); if ($values === FALSE) { return FALSE; @@ -478,16 +485,16 @@ class CRM_Core_PseudoConstant { /** * Fetch the key for a field option given its name * - * @param String $baoName - * @param String $fieldName - * @param String|Int $value + * @param string $baoName + * @param string $fieldName + * @param string|Int $value * * @return bool|null|string|number * FALSE if the given field has no associated option list * NULL if the given key has no corresponding option * String|Number if key is found */ - static function getKey($baoName, $fieldName, $value) { + public static function getKey($baoName, $fieldName, $value) { $values = $baoName::buildOptions($fieldName, 'validate'); if ($values === FALSE) { return FALSE; @@ -500,7 +507,7 @@ class CRM_Core_PseudoConstant { * @param $fieldSpec * @return string|null */ - static function getOptionEditUrl($fieldSpec) { + public static function getOptionEditUrl($fieldSpec) { // If it's an option group, that's easy if (!empty($fieldSpec['pseudoconstant']['optionGroupName'])) { return 'civicrm/admin/options/' . $fieldSpec['pseudoconstant']['optionGroupName']; @@ -524,26 +531,31 @@ class CRM_Core_PseudoConstant { /** * DEPRECATED generic populate method - * All pseudoconstant functions that use this method are also deprecated. + * All pseudoconstant functions that use this method are also @deprecated * * The static array $var is populated from the db * using the $name DAO. * * Note: any database errors will be trapped by the DAO. * - * @param array $var the associative array we will fill - * @param string $name the name of the DAO - * @param boolean $all get all objects. default is to get only active ones. - * @param string $retrieve the field that we are interested in (normally name, differs in some objects) - * @param string $filter the field that we want to filter the result set with - * @param string $condition the condition that gets passed to the final query as the WHERE clause + * @param array $var + * The associative array we will fill. + * @param string $name + * The name of the DAO. + * @param bool $all + * Get all objects. default is to get only active ones. + * @param string $retrieve + * The field that we are interested in (normally name, differs in some objects). + * @param string $filter + * The field that we want to filter the result set with. + * @param string $condition + * The condition that gets passed to the final query as the WHERE clause. * * @param null $orderby * @param string $key * @param null $force * * @return void - * @access public * @static */ public static function populate( @@ -596,7 +608,6 @@ class CRM_Core_PseudoConstant { * Flush given pseudoconstant so it can be reread from db * nex time it's requested. * - * @access public * @static * * @param bool|string $name pseudoconstant to be flushed @@ -611,15 +622,12 @@ class CRM_Core_PseudoConstant { } /** - * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object. + * @deprecated Please use the buildOptions() method in the appropriate BAO object. * * Get all Activty types. * * The static array activityType is returned * - * @internal param bool $all - get All Activity types - default is to get only active ones. - * - * @access public * @static * * @return array - array reference of all activity types. @@ -694,10 +702,9 @@ class CRM_Core_PseudoConstant { * * Note: any database errors will be trapped by the DAO. * - * @access public * @static * - * @param bool|int $id - Optional id to return + * @param bool|int $id - Optional id to return * * @param bool $limit * @@ -750,10 +757,9 @@ class CRM_Core_PseudoConstant { * * Same as above, except gets the abbreviations instead of the names. * - * @access public * @static * - * @param bool|int $id - Optional id to return + * @param bool|int $id - Optional id to return * * @param bool $limit * @@ -818,7 +824,6 @@ WHERE id = %1"; * * Note: any database errors will be trapped by the DAO. * - * @access public * @static * * @param bool|int $id - Optional id to return @@ -896,7 +901,6 @@ WHERE id = %1"; * * Note: any database errors will be trapped by the DAO. * - * @access public * @static * * @param bool $id @@ -919,7 +923,7 @@ WHERE id = %1"; } /** - * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object. + * @deprecated Please use the buildOptions() method in the appropriate BAO object. * * Get all groups from database * @@ -929,10 +933,11 @@ WHERE id = %1"; * * Note: any database errors will be trapped by the DAO. * - * @param string $groupType type of group(Access/Mailing) - * @param bool|\boolen $excludeHidden exclude hidden groups. + * @param string $groupType + * Type of group(Access/Mailing). + * @param bool $excludeHidden + * Exclude hidden groups. * - * @access public * @static * * @return array - array reference of all groups. @@ -961,7 +966,6 @@ WHERE id = %1"; * called for the first time * * - * @access public * @static * * @param bool $styledLabels @@ -988,10 +992,11 @@ WHERE id = %1"; * * Note: any database errors will be trapped by the DAO. * - * @param string $groupType type of group(Access/Mailing) - * @param bool $excludeHidden exclude hidden groups. + * @param string $groupType + * Type of group(Access/Mailing). + * @param bool $excludeHidden + * Exclude hidden groups. * - * @access public * @static * * @return array - array reference of all groups. @@ -1021,7 +1026,6 @@ WHERE id = %1"; * * Note: any database errors will be trapped by the DAO. * - * @access public * @static * * @param bool $onlyPublic @@ -1060,10 +1064,11 @@ WHERE id = %1"; * * Note: any database errors will be trapped by the DAO. * - * @param string $valueColumnName db column name/label. - * @param boolean $reset reset relationship types if true + * @param string $valueColumnName + * Db column name/label. + * @param bool $reset + * Reset relationship types if true. * - * @access public * @static * * @return array - array reference of all relationship types. @@ -1099,11 +1104,10 @@ WHERE id = %1"; } /** - * get all the ISO 4217 currency codes + * Get all the ISO 4217 currency codes * * so far, we use this for validation only, so there's no point of putting this into the database * - * @access public * * @return array - array reference of all currency codes * @static @@ -1392,10 +1396,9 @@ WHERE id = %1"; * * Note: any database errors will be trapped by the DAO. * - * @access public * @static * - * @param bool|int $id - Optional id to return + * @param bool|int $id - Optional id to return * * @return array - array reference of all Counties */ @@ -1418,16 +1421,17 @@ WHERE id = %1"; } /** - * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object. + * @deprecated Please use the buildOptions() method in the appropriate BAO object. * Get all active payment processors * * The static array paymentProcessor is returned * - * @access public * @static * - * @param boolean $all - get payment processors - default is to get only active ones. - * @param boolean $test - get test payment processors + * @param bool $all + * Get payment processors - default is to get only active ones. + * @param bool $test + * Get test payment processors. * * @param null $additionalCond * @@ -1454,16 +1458,16 @@ WHERE id = %1"; } /** - * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object. + * @deprecated Please use the buildOptions() method in the appropriate BAO object. * * The static array paymentProcessorType is returned * - * @access public * @static * - * @param boolean $all - get payment processors - default is to get only active ones. + * @param bool $all + * Get payment processors - default is to get only active ones. * - * @param null $id + * @param int $id * @param string $return * * @return array - array of all payment processor types @@ -1482,7 +1486,6 @@ WHERE id = %1"; /** * Get all the World Regions from Database * - * @access public * * @param bool $id * @@ -1507,13 +1510,12 @@ WHERE id = %1"; } /** - * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object. + * @deprecated Please use the buildOptions() method in the appropriate BAO object. * * Get all Activity Statuses. * * The static array activityStatus is returned * - * @access public * @static * * @param string $column @@ -1534,13 +1536,12 @@ WHERE id = %1"; } /** - * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object. + * @deprecated Please use the buildOptions() method in the appropriate BAO object. * * Get all Visibility levels. * * The static array visibility is returned * - * @access public * @static * * @param string $column @@ -1549,18 +1550,18 @@ WHERE id = %1"; */ public static function &visibility($column = 'label') { if (!isset(self::$visibility)) { - self::$visibility = array( ); + self::$visibility = array(); } if (!isset(self::$visibility[$column])) { self::$visibility[$column] = CRM_Core_OptionGroup::values('visibility', FALSE, FALSE, FALSE, NULL, $column); - } + } return self::$visibility[$column]; } /** - * @param $countryID + * @param int $countryID * @param string $field * * @return array @@ -1615,7 +1616,7 @@ ORDER BY name"; } /** - * @param $stateID + * @param int $stateID * * @return array */ @@ -1676,13 +1677,13 @@ ORDER BY name"; * Given a state ID return the country ID, this allows * us to populate forms and values for downstream code * - * @param $stateID int + * @param $stateID + * Int. * * @return int the country id that the state belongs to * @static - * @public */ - static function countryIDForStateID($stateID) { + public static function countryIDForStateID($stateID) { if (empty($stateID)) { return CRM_Core_DAO::$_nullObject; } @@ -1702,10 +1703,10 @@ WHERE id = %1 * * The static array of greeting is returned * - * @access public * @static * - * @param $filter - get All Email Greetings - default is to get only active ones. + * @param $filter + * Get All Email Greetings - default is to get only active ones. * * @param string $columnName * @@ -1753,7 +1754,6 @@ WHERE id = %1 /** * Construct array of default greeting values for contact type * - * @access public * @static * * @return array - array reference of default greetings. @@ -1787,7 +1787,6 @@ WHERE id = %1 * FIXME: This is called by civix but not by any core code. We * should provide an API call which civix can use instead. * - * @access public * @static * * @return array - array($fullyQualifiedName => $label) list of extensions @@ -1814,20 +1813,20 @@ WHERE id = %1 * * The static array option values is returned * - * @access public * @static * - * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones. + * @param bool $optionGroupName + * Get All Option Group values- default is to get only active ones. * - * @param null $id + * @param int $id * @param null $condition * * @return array - array reference of all Option Group Name */ - public static function accountOptionValues($optionGroupName, $id = null, $condition = null) { + public static function accountOptionValues($optionGroupName, $id = NULL, $condition = NULL) { $cacheKey = $optionGroupName . '_' . $condition; if (empty(self::$accountOptionValues[$cacheKey])) { - self::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup::values($optionGroupName, false, false, false, $condition); + self::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup::values($optionGroupName, FALSE, FALSE, FALSE, $condition); } if ($id) { return CRM_Utils_Array::value($id, self::$accountOptionValues[$cacheKey]); @@ -1839,8 +1838,8 @@ WHERE id = %1 /** * Fetch the list of active extensions of type 'module' * - * @param $fresh bool whether to forcibly reload extensions list from canonical store - * @access public + * @param $fresh + * Bool whether to forcibly reload extensions list from canonical store. * @static * * @return array - array(array('prefix' => $, 'file' => $)) @@ -1848,5 +1847,36 @@ WHERE id = %1 public static function getModuleExtensions($fresh = FALSE) { return CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles($fresh); } -} + + /** + * Get all tax rates + * + * The static array tax rates is returned + * + * @static + * + * @return array - array list of tax rates with the financial type + */ + public static function getTaxRates() { + if (!self::$taxRates) { + self::$taxRates = array(); + $sql = " + SELECT fa.tax_rate, efa.entity_id + FROM civicrm_entity_financial_account efa + INNER JOIN civicrm_financial_account fa ON fa.id = efa.financial_account_id + INNER JOIN civicrm_option_value cov ON cov.value = efa.account_relationship + INNER JOIN civicrm_option_group cog ON cog.id = cov.option_group_id + WHERE efa.entity_table = 'civicrm_financial_type' + AND cov.name = 'Sales Tax Account is' + AND cog.name = 'account_relationship' + AND fa.is_active = 1"; + $dao = CRM_Core_DAO::executeQuery($sql); + while ($dao->fetch()) { + self::$taxRates[$dao->entity_id] = $dao->tax_rate; + } + } + + return self::$taxRates; + } +}