Ejemplo n.º 1
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     require_once 'CRM/Member/BAO/Membership.php';
     require_once 'CRM/Member/BAO/MembershipType.php';
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $values = array();
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     // Make sure context is assigned to template for condition where we come here view civicrm/membership/view
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     if ($id) {
         $params = array('id' => $id);
         CRM_Member_BAO_Membership::retrieve($params, $values);
         // build associated contributions
         require_once 'CRM/Member/Page/Tab.php';
         CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
         //Provide information about membership source when it is the result of a relationship (CRM-1901)
         $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id');
         if (isset($values['owner_membership_id'])) {
             $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id');
             $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id');
             $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
             $direction = strrev($membershipType['relationship_direction']);
             $values['relationship'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $membershipType['relationship_type_id'], "name_{$direction}", 'id');
         }
         $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
         $this->assign('displayName', $displayName);
         // add viewed membership to recent items list
         require_once 'CRM/Utils/Recent.php';
         $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}");
         $title = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
         CRM_Utils_Recent::add($title, $url, $values['id'], 'Membership', $values['contact_id'], null);
         CRM_Member_Page_Tab::setContext($values['contact_id']);
         $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     }
     if ($values['is_test']) {
         $values['membership_type'] .= ' (test) ';
     }
     $this->assign($values);
 }
Ejemplo n.º 2
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $values = array();
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     // Make sure context is assigned to template for condition where we come here view civicrm/membership/view
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     if ($id) {
         $params = array('id' => $id);
         CRM_Member_BAO_Membership::retrieve($params, $values);
         $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
         // Do the action on related Membership if needed
         $relAction = CRM_Utils_Request::retrieve('relAction', 'String', $this);
         if ($relAction) {
             $this->relAction($relAction, $values);
         }
         // build associated contributions
         $this->assign('accessContribution', FALSE);
         if (CRM_Core_Permission::access('CiviContribute')) {
             $this->assign('accessContribution', TRUE);
             CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
         }
         //Provide information about membership source when it is the result of a relationship (CRM-1901)
         $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id');
         if (isset($values['owner_membership_id'])) {
             $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id');
             $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id');
             $direction = strrev($membershipType['relationship_direction']);
             // To display relationship type in view membership page
             $relTypeIds = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ",", $membershipType['relationship_type_id']);
             $sql = "\nSELECT relationship_type_id,\n  CASE\n  WHEN  contact_id_a = {$values['owner_contact_id']} AND contact_id_b = {$values['contact_id']} THEN 'b_a'\n  WHEN  contact_id_b = {$values['owner_contact_id']} AND contact_id_a = {$values['contact_id']} THEN 'a_b'\nEND AS 'relType'\n  FROM civicrm_relationship\n WHERE relationship_type_id IN ({$relTypeIds})";
             $dao = CRM_Core_DAO::executeQuery($sql);
             $values['relationship'] = NULL;
             while ($dao->fetch()) {
                 $typeId = $dao->relationship_type_id;
                 $direction = $dao->relType;
                 if ($direction && $typeId) {
                     if ($values['relationship']) {
                         $values['relationship'] .= ',';
                     }
                     $values['relationship'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $typeId, "name_{$direction}", 'id');
                 }
             }
         }
         $this->assign('has_related', FALSE);
         // if membership can be granted, and we are the owner of the membership
         if (!empty($membershipType['relationship_type_id']) && empty($values['owner_membership_id'])) {
             // display related contacts/membership block
             $this->assign('has_related', TRUE);
             $this->assign('max_related', CRM_Utils_Array::value('max_related', $values, ts('Unlimited')));
             // split the relations in 2 arrays based on direction
             $relTypeId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
             $relDirection = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
             foreach ($relTypeId as $rid) {
                 $dir = each($relDirection);
                 $relTypeDir[substr($dir['value'], 0, 1)][] = $rid;
             }
             // build query in 2 parts with a UNION if necessary
             // _x and _y are replaced with _a and _b first, then vice-versa
             // comment is a qualifier for the relationship - now just job_title
             $select = "\nSELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment,\n       rt.name_x_y as relation, r.start_date, r.end_date,\n       m.id as mid, ms.is_current_member, ms.label as status\n  FROM civicrm_relationship r\n  LEFT JOIN civicrm_relationship_type rt ON rt.id = r.relationship_type_id\n  LEFT JOIN civicrm_contact c ON c.id = r.contact_id_x\n  LEFT JOIN civicrm_membership m ON (m.owner_membership_id = {$values['id']}\n  AND m.contact_id = r.contact_id_x AND m.is_test = 0)\n  LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id\n WHERE r.contact_id_y = {$values['contact_id']} AND r.is_active = 1  AND c.is_deleted = 0";
             $query = '';
             foreach (array('a', 'b') as $dir) {
                 if (isset($relTypeDir[$dir])) {
                     $query .= ($query ? ' UNION ' : '') . str_replace('_y', '_' . $dir, str_replace('_x', '_' . ($dir == 'a' ? 'b' : 'a'), $select)) . ' AND r.relationship_type_id IN (' . implode(',', $relTypeDir[$dir]) . ')';
                 }
             }
             $query .= " ORDER BY is_current_member DESC";
             $dao = CRM_Core_DAO::executeQuery($query);
             $related = array();
             $relatedRemaining = CRM_Utils_Array::value('max_related', $values, PHP_INT_MAX);
             $rowElememts = array('id', 'cid', 'name', 'comment', 'relation', 'mid', 'start_date', 'end_date', 'is_current_member', 'status');
             while ($dao->fetch()) {
                 $row = array();
                 foreach ($rowElememts as $field) {
                     $row[$field] = $dao->{$field};
                 }
                 if ($row['mid'] && $row['is_current_member'] == 1) {
                     $relatedRemaining--;
                     $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::DELETE, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'mid' => $row['mid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this));
                 } else {
                     if ($relatedRemaining > 0) {
                         $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::ADD, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'rid' => $row['cid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this));
                     }
                 }
                 $related[] = $row;
             }
             $this->assign('related', $related);
             if ($relatedRemaining <= 0) {
                 $this->assign('related_text', ts('None available'));
             } else {
                 if ($relatedRemaining < 100000) {
                     $this->assign('related_text', ts('%1 available', array(1 => $relatedRemaining)));
                 } else {
                     $this->assign('related_text', ts('Unlimited', array(1 => $relatedRemaining)));
                 }
             }
         }
         $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
         $this->assign('displayName', $displayName);
         // Check if this is default domain contact CRM-10482
         if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
             $displayName .= ' (' . ts('default organization') . ')';
         }
         // omitting contactImage from title for now since the summary overlay css doesn't work outside crm-container
         CRM_Utils_System::setTitle(ts('View Membership for') . ' ' . $displayName);
         // add viewed membership to recent items list
         $recentTitle = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
         $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         $recentOther = array();
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::UPDATE)) {
             $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
             $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         CRM_Utils_Recent::add($recentTitle, $url, $values['id'], 'Membership', $values['contact_id'], NULL, $recentOther);
         CRM_Member_Page_Tab::setContext($this, $values['contact_id']);
         $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
         $isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id');
         $autoRenew = $isRecur ? TRUE : FALSE;
     }
     if (!empty($values['is_test'])) {
         $values['membership_type'] .= ' (test) ';
     }
     $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($id);
     $values['auto_renew'] = $autoRenew && !$subscriptionCancelled ? 'Yes' : 'No';
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     $this->assign($values);
 }
