(NFC) (dev/core#878) Simplify copyright header (CRM/*)
[civicrm-core.git] / CRM / Contact / Form / Edit / Lock.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Auxiliary class to provide support for locking (and ignoring locks on) contact records.
20 */
21 class CRM_Contact_Form_Edit_Lock {
22
23 /**
24 * Build the form object.
25 *
26 * @param CRM_Core_Form $form
27 * Form object.
28 */
29 public static function buildQuickForm(&$form) {
30 $form->addField('modified_date', ['type' => 'hidden', 'id' => 'modified_date', 'label' => '']);
31 }
32
33 /**
34 * Ensure that modified_date has not changed in the underlying DB.
35 *
36 * @param array $fields
37 * The input form values.
38 * @param array $files
39 * The uploaded files if any.
40 * @param int $contactID
41 *
42 * @return bool|array
43 * true if no errors, else array of errors
44 */
45 public static function formRule($fields, $files, $contactID = NULL) {
46 $errors = [];
47
48 $timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
49 if ($fields['modified_date'] != $timestamps['modified_date']) {
50 // Inline buttons generated via JS
51 $open = sprintf("<span id='update_modified_date' data:latest_modified_date='%s'>", $timestamps['modified_date']);
52 $close = "</span>";
53 $errors['modified_date'] = $open . ts('This record was modified by another user!') . $close;
54 }
55
56 return empty($errors) ? TRUE : $errors;
57 }
58
59 }