/** * 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 $imId * @param bool $isPrimary Has any previous entry been marked as isPrimary? * * @return object CRM_Core_BAO_IM object on success, null otherwise * @access public * @static */ function add(&$params, &$ids, $locationId, $imId, &$isPrimary) { if (!CRM_Core_BAO_IM::dataExists($params, $locationId, $imId, $ids)) { return null; } $im =& new CRM_Core_DAO_IM(); $im->name = $params['location'][$locationId]['im'][$imId]['name']; $im->id = CRM_Utils_Array::value($imId, $ids['location'][$locationId]['im']); if (empty($im->name)) { $im->delete(); return null; } $im->location_id = $params['location'][$locationId]['id']; $im->provider_id = $params['location'][$locationId]['im'][$imId]['provider_id']; if (!$im->provider_id) { $im->provider_id = 'null'; } // set this object to be the value of isPrimary and make sure no one else can be isPrimary $im->is_primary = $isPrimary; $isPrimary = false; return $im->save(); }
/** * 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; }