当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Contact_DAO_Contact::save方法代码示例

本文整理汇总了PHP中CRM_Contact_DAO_Contact::save方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_DAO_Contact::save方法的具体用法?PHP CRM_Contact_DAO_Contact::save怎么用?PHP CRM_Contact_DAO_Contact::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Contact_DAO_Contact的用法示例。


在下文中一共展示了CRM_Contact_DAO_Contact::save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: randomContact

 /**
  * Generate a random contact of type $cType.
  *
  * @param  string  Contact Type, default as 'Individual'
  * @return int     Contact ID of created contact
  */
 private function randomContact($cType = 'Individual')
 {
     $contact = new CRM_Contact_DAO_Contact();
     //TODO : in future if we need cType as 'Organization'
     //Generate contact of type individual randomly
     $contact->contact_type = $cType;
     if ($cType == 'Individual') {
         list($gender_id, $gender) = $this->randomKeyValue($this->gender);
         $contact->gender_id = $gender_id;
         $contact->first_name = $this->randomItem($gender . '_name');
         $contact->middle_name = $this->probability(0.5) ? '' : ucfirst($this->randomChar());
         $contact->last_name = $this->randomItem('last_name');
         $contact->sort_name = $contact->last_name . ', ' . $contact->first_name;
         $contact->display_name = $contact->first_name . ' ' . $contact->last_name;
     }
     $contact->save();
     $email = $this->_individualEmail($contact);
     $this->_addEmail($contact->id, $email, self::WORK);
     return $contact->id;
 }
开发者ID:JoeMurray,项目名称:civihr,代码行数:26,代码来源:GenerateHRData.php

