/**
 * Create a Membership Status
 *
 * This API is used for creating a Membership Status
 *
 * @param   array  $params  an associative array of name/value property values of civicrm_membership_status
 *
 * @return array of newly created membership status property values.
 * {@getfields MembershipStatus_create}
 * @access public
 */
function civicrm_api3_membership_status_create($params)
{
    civicrm_api3_verify_one_mandatory($params, 'CRM_Member_DAO_MembershipStatus', array('name', 'label'));
    //move before verifiy? DAO check requires?
    if (empty($params['name'])) {
        $params['name'] = CRM_Utils_Array::value('label', $params);
    }
    //don't allow duplicate names.
    require_once 'CRM/Member/DAO/MembershipStatus.php';
    $status = new CRM_Member_DAO_MembershipStatus();
    $status->name = $params['name'];
    if ($status->find(TRUE)) {
        return civicrm_api3_create_error(ts('A membership status with this name already exists.'));
    }
    require_once 'CRM/Member/BAO/MembershipStatus.php';
    $ids = array();
    $membershipStatusBAO = CRM_Member_BAO_MembershipStatus::add($params, $ids);
    if (is_a($membershipStatusBAO, 'CRM_Core_Error')) {
        return civicrm_api3_create_error("Membership is not created");
    } else {
        $values = array();
        $values['id'] = $membershipStatusBAO->id;
        $values['is_error'] = 0;
        return civicrm_api3_create_success($values, $params);
    }
}
/**
 * Create a Membership Status
 *
 * This API is used for creating a Membership Status
 *
 * @param   array  $params  an associative array of name/value property values of civicrm_membership_status
 *
 * @return array of newly created membership status property values.
 * @access public
 */
function civicrm_membership_status_create(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        return civicrm_create_error('Params is not an array.');
    }
    if (empty($params)) {
        return civicrm_create_error('Params can not be empty.');
    }
    $name = CRM_Utils_Array::value('name', $params);
    if (!$name) {
        $name = CRM_Utils_Array::value('label', $params);
    }
    if (!$name) {
        return civicrm_create_error('Missing required fields');
    }
    //don't allow duplicate names.
    require_once 'CRM/Member/DAO/MembershipStatus.php';
    $status = new CRM_Member_DAO_MembershipStatus();
    $status->name = $name;
    if ($status->find(TRUE)) {
        return civicrm_create_error(ts('A membership status with this name already exists.'));
    }
    require_once 'CRM/Member/BAO/MembershipStatus.php';
    $ids = array();
    $membershipStatusBAO = CRM_Member_BAO_MembershipStatus::add($params, $ids);
    if (is_a($membershipStatusBAO, 'CRM_Core_Error')) {
        return civicrm_create_error("Membership is not created");
    } else {
        $values = array();
        $values['id'] = $membershipStatusBAO->id;
        $values['is_error'] = 0;
        return $values;
    }
}
Example #3
0
/**
 * Create a Membership Status
 *  
 * This API is used for creating a Membership Status
 * 
 * @param   array  $params  an associative array of name/value property values of civicrm_membership_status
 * @return array of newly created membership status property values.
 * @access public
 */
function civicrm_membership_status_create(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        return civicrm_create_error('Params is not an array.');
    }
    if (empty($params)) {
        return civicrm_create_error('Params can not be empty.');
    }
    if (!isset($params['name'])) {
        return civicrm_create_error('Missing required fields');
    }
    require_once 'CRM/Member/BAO/MembershipStatus.php';
    $ids = array();
    $membershipStatusBAO = CRM_Member_BAO_MembershipStatus::add($params, $ids);
    if (is_a($membershipStatusBAO, 'CRM_Core_Error')) {
        return civicrm_create_error("Membership is not created");
    } else {
        $values = array();
        $values['id'] = $membershipStatusBAO->id;
        $values['is_error'] = 0;
        return $values;
    }
}
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         try {
             CRM_Member_BAO_MembershipStatus::del($this->_id);
         } catch (CRM_Core_Exception $e) {
             CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Delete Failed'));
         }
         CRM_Core_Session::setStatus(ts('Selected membership status has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['membershipStatus'] = $this->_id;
         }
         $oldWeight = NULL;
         if ($this->_id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']);
         // only for add mode, set label to name.
         if ($this->_action & CRM_Core_Action::ADD) {
             $params['name'] = $params['label'];
         }
         $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.', array(1 => $membershipStatus->label)), ts('Saved'), 'success');
     }
 }
 public function testgetMembershipStatusCurrent()
 {
     $params = array('name' => 'Current', 'is_active' => 1, 'is_current_member' => 1);
     $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
     $result = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
     $this->assertEquals(empty($result), FALSE, 'Verify membership status records is_current_member.');
 }
 /**
  * Takes an associative array and creates a membership Status object.
  * See http://wiki.civicrm.org/confluence/display/CRM/Database+layer
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @throws Exception
  * @return CRM_Member_BAO_MembershipStatus
  */
 public static function create($params)
 {
     $ids = array();
     if (!empty($params['id'])) {
         $ids['membershipStatus'] = $params['id'];
     } else {
         //don't allow duplicate names - if id not set
         $status = new CRM_Member_DAO_MembershipStatus();
         $status->name = $params['name'];
         if ($status->find(TRUE)) {
             throw new Exception('A membership status with this name already exists.');
         }
     }
     $membershipStatusBAO = CRM_Member_BAO_MembershipStatus::add($params, $ids);
     return $membershipStatusBAO;
 }
Example #7
0
/**
 * Create a Membership Status
 *  
 * This API is used for creating a Membership Status
 * 
 * @param   array  $params  an associative array of name/value property values of civicrm_membership_status
 * @return array of newly created membership status property values.
 * @access public
 */
function crm_create_membership_status($params)
{
    _crm_initialize();
    if (!is_array($params)) {
        return _crm_error('Params is not an array.');
    }
    if (empty($params)) {
        return _crm_error('Params can not be empty.');
    }
    if (!$params["name"]) {
        return _crm_error('Missing require fileds');
    }
    require_once 'CRM/Member/BAO/MembershipStatus.php';
    $ids = array();
    $membershipStatusBAO = CRM_Member_BAO_MembershipStatus::add($params, $ids);
    $membershipStatus = array();
    _crm_object_to_array($membershipStatusBAO, $membershipStatus);
    return $membershipStatus;
}
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     require_once 'CRM/Member/BAO/MembershipStatus.php';
     if ($this->_action & CRM_Core_Action::DELETE) {
         $wt = CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipStatus', $this->_id);
         CRM_Member_BAO_MembershipStatus::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected membership status has been deleted.'));
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['membershipStatus'] = $this->_id;
         }
         if ($this->_id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']);
         // only for add mode, set label to name.
         if ($this->_action & CRM_Core_Action::ADD) {
             $params['name'] = $params['label'];
         }
         $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.', array(1 => $membershipStatus->label)));
     }
 }