Proyectos de Subversion LeadersLinked - Services

Rev

Rev 382 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 382 Rev 386
Línea 37... Línea 37...
37
    private function __construct($adapter)
37
    private function __construct($adapter)
38
    {
38
    {
39
        parent::__construct($adapter);
39
        parent::__construct($adapter);
40
    }
40
    }
Línea 41... Línea -...
41
 
-
 
42
    /**
-
 
43
     * Valida y ajusta las fechas de un rango de búsqueda.
-
 
44
     *
-
 
45
     * - Si alguna fecha es `null`, se asigna la fecha actual en formato `YYYY-MM-DD`.
-
 
46
     * - Si la fecha inicial es mayor que la final, se intercambian.
-
 
47
     *
-
 
48
     * @param string|null $initialDate Fecha inicial en formato `YYYY-MM-DD` o `null`.
-
 
49
     * @param string|null $finalDate Fecha final en formato `YYYY-MM-DD` o `null`.
-
 
50
     * @return array Arreglo con las fechas validadas [initialDate, finalDate].
-
 
51
     */
-
 
52
    function validateAndAdjustDates($filter, $initialDate, $finalDate)
-
 
53
    {
-
 
54
        $currentDate = date('Y-m-d'); // Fecha actual en formato YYYY-MM-DD
-
 
55
        $yesterdayDate = date('Y-m-d', strtotime('-1 day')); // Fecha del día anterior
-
 
56
 
-
 
57
        // Asignar la fecha del día anterior si initialDate es nula
-
 
58
        if (empty($initialDate)) {
-
 
59
            $initialDate = $yesterdayDate;
-
 
60
        }
-
 
61
 
-
 
62
        // Asignar la fecha actual si finalDate es nula
-
 
63
        if (empty($finalDate)) {
-
 
64
            $finalDate = $currentDate;
-
 
65
        }
-
 
66
 
-
 
67
        // Convertir las fechas a objetos DateTime para compararlas
-
 
68
        $initialDateObj = new DateTime($initialDate);
-
 
69
        $finalDateObj = new DateTime($finalDate);
-
 
70
 
-
 
71
        // Si la fecha inicial es mayor a la final, intercambiarlas
-
 
72
        if ($initialDateObj > $finalDateObj) {
-
 
73
            list($initialDate, $finalDate) = [$finalDate, $initialDate];
-
 
74
        }
-
 
75
 
-
 
76
        return [$initialDate, $finalDate];
-
 
77
    }
-
 
78
 
-
 
79
    /**
-
 
80
     * Generates a list of dates within a given range and marks whether they exist in a provided list.
-
 
81
     *
-
 
82
     * @param array $datesList An array of dates to check against.
-
 
83
     * @param string $startDate The start date of the range (YYYY-MM-DD).
-
 
84
     * @param string $endDate The end date of the range (YYYY-MM-DD).
-
 
85
     * @return array A list of dictionaries with each date and a flag indicating its presence in the given list.
-
 
86
     */
-
 
87
    function generateDateList($datesList, $startDate, $endDate)
-
 
88
    {
-
 
89
        $result = [];
-
 
90
        $start = new DateTime($startDate);
-
 
91
        $end = new DateTime($endDate);
-
 
92
        $datesLookup = array_flip($datesList); // Convert list to keys for quick lookup
-
 
93
 
-
 
94
        while ($start <= $end) {
-
 
95
            $dateStr = $start->format('Y-m-d');
-
 
96
            $result[] = [
-
 
97
                'date' => $dateStr,
-
 
98
                'flag' => isset($datesLookup[$dateStr]) ? 1 : 0
-
 
99
            ];
-
 
100
            $start->modify('+1 day');
-
 
101
        }
-
 
102
 
-
 
103
        return $result;
-
 
104
    }
-
 
Línea 105... Línea 41...
105
 
41
 
106
 
42
 
107
    /**
43
    /**
108
     *
44
     *
Línea 120... Línea 56...
120
    /**
56
    /**
121
     * 
57
     * 
122
     * @param int $id
58
     * @param int $id
123
     * @return array
59
     * @return array
124
     */
60
     */
125
    public function fetchDaysIntervalsRegisterList($id, $dateInitial, $dateFinal)
61
    public function fetchAccessDayRecordsByDayIntervals($id, $dateInitial, $dateFinal)
126
    {
62
    {
127
        // Crear el objeto de selección
63
        // Crear el objeto de selección
128
        $select = $this->sql->select(self::_TABLE_B);
64
        $select = $this->sql->select(self::_TABLE_B);
Línea 129... Línea 65...
129
 
65
 
Línea 225... Línea 161...
225
    }
161
    }
Línea 226... Línea 162...
226
 
162
 
-
 
163
 
227
 
164
 
228
 
-
 
229
    /**
-
 
230
     *
-
 
231
     * @param int[] $company_ids
-
 
232
     * @return HabitSkill[]
-
 
233
     */
-
 
234
    public function fetchAllTemplateByCompayIds($company_ids)
-
 