示例2: updateRecords

 /**
  * Updates contacts affected by the option value passed.
  *
  * @param int $optionValueId
  *   The option value id.
  * @param int $action
  *   The action describing whether prefix/suffix was UPDATED or DELETED.
  *
  * @return bool
  */
 public static function updateRecords(&$optionValueId, $action)
 {
     //finding group name
     $optionValue = new CRM_Core_DAO_OptionValue();
     $optionValue->id = $optionValueId;
     $optionValue->find(TRUE);
     $optionGroup = new CRM_Core_DAO_OptionGroup();
     $optionGroup->id = $optionValue->option_group_id;
     $optionGroup->find(TRUE);
     // group name
     $gName = $optionGroup->name;
     // value
     $value = $optionValue->value;
     // get the proper group name & affected field name
     // todo: this may no longer be needed for individuals - check inputs
     $individuals = array('gender' => 'gender_id', 'individual_prefix' => 'prefix_id', 'individual_suffix' => 'suffix_id', 'communication_style' => 'communication_style_id');
     $contributions = array('payment_instrument' => 'payment_instrument_id');
     $activities = array('activity_type' => 'activity_type_id');
     $participant = array('participant_role' => 'role_id');
     $eventType = array('event_type' => 'event_type_id');
     $aclRole = array('acl_role' => 'acl_role_id');
     $all = array_merge($individuals, $contributions, $activities, $participant, $eventType, $aclRole);
     $fieldName = '';
     foreach ($all as $name => $id) {
         if ($gName == $name) {
             $fieldName = $id;
         }
     }
     if ($fieldName == '') {
         return TRUE;
     }
     if (array_key_exists($gName, $individuals)) {
         $contactDAO = new CRM_Contact_DAO_Contact();
         $contactDAO->{$fieldName} = $value;
         $contactDAO->find();
         while ($contactDAO->fetch()) {
             if ($action == CRM_Core_Action::DELETE) {
                 $contact = new CRM_Contact_DAO_Contact();
                 $contact->id = $contactDAO->id;
                 $contact->find(TRUE);
                 // make sure dates doesn't get reset
                 $contact->birth_date = CRM_Utils_Date::isoToMysql($contact->birth_date);
                 $contact->deceased_date = CRM_Utils_Date::isoToMysql($contact->deceased_date);
                 $contact->{$fieldName} = 'NULL';
                 $contact->save();
             }
         }
         return TRUE;
     }
     if (array_key_exists($gName, $contributions)) {
         $contribution = new CRM_Contribute_DAO_Contribution();
         $contribution->{$fieldName} = $value;
         $contribution->find();
         while ($contribution->fetch()) {
             if ($action == CRM_Core_Action::DELETE) {
                 $contribution->{$fieldName} = 'NULL';
                 $contribution->save();
             }
         }
         return TRUE;
     }
     if (array_key_exists($gName, $activities)) {
         $activity = new CRM_Activity_DAO_Activity();
         $activity->{$fieldName} = $value;
         $activity->find();
         while ($activity->fetch()) {
             $activity->delete();
         }
         return TRUE;
     }
     //delete participant role, type and event type option value
     if (array_key_exists($gName, $participant)) {
         $participantValue = new CRM_Event_DAO_Participant();
         $participantValue->{$fieldName} = $value;
         if ($participantValue->find(TRUE)) {
             return FALSE;
         }
         return TRUE;
     }
     //delete event type option value
     if (array_key_exists($gName, $eventType)) {
         $event = new CRM_Event_DAO_Event();
         $event->{$fieldName} = $value;
         if ($event->find(TRUE)) {
             return FALSE;
         }
         return TRUE;
     }
     //delete acl_role option value
     if (array_key_exists($gName, $aclRole)) {
//.........这里部分代码省略.........
开发者ID:kidaa30,项目名称:yes,代码行数:101,代码来源:OptionValue.php

示例3: contactTrashRestore

 /**
  * Function to set is_delete true or restore deleted contact.
  *
  * @param CRM_Contact_DAO_Contact $contact
  *   Contact DAO object.
  * @param bool $restore
  *   True to set the is_delete = 1 else false to restore deleted contact,
  *   i.e. is_delete = 0
  *
  * @return bool
  */
 public static function contactTrashRestore($contact, $restore = FALSE)
 {
     $updateParams = array('id' => $contact->id, 'is_deleted' => $restore ? 0 : 1);
     CRM_Utils_Hook::pre('update', $contact->contact_type, $contact->id, $updateParams);
     $params = array(1 => array($contact->id, 'Integer'));
     if (!$restore) {
         $query = "DELETE FROM civicrm_uf_match WHERE contact_id = %1";
         CRM_Core_DAO::executeQuery($query, $params);
     }
     $contact->copyValues($updateParams);
     $contact->save();
     CRM_Utils_Hook::post('update', $contact->contact_type, $contact->id, $contact);
     return TRUE;
 }
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:25,代码来源:Contact.php

示例4: updateRecords

 /**
  * updates contacts affected by the option value passed.
  *
  * @param Integer $optionValueId     the option value id.
  * @param int     $action            the action describing whether prefix/suffix was UPDATED or DELETED
  *
  * @return void
  */
 static function updateRecords(&$optionValueId, $action)
 {
     //finding group name
     $optionValue =& new CRM_Core_DAO_OptionValue();
     $optionValue->id = $optionValueId;
     $optionValue->find(true);
     $optionGroup =& new CRM_Core_DAO_OptionGroup();
     $optionGroup->id = $optionValue->option_group_id;
     $optionGroup->find(true);
     $gName = $optionGroup->name;
     //group name
     $value = $optionValue->value;
     //value
     // get the proper group name & affected field name
     $individuals = array('gender' => 'gender_id', 'individual_prefix' => 'prefix_id', 'individual_suffix' => 'suffix_id');
     $contributions = array('payment_instrument' => 'payment_instrument_id');
     $activities = array('activity_type' => 'activity_type_id');
     $participant = array('participant_role' => 'role_id');
     $eventType = array('event_type' => 'event_type_id');
     $aclRole = array('acl_role' => 'acl_role_id');
     $all = array_merge($individuals, $contributions, $activities, $participant, $eventType, $aclRole);
     $fieldName = '';
     foreach ($all as $name => $id) {
         if ($gName == $name) {
             $fieldName = $id;
         }
     }
     if ($fieldName == '') {
         return true;
     }
     if (array_key_exists($gName, $individuals)) {
         require_once 'CRM/Contact/BAO/Contact.php';
         $contactDAO =& new CRM_Contact_DAO_Contact();
         $contactDAO->{$fieldName} = $value;
         $contactDAO->find();
         while ($contactDAO->fetch()) {
             if ($action == CRM_Core_Action::DELETE) {
                 $contact = new CRM_Contact_DAO_Contact();
                 $contact->id = $contactDAO->id;
                 $contact->find(true);
                 // make sure dates doesn't get reset
                 $contact->birth_date = CRM_Utils_Date::isoToMysql($contact->birth_date);
                 $contact->deceased_date = CRM_Utils_Date::isoToMysql($contact->deceased_date);
                 $contact->{$fieldName} = 'NULL';
                 $contact->save();
             }
         }
         return true;
     }
     if (array_key_exists($gName, $contributions)) {
         require_once 'CRM/Contribute/DAO/Contribution.php';
         $contribution =& new CRM_Contribute_DAO_Contribution();
         $contribution->{$fieldName} = $value;
         $contribution->find();
         while ($contribution->fetch()) {
             if ($action == CRM_Core_Action::DELETE) {
                 $contribution->{$fieldName} = 'NULL';
                 $contribution->save();
             }
         }
         return true;
     }
     if (array_key_exists($gName, $activities)) {
         require_once 'CRM/Activity/DAO/Activity.php';
         $activity =& new CRM_Activity_DAO_Activity();
         $activity->{$fieldName} = $value;
         $activity->find();
         while ($activity->fetch()) {
             $activity->delete();
         }
         return true;
     }
     //delete participant role, type and event type option value
     if (array_key_exists($gName, $participant)) {
         require_once 'CRM/Event/DAO/Participant.php';
         $participantValue =& new CRM_Event_DAO_Participant();
         $participantValue->{$fieldName} = $value;
         if ($participantValue->find(true)) {
             return false;
         }
         return true;
     }
     //delete event type option value
     if (array_key_exists($gName, $eventType)) {
         require_once 'CRM/Event/DAO/Event.php';
         $event =& new CRM_Event_DAO_Event();
         $event->{$fieldName} = $value;
         if ($event->find(true)) {
             return false;
         }
         return true;
     }
//.........这里部分代码省略.........
开发者ID:ksecor,项目名称:civicrm,代码行数:101,代码来源:OptionValue.php

示例5: revert


//.........这里部分代码省略.........
                 case 'Insert':
                     if (!isset($deletes[$table])) {
                         $deletes[$table] = array();
                     }
                     $deletes[$table][] = $change['id'];
                     break;
                 case 'Delete':
                 case 'Update':
                     if (!isset($reverts[$table])) {
                         $reverts[$table] = array();
                     }
                     if (!isset($reverts[$table][$change['id']])) {
                         $reverts[$table][$change['id']] = array('log_action' => $change['action']);
                     }
                     $reverts[$table][$change['id']][$change['field']] = $change['from'];
                     break;
             }
         }
     }
     // revert inserts by deleting
     foreach ($deletes as $table => $ids) {
         CRM_Core_DAO::executeQuery("DELETE FROM `{$table}` WHERE id IN (" . implode(', ', array_unique($ids)) . ')');
     }
     // revert updates by updating to previous values
     foreach ($reverts as $table => $row) {
         switch (TRUE) {
             // DAO-based tables
             case in_array($table, array_keys($daos)):
                 require_once str_replace('_', DIRECTORY_SEPARATOR, $daos[$table]) . '.php';
                 eval("\$dao = new {$daos[$table]};");
                 foreach ($row as $id => $changes) {
                     $dao->id = $id;
                     foreach ($changes as $field => $value) {
                         if ($field == 'log_action') {
                             continue;
                         }
                         if (empty($value) and $value !== 0 and $value !== '0') {
                             $value = 'null';
                         }
                         $dao->{$field} = $value;
                     }
                     $changes['log_action'] == 'Delete' ? $dao->insert() : $dao->update();
                     $dao->reset();
                 }
                 break;
                 // custom data tables
             // custom data tables
             case in_array($table, array_keys($ctypes)):
                 foreach ($row as $id => $changes) {
                     $inserts = array('id' => '%1');
                     $updates = array();
                     $params = array(1 => array($id, 'Integer'));
                     $counter = 2;
                     foreach ($changes as $field => $value) {
                         // don’t try reverting a field that’s no longer there
                         if (!isset($ctypes[$table][$field])) {
                             continue;
                         }
                         switch ($ctypes[$table][$field]) {
                             case 'Date':
                                 $value = substr(CRM_Utils_Date::isoToMysql($value), 0, 8);
                                 break;
                             case 'Timestamp':
                                 $value = CRM_Utils_Date::isoToMysql($value);
                                 break;
                         }
                         $inserts[$field] = "%{$counter}";
                         $updates[] = "{$field} = %{$counter}";
                         $params[$counter] = array($value, $ctypes[$table][$field]);
                         $counter++;
                     }
                     if ($changes['log_action'] == 'Delete') {
                         $sql = "INSERT INTO `{$table}` (" . implode(', ', array_keys($inserts)) . ') VALUES (' . implode(', ', $inserts) . ')';
                     } else {
                         $sql = "UPDATE `{$table}` SET " . implode(', ', $updates) . ' WHERE id = %1';
                     }
                     CRM_Core_DAO::executeQuery($sql, $params);
                 }
                 break;
         }
     }
     // CRM-7353: if nothing altered civicrm_contact, touch it; this will
     // make sure there’s an entry in log_civicrm_contact for this revert
     if (empty($diffs['civicrm_contact'])) {
         $query = "\n                SELECT id FROM `{$this->db}`.log_civicrm_contact\n                WHERE log_conn_id = %1 AND log_date BETWEEN DATE_SUB(%2, INTERVAL 10 SECOND) AND DATE_ADD(%2, INTERVAL 10 SECOND)\n                ORDER BY log_date DESC LIMIT 1\n            ";
         $params = array(1 => array($this->log_conn_id, 'Integer'), 2 => array($this->log_date, 'String'));
         $cid = CRM_Core_DAO::singleValueQuery($query, $params);
         if (!$cid) {
             return;
         }
         $dao = new CRM_Contact_DAO_Contact();
         $dao->id = $cid;
         if ($dao->find(TRUE)) {
             // CRM-8102: MySQL can’t parse its own dates
             $dao->birth_date = CRM_Utils_Date::isoToMysql($dao->birth_date);
             $dao->deceased_date = CRM_Utils_Date::isoToMysql($dao->deceased_date);
             $dao->save();
         }
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:Reverter.php

示例6: revert


//.........这里部分代码省略.........
                 case 'Delete':
                 case 'Update':
                     if (!isset($reverts[$table])) {
                         $reverts[$table] = array();
                     }
                     if (!isset($reverts[$table][$change['id']])) {
                         $reverts[$table][$change['id']] = array('log_action' => $change['action']);
                     }
                     $reverts[$table][$change['id']][$change['field']] = $change['from'];
                     break;
             }
         }
     }
     // revert inserts by deleting
     foreach ($deletes as $table => $ids) {
         CRM_Core_DAO::executeQuery("DELETE FROM `{$table}` WHERE id IN (" . implode(', ', array_unique($ids)) . ')');
     }
     // revert updates by updating to previous values
     foreach ($reverts as $table => $row) {
         switch (TRUE) {
             // DAO-based tables
             case ($tableDAO = CRM_Core_DAO_AllCoreTables::getClassForTable($table)) != FALSE:
                 $dao = new $tableDAO();
                 foreach ($row as $id => $changes) {
                     $dao->id = $id;
                     foreach ($changes as $field => $value) {
                         if ($field == 'log_action') {
                             continue;
                         }
                         if (empty($value) and $value !== 0 and $value !== '0') {
                             $value = 'null';
                         }
                         $dao->{$field} = $value;
                     }
                     $changes['log_action'] == 'Delete' ? $dao->insert() : $dao->update();
                     $dao->reset();
                 }
                 break;
                 // custom data tables
             // custom data tables
             case in_array($table, array_keys($ctypes)):
                 foreach ($row as $id => $changes) {
                     $inserts = array('id' => '%1');
                     $updates = array();
                     $params = array(1 => array($id, 'Integer'));
                     $counter = 2;
                     foreach ($changes as $field => $value) {
                         // don’t try reverting a field that’s no longer there
                         if (!isset($ctypes[$table][$field])) {
                             continue;
                         }
                         $fldVal = "%{$counter}";
                         switch ($ctypes[$table][$field]) {
                             case 'Date':
                                 $value = substr(CRM_Utils_Date::isoToMysql($value), 0, 8);
                                 break;
                             case 'Timestamp':
                                 $value = CRM_Utils_Date::isoToMysql($value);
                                 break;
                             case 'Boolean':
                                 if ($value === '') {
                                     $fldVal = 'DEFAULT';
                                 }
                         }
                         $inserts[$field] = "%{$counter}";
                         $updates[] = "{$field} = {$fldVal}";
                         if ($fldVal != 'DEFAULT') {
                             $params[$counter] = array($value, $ctypes[$table][$field]);
                         }
                         $counter++;
                     }
                     if ($changes['log_action'] == 'Delete') {
                         $sql = "INSERT INTO `{$table}` (" . implode(', ', array_keys($inserts)) . ') VALUES (' . implode(', ', $inserts) . ')';
                     } else {
                         $sql = "UPDATE `{$table}` SET " . implode(', ', $updates) . ' WHERE id = %1';
                     }
                     CRM_Core_DAO::executeQuery($sql, $params);
                 }
                 break;
         }
     }
     // CRM-7353: if nothing altered civicrm_contact, touch it; this will
     // make sure there’s an entry in log_civicrm_contact for this revert
     if (empty($diffs['civicrm_contact'])) {
         $query = "\n                SELECT id FROM `{$this->db}`.log_civicrm_contact\n                WHERE log_conn_id = %1 AND log_date BETWEEN DATE_SUB(%2, INTERVAL 10 SECOND) AND DATE_ADD(%2, INTERVAL 10 SECOND)\n                ORDER BY log_date DESC LIMIT 1\n            ";
         $params = array(1 => array($this->log_conn_id, 'String'), 2 => array($this->log_date, 'String'));
         $cid = CRM_Core_DAO::singleValueQuery($query, $params);
         if (!$cid) {
             return;
         }
         $dao = new CRM_Contact_DAO_Contact();
         $dao->id = $cid;
         if ($dao->find(TRUE)) {
             // CRM-8102: MySQL can’t parse its own dates
             $dao->birth_date = CRM_Utils_Date::isoToMysql($dao->birth_date);
             $dao->deceased_date = CRM_Utils_Date::isoToMysql($dao->deceased_date);
             $dao->save();
         }
     }
 }
