public function getValue() { $value = parent::getValue(); if (is_string($value)) { $value = zbase_date_from_format($this->getDateFormat(), $value); } if ($value instanceof \DateTime) { $this->_value = $value->format($this->getDateFormat()); } return $this->_value; }
/** * Schedule a Downtime/Maintenannce * * @return void */ public function scheduleDowntime($data) { $file = $this->maintenanceFile . '_schedule'; if (file_exists($file)) { unlink($file); } if (!empty($data['status'])) { // '2016-08-22T22:00' $format = 'Y-m-d\\TH:i:s'; if (strlen($data['start-datetime']) == 16) { $format = 'Y-m-d\\TH:i'; } $data['start-datetime'] = zbase_date_from_format($format, $data['start-datetime'])->format('Y-m-d H:i:s'); $data['end-datetime'] = zbase_date_from_format($format, $data['end-datetime'])->format('Y-m-d H:i:s'); file_put_contents($file, json_encode($data)); } else { $this->unScheduleDowntime(); } }
/** * Readable DAte * Difference for Humans * @return string */ function zbase_date_human_formatted($time, $format = DATE_FORMAT_DB) { return zbase_date_from_format($format, $time)->format('F d, Y h:i A') . ' [' . zbase_date_human($time) . ']'; }
/** * Filter Query * @param array $filters Array of Filters * @param array $sorting Array of Sorting * @param array $options some options * @return array */ public function queryFilters($filters, $sorting = [], $options = []) { $queryFilters = []; if (!empty($filters)) { /** * run through a given filters, possibly valid query filters */ if (!empty($filters)) { foreach ($filters as $fK => $fV) { if (!empty($fV['eq']) && !empty($fV['eq']['field']) && !empty($fV['eq']['value'])) { if (!preg_match('/' . static::$nodeNamePrefix . '\\./', $fV['eq']['field'])) { $fV['eq']['field'] = static::$nodeNamePrefix . '.' . $fV['eq']['field']; } $queryFilters[$fK] = $fV; } } } $isPublic = !empty($filters['public']) ? true : false; if (!empty($isPublic)) { $queryFilters['status'] = ['eq' => ['field' => static::$nodeNamePrefix . '.status', 'value' => 2]]; } $currentUser = !empty($filters['currentUser']) ? true : false; if (!empty($currentUser)) { $queryFilters['user'] = ['eq' => ['field' => static::$nodeNamePrefix . '.user_id', 'value' => zbase_auth_user()->id()]]; } if (!empty($filters['category'])) { $categoryObject = zbase_entity(static::$nodeNamePrefix . '_category', [], true); /** * We have category as a filter, * Then search for the selected category * @var strings[]|integers[]|EntityInterface[] */ $filterCategories = $filters['category']; /** * We need category Ids To be able to do a cross-table-pivot search * Examine the given filter if its an array of strings or integers or just a string or an integer */ $filterCategoryIds = []; if (is_array($filterCategories)) { foreach ($filterCategories as $filterCategory) { if (!$filterCategory instanceof Interfaces\EntityInterface) { $filterCategory = $categoryObject::searchCategory(trim($filterCategory), $isPublic); } if ($filterCategory instanceof Interfaces\EntityInterface && !$filterCategory->isRoot()) { $filterCategoryIds[] = $filterCategory->id(); continue; } } } else { $filterCategory = $categoryObject::searchCategory(trim($filterCategories), $isPublic); if ($filterCategory instanceof Interfaces\EntityInterface && !$filterCategory->isRoot()) { $filterCategoryIds[] = $filterCategory->id(); } } if (!empty($filterCategoryIds)) { $queryFilters['pivot.category_id'] = ['in' => ['field' => 'pivot.category_id', 'values' => $filterCategoryIds]]; } unset($filters['category']); } if (!empty($this->filterableColumns)) { $processedFilters = []; foreach ($filters as $filterName => $filterValue) { if (empty($filterValue)) { continue; } if (in_array($filterName, $processedFilters)) { continue; } if (array_key_exists($filterName, $this->filterableColumns)) { $column = $this->filterableColumns[$filterName]['column']; $filterType = $this->filterableColumns[$filterName]['filterType']; $options = $this->filterableColumns[$filterName]['options']; $columnType = $this->filterableColumns[$filterName]['type']; if ($filterType == 'between') { $startValue = $filterValue; $endValue = null; if (preg_match('/\\:/', $filterType)) { $filterTypeEx = explode(':', $filterType); if (!empty($filterTypeEx[1])) { $endFilterName = $filterTypeEx[1]; $processedFilters[] = $endFilterName; if (!empty($filters[$endFilterName])) { $endValue = $filters[$endFilterName]; } } } if ($columnType == 'timestamp') { $timestampFormat = zbase_data_get($options, 'timestamp.format', 'Y-m-d'); $startValue = zbase_date_from_format($timestampFormat, $startValue); if ($startValue instanceof \DateTime) { $startValue->hour = 0; $startValue->minute = 0; $startValue->second = 0; } if (empty($endValue)) { $endValue = clone $startValue; $endValue->hour = 23; $endValue->minute = 59; $endValue->second = 59; } else { $endValue = zbase_date_from_format($timestampFormat, $endValue); } /** * Argument is the other end of the between */ $queryFilters[$filterName] = [$filterType => ['field' => static::$nodeNamePrefix . '.' . $column, 'from' => $startValue->format(DATE_FORMAT_DB), 'to' => $endValue->format(DATE_FORMAT_DB)]]; } } else { $queryFilters[$filterName] = [$filterType => ['field' => static::$nodeNamePrefix . '.' . $column, 'value' => $filterValue]]; } $processedFilters[] = $filterName; } } } } return $queryFilters; }
* @license proprietary * @copyright Copyright (c) 2015 ClaremontDesign/MadLabs-Dx * @version 0.0.0.1 * @since Aug 22, 2016 8:29:03 PM * @file maintenance-notice.blade.php * @project Zbase * @package Expression package is undefined on line 14, column 15 in Templates/Scripting/EmptyPHP.php. */ if (zbase()->system()->hasScheduledDowntime() && !zbase()->system()->inMaintenance()) { ?> <?php $details = zbase()->system()->scheduledDowntimeDetails(); ?> <div class="alert alert-warning"> <h3>Temporary Downtime Notice.</h3> <p> <?php $message = null; if (!empty($details['maintenance-message'])) { $message = $details['maintenance-message']; } if (!empty($details['start-datetime'])) { $startTime = zbase_date_from_format('Y-m-d H:i:s', $details['start-datetime']); $endTime = zbase_date_from_format('Y-m-d H:i:s', $details['end-datetime']); echo str_replace(array('{START_TIME}', '{END_TIME}'), array('<strong>' . $startTime->format('F d, Y h:i A') . '</strong>', '<strong>' . $endTime->format('F d, Y h:i A') . '</strong>'), nl2br($message)); } ?> </p> </div> <?php }