/** * function to add the membership types * * @param array $params reference array contains the values submitted by the form * @param array $ids reference array contains the id * * @access public * @static * * @return object */ static function add(&$params, &$ids) { $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['is_current_member'] = CRM_Utils_Array::value('is_current_member', $params, FALSE); $params['is_admin'] = CRM_Utils_Array::value('is_admin', $params, FALSE); $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); // set all other defaults to false. if ($params['is_default']) { $query = "UPDATE civicrm_membership_status SET is_default = 0"; CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } //copy name to label when not passed. if (empty($params['label']) && !empty($params['name'])) { $params['label'] = $params['name']; } //for add mode, copy label to name. $statusId = CRM_Utils_Array::value('membershipStatus', $ids); if (!$statusId && !empty($params['label']) && empty($params['name'])) { $params['name'] = $params['label']; } // action is taken depending upon the mode $membershipStatus = new CRM_Member_DAO_MembershipStatus(); $membershipStatus->copyValues($params); $membershipStatus->id = $statusId; $membershipStatus->save(); return $membershipStatus; }
/** * Add the membership types. * * @param array $params * Reference array contains the values submitted by the form. * @param array $ids * Array contains the id - this param is deprecated. * * * @return object */ public static function add(&$params, $ids = array()) { $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membershipStatus', $ids)); if (!$id) { CRM_Core_DAO::setCreateDefaults($params, self::getDefaults()); //copy name to label when not passed. if (empty($params['label']) && !empty($params['name'])) { $params['label'] = $params['name']; } if (empty($params['name']) && !empty($params['label'])) { $params['name'] = $params['label']; } } // set all other defaults to false. if (!empty($params['is_default'])) { $query = "UPDATE civicrm_membership_status SET is_default = 0"; CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } // action is taken depending upon the mode $membershipStatus = new CRM_Member_DAO_MembershipStatus(); $membershipStatus->copyValues($params); $membershipStatus->id = $id; $membershipStatus->save(); return $membershipStatus; }
/** * @param $rev */ public function upgrade_3_2_beta4($rev) { $upgrade = new CRM_Upgrade_Form(); $config = CRM_Core_Config::singleton(); $seedLocale = $config->lcMessages; //handle missing civicrm_uf_field.help_pre $hasLocalizedPreHelpCols = FALSE; // CRM-6451: for multilingual sites we need to find the optimal // locale to use as the final civicrm_membership_status.name column $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); $locales = array(); if ($domain->locales) { $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); // optimal: an English locale foreach (array('en_US', 'en_GB', 'en_AU') as $loc) { if (in_array($loc, $locales)) { $seedLocale = $loc; break; } } // if no English and no $config->lcMessages: use the first available if (!$seedLocale) { $seedLocale = $locales[0]; } $upgrade->assign('seedLocale', $seedLocale); $upgrade->assign('locales', $locales); $localizedColNames = array(); foreach ($locales as $loc) { $localizedName = "help_pre_{$loc}"; $localizedColNames[$localizedName] = $localizedName; } $columns = CRM_Core_DAO::executeQuery('SHOW COLUMNS FROM civicrm_uf_field'); while ($columns->fetch()) { if (strpos($columns->Field, 'help_pre') !== FALSE && in_array($columns->Field, $localizedColNames)) { $hasLocalizedPreHelpCols = TRUE; break; } } } $upgrade->assign('hasLocalizedPreHelpCols', $hasLocalizedPreHelpCols); $upgrade->processSQL($rev); // now civicrm_membership_status.name has possibly localised strings, so fix them $i18n = new CRM_Core_I18n($seedLocale); $statuses = array(array('name' => 'New', 'start_event' => 'join_date', 'end_event' => 'join_date', 'end_event_adjust_unit' => 'month', 'end_event_adjust_interval' => '3', 'is_current_member' => '1', 'is_admin' => '0', 'is_default' => '0', 'is_reserved' => '0'), array('name' => 'Current', 'start_event' => 'start_date', 'end_event' => 'end_date', 'is_current_member' => '1', 'is_admin' => '0', 'is_default' => '1', 'is_reserved' => '0'), array('name' => 'Grace', 'start_event' => 'end_date', 'end_event' => 'end_date', 'end_event_adjust_unit' => 'month', 'end_event_adjust_interval' => '1', 'is_current_member' => '1', 'is_admin' => '0', 'is_default' => '0', 'is_reserved' => '0'), array('name' => 'Expired', 'start_event' => 'end_date', 'start_event_adjust_unit' => 'month', 'start_event_adjust_interval' => '1', 'is_current_member' => '0', 'is_admin' => '0', 'is_default' => '0', 'is_reserved' => '0'), array('name' => 'Pending', 'start_event' => 'join_date', 'end_event' => 'join_date', 'is_current_member' => '0', 'is_admin' => '0', 'is_default' => '0', 'is_reserved' => '1'), array('name' => 'Cancelled', 'start_event' => 'join_date', 'end_event' => 'join_date', 'is_current_member' => '0', 'is_admin' => '0', 'is_default' => '0', 'is_reserved' => '0'), array('name' => 'Deceased', 'is_current_member' => '0', 'is_admin' => '1', 'is_default' => '0', 'is_reserved' => '1')); $statusIds = array(); $insertedNewRecord = FALSE; foreach ($statuses as $status) { $dao = new CRM_Member_DAO_MembershipStatus(); // try to find an existing English status $dao->name = $status['name']; // // if not found, look for translated status name // if (!$dao->find(true)) { // $found = false; // $dao->name = $i18n->translate($status['name']); // } // if found, update name and is_reserved if ($dao->find(TRUE)) { $dao->name = $status['name']; $dao->is_reserved = $status['is_reserved']; if ($status['is_reserved']) { $dao->is_active = 1; } // if not found, prepare a new row for insertion } else { $insertedNewRecord = TRUE; foreach ($status as $property => $value) { $dao->{$property} = $value; } $dao->weight = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipStatus'); } // add label (translated name) and save (UPDATE or INSERT) $dao->label = $i18n->translate($status['name']); $dao->save(); $statusIds[$dao->id] = $dao->id; } //disable all status those are customs. if ($insertedNewRecord) { $sql = ' UPDATE civicrm_membership_status SET is_active = 0 WHERE id NOT IN ( ' . implode(',', $statusIds) . ' )'; CRM_Core_DAO::executeQuery($sql); } }