开发者ID:saurabhbatra96,项目名称:civicrm-core,代码行数:101,代码来源:Reverter.php

示例7: del

 /**
  * Function to delete the relationship
  *
  * @param int $id relationship id
  *
  * @return null
  * @access public
  *
  * @static
  */
 static function del($id)
 {
     // delete from relationship table
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::pre('delete', 'Relationship', $id, CRM_Core_DAO::$_nullArray);
     $relationship =& new CRM_Contact_DAO_Relationship();
     $relationship->id = $id;
     $relationship->find(true);
     //to delete relationship between household and individual
     //or between individual and orgnization
     if ($relationship->relationship_type_id == 4 || $relationship->relationship_type_id == 7) {
         $sharedContact = new CRM_Contact_DAO_Contact();
         $sharedContact->id = $relationship->contact_id_a;
         $sharedContact->find(true);
         if ($relationship->relationship_type_id == 4 && $relationship->contact_id_b == $sharedContact->employer_id) {
             $sharedContact->organization_name = 'NULL';
             $sharedContact->employer_id = 'NULL';
             $sharedContact->save();
         } else {
             if ($sharedContact->mail_to_household_id == $relationship->contact_id_b) {
                 self::deleteSharedAddress($relationship->contact_id_a);
             }
         }
     }
     if (CRM_Core_Permission::access('CiviMember')) {
         // create $params array which isrequired to delete memberships
         // of the related contacts.
         $params = array('relationship_type_id' => "{$relationship->relationship_type_id}_a_b", 'contact_check' => array($relationship->contact_id_b => 1));
         $ids = array();
         // calling relatedMemberships to delete the memberships of
         // related contacts.
         self::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::DELETE);
     }
     $relationship->delete();
     CRM_Core_Session::setStatus(ts('Selected Relationship has been Deleted Successfuly.'));
     CRM_Utils_Hook::post('delete', 'Relationship', $relationship->id, $relationship);
     return $relationship;
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:48,代码来源:Relationship.php


注:本文中的CRM_Contact_DAO_Contact::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。