7
7
8
8
class CheckboxController extends BaseController
9
9
{
10
- private const regexCheckbox = '/\[[x, ]\]/m ' ;
10
+ /*
11
+ # must match
12
+ + [x] 2
13
+ * [ ] 3
14
+ > - [ ] 1
15
+ + [x] 2
16
+ * [ ] 3
17
+ > > * * [ ] 3
18
+ > * > * * [ ] 3
19
+ [ ] test 8
20
+
21
+ # must not match:
22
+
23
+ - [x]1
24
+ + [ ]
25
+ test [x]
26
+ test [x]
27
+ [] test 3
28
+ [a] test
29
+ [x](www.google.de) test4
30
+ */
31
+
32
+ private const regexCheckbox = '/^([+,\-,*,>, ] )*(\[[x, ]\] )/m ' ;
11
33
12
34
private function findCheckBox ($ text , $ number , &$ offset )
13
35
{
@@ -17,7 +39,9 @@ private function findCheckBox($text, $number, &$offset)
17
39
if ($ offset >= $ number ) {
18
40
return array (
19
41
'success ' => true ,
20
- 'offset ' => $ matches [0 ][$ count - $ offset + $ number - 1 ][1 ] + 1
42
+ 'offset ' => end ($ matches ) // the actual box [ ]/[x]
43
+ [$ count - $ offset + $ number - 1 ] // the requested checkbox
44
+ [1 ] + 1 // the offset to the checkbox content
21
45
);
22
46
}
23
47
return array ('success ' => false );
@@ -35,69 +59,71 @@ private function togglechar(&$string, $offset)
35
59
public function toggle ()
36
60
{
37
61
$ values = $ this ->request ->getJson ();
38
-
39
- $ foundCheckboxes = 0 ;
40
- $ number = intval ($ values ['number ' ]);
41
62
$ taskId = $ values ['task_id ' ];
42
63
43
64
if (isset ($ taskId )) {
44
65
$ task = $ this ->taskFinderModel ->getById ($ taskId );
45
66
46
- $ text = $ task ['description ' ];
47
- $ result = $ this ->findCheckBox ($ text , $ number , $ foundCheckboxes );
48
- if ($ result ['success ' ]) {
49
- $ this ->togglechar ($ text , $ result ['offset ' ]);
50
- $ task ['description ' ] = $ text ;
51
- $ this ->taskModificationModel ->update ($ task );
52
- return ;
53
- }
67
+ if ($ task ) {
68
+ $ foundCheckboxes = 0 ;
69
+ $ number = intval ($ values ['number ' ]);
54
70
55
- if (isset ($ this ->container ["definitionOfDoneModel " ])) {
56
- foreach ($ this ->definitionOfDoneModel ->getAll ($ taskId ) as $ subtask ) {
57
- $ dod = $ this ->definitionOfDoneModel ->getById ($ subtask ['id ' ]);
71
+ $ text = $ task ['description ' ];
72
+ $ result = $ this ->findCheckBox ($ text , $ number , $ foundCheckboxes );
73
+ if ($ result ['success ' ]) {
74
+ $ this ->togglechar ($ text , $ result ['offset ' ]);
75
+ $ task ['description ' ] = $ text ;
76
+ $ this ->taskModificationModel ->update ($ task );
77
+ return ;
78
+ }
58
79
59
- $ result = $ this ->findCheckBox ($ dod ['title ' ], $ number , $ foundCheckboxes );
60
- if ($ result ['success ' ]) {
61
- $ this ->togglechar ($ dod ['title ' ], $ result ['offset ' ]);
62
- $ this ->definitionOfDoneModel ->save ($ dod );
63
- return ;
80
+ if (isset ($ this ->container ["definitionOfDoneModel " ])) {
81
+ foreach ($ this ->definitionOfDoneModel ->getAll ($ taskId ) as $ subtask ) {
82
+ $ dod = $ this ->definitionOfDoneModel ->getById ($ subtask ['id ' ]);
83
+
84
+ $ result = $ this ->findCheckBox ($ dod ['title ' ], $ number , $ foundCheckboxes );
85
+ if ($ result ['success ' ]) {
86
+ $ this ->togglechar ($ dod ['title ' ], $ result ['offset ' ]);
87
+ $ this ->definitionOfDoneModel ->save ($ dod );
88
+ return ;
89
+ }
90
+
91
+ $ result = $ this ->findCheckBox ($ dod ['text ' ], $ number , $ foundCheckboxes );
92
+ if ($ result ['success ' ]) {
93
+ $ this ->togglechar ($ dod ['text ' ], $ result ['offset ' ]);
94
+ $ this ->definitionOfDoneModel ->save ($ dod );
95
+ return ;
96
+ }
64
97
}
98
+ }
65
99
66
- $ result = $ this ->findCheckBox ($ dod ['text ' ], $ number , $ foundCheckboxes );
67
- if ($ result ['success ' ]) {
68
- $ this ->togglechar ($ dod ['text ' ], $ result ['offset ' ]);
69
- $ this ->definitionOfDoneModel ->save ($ dod );
70
- return ;
100
+ if (isset ($ this ->container ["subtaskResultModel " ])) {
101
+ foreach ($ this ->subtaskModel ->getAll ($ taskId ) as $ subtask ) {
102
+ $ text = $ this ->subtaskResultModel ->getById ($ subtask ['id ' ]);
103
+ $ result = $ this ->findCheckBox ($ text , $ number , $ foundCheckboxes );
104
+ if ($ result ['success ' ]) {
105
+ $ this ->togglechar ($ text , $ result ['offset ' ]);
106
+ $ this ->subtaskResultModel ->Save ($ subtask ['id ' ], $ text );
107
+ return ;
108
+ }
71
109
}
72
110
}
73
- }
74
111
75
- if (isset ($ this ->container ["subtaskResultModel " ])) {
76
- foreach ($ this ->subtaskModel ->getAll ($ taskId ) as $ subtask ) {
77
- $ text = $ this ->subtaskResultModel ->getById ($ subtask ['id ' ]);
112
+ $ commentSortingDirection = $ this ->userMetadataCacheDecorator ->get (UserMetadataModel::KEY_COMMENT_SORTING_DIRECTION , 'ASC ' );
113
+
114
+ foreach ($ this ->commentModel ->getAll ($ taskId , $ commentSortingDirection ) as $ comment ) {
115
+ $ text = $ comment ['comment ' ];
116
+
78
117
$ result = $ this ->findCheckBox ($ text , $ number , $ foundCheckboxes );
118
+
79
119
if ($ result ['success ' ]) {
80
120
$ this ->togglechar ($ text , $ result ['offset ' ]);
81
- $ this ->subtaskResultModel ->Save ($ subtask ['id ' ], $ text );
121
+ $ comment ['comment ' ] = $ text ;
122
+ $ this ->commentModel ->update ($ comment );
82
123
return ;
83
124
}
84
125
}
85
126
}
86
-
87
- $ commentSortingDirection = $ this ->userMetadataCacheDecorator ->get (UserMetadataModel::KEY_COMMENT_SORTING_DIRECTION , 'ASC ' );
88
-
89
- foreach ($ this ->commentModel ->getAll ($ taskId , $ commentSortingDirection ) as $ comment ) {
90
- $ text = $ comment ['comment ' ];
91
-
92
- $ result = $ this ->findCheckBox ($ text , $ number , $ foundCheckboxes );
93
-
94
- if ($ result ['success ' ]) {
95
- $ this ->togglechar ($ text , $ result ['offset ' ]);
96
- $ comment ['comment ' ] = $ text ;
97
- $ this ->commentModel ->update ($ comment );
98
- return ;
99
- }
100
- }
101
127
}
102
128
}
103
129
}
0 commit comments