Пример #1
0
 /**
  * Set 'is_valid' field to false for all relationships whose end date is in the past, ie. are expired.
  *
  * @return bool
  *   True on success, false if error is encountered.
  */
 public static function disableExpiredRelationships()
 {
     $query = "SELECT id FROM civicrm_relationship WHERE is_active = 1 AND end_date < CURDATE()";
     $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
         $result = CRM_Contact_BAO_Relationship::setIsActive($dao->id, FALSE);
         // Result will be NULL if error occurred. We abort early if error detected.
         if ($result == NULL) {
             return FALSE;
         }
     }
     return TRUE;
 }
Пример #2
0
 /**
  * This function is the main function that is called when the page loads,
  * it decides the which action has to be taken for the page.
  * 
  * return null
  * @access public
  */
 function run()
 {
     $this->preProcess();
     $this->setContext();
     $this->_caseId = CRM_Utils_Request::retrieve('caseID', 'Integer', $this);
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->view();
     } else {
         if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
             $this->edit();
         } else {
             if ($this->_action & CRM_Core_Action::DISABLE) {
                 CRM_Contact_BAO_Relationship::disableEnableRelationship($this->_id, CRM_Core_Action::DISABLE);
                 CRM_Contact_BAO_Relationship::setIsActive($this->_id, 0);
                 $session =& CRM_Core_Session::singleton();
                 CRM_Utils_System::redirect($session->popUserContext());
             } else {
                 if ($this->_action & CRM_Core_Action::ENABLE) {
                     CRM_Contact_BAO_Relationship::disableEnableRelationship($this->_id, CRM_Core_Action::ENABLE);
                     CRM_Contact_BAO_Relationship::setIsActive($this->_id, 1);
                     $session =& CRM_Core_Session::singleton();
                     CRM_Utils_System::redirect($session->popUserContext());
                 }
             }
         }
     }
     // if this is called from case view, suppress browse relationships form
     if (!$this->_caseId) {
         $this->browse();
     }
     return parent::run();
 }
Пример #3
0
 /**
  * Clear cached current employer name.
  *
  * @param int $contactId
  *   Contact id ( mostly individual contact id).
  * @param int $employerId
  *   Contact id ( mostly organization contact id).
  */
 public static function clearCurrentEmployer($contactId, $employerId = NULL)
 {
     $query = "UPDATE civicrm_contact\nSET organization_name=NULL, employer_id = NULL\nWHERE id={$contactId}; ";
     $dao = CRM_Core_DAO::executeQuery($query);
     // need to handle related meberships. CRM-3792
     if ($employerId) {
         //1. disable corresponding relationship.
         //2. delete related membership.
         //get the relationship type id of "Employee of"
         $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
         if (!$relTypeId) {
             CRM_Core_Error::fatal(ts("You seem to have deleted the relationship type 'Employee of'"));
         }
         $relMembershipParams['relationship_type_id'] = $relTypeId . '_a_b';
         $relMembershipParams['contact_check'][$employerId] = 1;
         //get relationship id.
         if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($relMembershipParams, $contactId, $employerId)) {
             $relationship = new CRM_Contact_DAO_Relationship();
             $relationship->contact_id_a = $contactId;
             $relationship->contact_id_b = $employerId;
             $relationship->relationship_type_id = $relTypeId;
             if ($relationship->find(TRUE)) {
                 CRM_Contact_BAO_Relationship::setIsActive($relationship->id, FALSE);
                 CRM_Contact_BAO_Relationship::relatedMemberships($contactId, $relMembershipParams, $ids = array(), CRM_Core_Action::DELETE);
             }
             $relationship->free();
         }
     }
 }
Пример #4
0
 /**
  * This function is the main function that is called when the page loads,
  * it decides the which action has to be taken for the page.
  * 
  * return null
  * @access public
  */
 function run()
 {
     $this->preProcess();
     if ($this->_action & CRM_CORE_ACTION_VIEW) {
         $this->view();
     } else {
         if ($this->_action & (CRM_CORE_ACTION_UPDATE | CRM_CORE_ACTION_ADD | CRM_CORE_ACTION_DELETE)) {
             $this->edit();
         } else {
             if ($this->_action & CRM_CORE_ACTION_DISABLE) {
                 CRM_Contact_BAO_Relationship::setIsActive($this->_id, 0);
             } else {
                 if ($this->_action & CRM_CORE_ACTION_ENABLE) {
                     CRM_Contact_BAO_Relationship::setIsActive($this->_id, 1);
                 }
             }
         }
     }
     $this->browse();
     return parent::run();
 }