예제 #1
0
 /**
  * takes an associative array and creates a contact object
  *
  * the function extract all the params it needs to initialize the create a
  * contact object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params         (reference ) an assoc array of name/value pairs
  * @param array  $ids            the array that holds all the db ids
  * @param int    $locationId
  * @param int    $emailId
  * @param bool   $isPrimary      Has any previous entry been marked as isPrimary?
  *
  * @return object    CRM_Core_BAO_Email object if successful 
  *                   else null will be returned
  * @access public
  * @static
  */
 function add(&$params, &$ids, $locationId, $emailId, &$isPrimary)
 {
     // if no data and we are not updating an exisiting record
     if (!CRM_Core_BAO_Email::dataExists($params, $locationId, $emailId, $ids)) {
         return null;
     }
     $email =& new CRM_Core_DAO_Email();
     $email->id = CRM_Utils_Array::value($emailId, $ids['location'][$locationId]['email']);
     $email->email = $params['location'][$locationId]['email'][$emailId]['email'];
     if (empty($email->email)) {
         $email->delete();
         return null;
     }
     $email->location_id = $params['location'][$locationId]['id'];
     // set this object to be the value of isPrimary and make sure no one else can be isPrimary
     $email->is_primary = $isPrimary;
     $isPrimary = false;
     return $email->save();
 }
예제 #2
0
 /**
  * Check if there is data to create the object
  *
  * @param array  $params         (reference ) an assoc array of name/value pairs
  * @param array  $locationId     
  * @param array  $ids            (reference ) the array that holds all the db ids
  *
  * @return boolean
  * @access public
  * @static
  */
 function dataExists(&$params, $locationId, &$ids)
 {
     if (CRM_Utils_Array::value('id', $ids['location'][$locationId])) {
         return true;
     }
     // return if no data present
     if (!array_key_exists('location', $params) || !array_key_exists($locationId, $params['location'])) {
         return false;
     }
     //if location name exits return true
     if (CRM_Utils_Array::value('name', $params['location'][$locationId])) {
         return true;
     }
     if (CRM_Core_BAO_Address::dataExists($params, $locationId, $ids)) {
         return true;
     }
     for ($i = 1; $i <= CRM_CONTACT_FORM_LOCATION_BLOCKS; $i++) {
         if (CRM_Core_BAO_Phone::dataExists($params, $locationId, $i, $ids) || CRM_Core_BAO_Email::dataExists($params, $locationId, $i, $ids) || CRM_Core_BAO_IM::dataExists($params, $locationId, $i, $ids)) {
             return true;
         }
     }
     return false;
 }