235
    {
-
 
236
        $prototype = new HabitSkill();
-
 
237
 
-
 
238
 
165
    /**
239
        $select = $this->sql->select(self::_TABLE);
-
 
240
        $select->where->in('company_id', $company_ids);
166
     * Valida y ajusta las fechas de un rango de búsqueda.
241
        $select->where->equalTo('template', HabitSkill::TEMPLATE_YES);
-
 
242
 
-
 
243
        return $this->executeFetchAllObject($select, $prototype);
-
 
244
    }
167
     *
245
 
-
 
246
    /**
-
 
247
     *
-
 
248
     * @param int $company_id
168
     * - Si alguna fecha es `null`, se asigna la fecha actual en formato `YYYY-MM-DD`.
249
     * @param string $search
169
     * - Si la fecha inicial es mayor que la final, se intercambian.
250
     * @param int $page
170
     *
251
     * @param int $records_per_page
-
 
252
     * @param string $order_field
171
     * @param string|null $initialDate Fecha inicial en formato `YYYY-MM-DD` o `null`.
253
     * @param string $order_direction
172
     * @param string|null $finalDate Fecha final en formato `YYYY-MM-DD` o `null`.
254
     * @return Paginator
173
     * @return array Arreglo con las fechas validadas [initialDate, finalDate].
255
     */
174
     */
256
    public function fetchAllDataTableTemplates($company_id, $search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC')
175
    function validateAndAdjustDates($filter, $initialDate, $finalDate)
Línea -... Línea 176...
-
 
176
    {
257
    {
177
        $currentDate = date('Y-m-d'); // Fecha actual en formato YYYY-MM-DD
258
        $prototype = new HabitSkill();
178
        $yesterdayDate = date('Y-m-d', strtotime('-1 day')); // Fecha del día anterior
259
        $select = $this->sql->select(self::_TABLE);
179
 
260
 
-
 
261
        if ($search) {
-
 
Línea -... Línea 180...
-
 
180
        // Asignar la fecha del día anterior si initialDate es nula
-
 
181
        if (empty($initialDate)) {
-
 
182
            $initialDate = $yesterdayDate;
-
 
183
        }
Línea -... Línea 184...
-
 
184
 
-
 
185
        // Asignar la fecha actual si finalDate es nula
-
 
186
        if (empty($finalDate)) {
Línea 262... Línea 187...
262
            $select->where->like('name', '%' . $search . '%');
187
            $finalDate = $currentDate;
263
        }
-
 
264
        $select->where->equalTo('company_id', $company_id);
188
        }
265
        $select->order($order_field . ' ' . $order_direction);
189
 
266
 
-
 
267
 
-
 
268
 
190
        // Convertir las fechas a objetos DateTime para compararlas
269
        // echo $select->getSqlString($this->adapter->platform); exit;
-
 
270
 
-
 
271
        $hydrator   = new ObjectPropertyHydrator();
-
 
Línea 272... Línea 191...
272
        $resultset  = new HydratingResultSet($hydrator, $prototype);
191
        $initialDateObj = new DateTime($initialDate);
273
 
192
        $finalDateObj = new DateTime($finalDate);
Línea 274... Línea -...
274
        $adapter = new DbSelect($select, $this->sql, $resultset);
-
 
275
        $paginator = new Paginator($adapter);
-
 
276
        $paginator->setItemCountPerPage($records_per_page);
193
 
-
 
194
        // Si la fecha inicial es mayor a la final, intercambiarlas
277
        $paginator->setCurrentPageNumber($page);
195
        if ($initialDateObj > $finalDateObj) {
278
 
-
 
279
 
-
 
280
        return $paginator;
-
 
281
    }
196
            list($initialDate, $finalDate) = [$finalDate, $initialDate];
282
 
197
        }
283
 
198
 
284
 
199
        return [$initialDate, $finalDate];
285
    /**
200
    }
286
     * 
201
 
287
     * @param int $user_id
202
    /**
-
 
203
     * Generates a list of dates within a given range and marks whether they exist in a provided list.
288
     * @param string $search
204
     *
289
     * @param int $page
205
     * @param array $datesList An array of dates to check against.
-
 
206
     * @param string $startDate The start date of the range (YYYY-MM-DD).
Línea 290... Línea 207...
290
     * @param int $records_per_page
207
     * @param string $endDate The end date of the range (YYYY-MM-DD).
-
 
208
     * @return array A list of dictionaries with each date and a flag indicating its presence in the given list.
-
 
209
     */
-
 
210
    function generateDateList($datesList, $startDate, $endDate)
291
     * @param string $order_field
211
    {
-
 
212
        $result = [];
-
 
213
        $start = new DateTime($startDate);
292
     * @param string $order_direction
214
        $end = new DateTime($endDate);
293
     * @return Paginator
-
 
294
     */
-
 
295
    public function fetchAllDataTable($user_id, $search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC')
-
 
296
    {
-
 
297
        $prototype = new HabitSkill();
-
 
298
        $select = $this->sql->select(self::_TABLE);
-
 
299
 
-
 
Línea 300... Línea -...
300
        if ($search) {
-
 
301
            $select->where->like('name', '%' . $search . '%');
-
 
302
        }
-
 
303
        $select->where->equalTo('user_id', $user_id);
-
 
304
        $select->order($order_field . ' ' . $order_direction);
-
 
305
 
-
 
306
        // echo $select->getSqlString($this->adapter->platform); exit;
215
        $datesLookup = array_flip($datesList); // Convert list to keys for quick lookup
307
 
216
 
308
        $hydrator   = new ObjectPropertyHydrator();
-
 
309
        $resultset  = new HydratingResultSet($hydrator, $prototype);
217
        while ($start <= $end) {