Ejemplo n.º 3
0
 /**
  * Function to define action links for membership types of related organization
  *
  * @return array self::$_membershipTypesLinks array of action links
  * @access public
  */
 static function &membershipTypesLinks()
 {
     if (!self::$_membershipTypesLinks) {
         self::$_membershipTypesLinks = array(CRM_Core_Action::VIEW => array('name' => ts('Members'), 'url' => 'civicrm/member/search/', 'qs' => 'reset=1&force=1&type=%%id%%', 'title' => ts('Search')), CRM_Core_Action::UPDATE => array('name' => ts('Edit'), 'url' => 'civicrm/admin/member/membershipType', 'qs' => 'action=update&id=%%id%%&reset=1', 'title' => ts('Edit Membership Type')));
     }
     return self::$_membershipTypesLinks;
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $values = array();
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     // Make sure context is assigned to template for condition where we come here view civicrm/membership/view
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     if ($id) {
         $params = array('id' => $id);
         CRM_Member_BAO_Membership::retrieve($params, $values);
         // build associated contributions
         CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
         //Provide information about membership source when it is the result of a relationship (CRM-1901)
         $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id');
         if (isset($values['owner_membership_id'])) {
             $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id');
             $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id');
             $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
             $direction = strrev($membershipType['relationship_direction']);
             // To display relationship type in view membership page
             $relTypeIds = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ",", $membershipType['relationship_type_id']);
             $sql = "\nSELECT relationship_type_id,\n  CASE    \n  WHEN  contact_id_a = {$values['owner_contact_id']} AND contact_id_b = {$values['contact_id']} THEN 'b_a'\n  WHEN  contact_id_b = {$values['owner_contact_id']} AND contact_id_a = {$values['contact_id']} THEN 'a_b'\nEND AS 'relType'\n  FROM civicrm_relationship \n WHERE relationship_type_id IN ({$relTypeIds})";
             $dao = CRM_Core_DAO::executeQuery($sql);
             $values['relationship'] = NULL;
             while ($dao->fetch()) {
                 $membershipType['relationship_type_id'] = $dao->relationship_type_id;
                 $direction = $dao->relType;
                 if ($direction && $membershipType['relationship_type_id']) {
                     if ($values['relationship']) {
                         $values['relationship'] .= ',';
                     }
                     $values['relationship'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $membershipType['relationship_type_id'], "name_{$direction}", 'id');
                 }
             }
         }
         $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
         $this->assign('displayName', $displayName);
         // add viewed membership to recent items list
         $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         $title = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
         $recentOther = array();
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::UPDATE)) {
             $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
             $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         CRM_Utils_Recent::add($title, $url, $values['id'], 'Membership', $values['contact_id'], NULL, $recentOther);
         CRM_Member_Page_Tab::setContext($values['contact_id']);
         $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
         $isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id');
         $autoRenew = $isRecur ? TRUE : FALSE;
     }
     if (CRM_Utils_Array::value('is_test', $values)) {
         $values['membership_type'] .= ' (test) ';
     }
     $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($id);
     $values['auto_renew'] = $autoRenew && !$subscriptionCancelled ? 'Yes' : 'No';
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     $this->assign($values);
 }