public function scaffoldFormField($title = null, $params = null)
 {
     $field = DateField::create($this->name, $title);
     // Show formatting hints for better usability
     $field->setDescription(sprintf(_t('FormField.Example', 'e.g. %s', 'Example format'), Convert::raw2xml(Zend_Date::now()->toString($field->getConfig('dateformat')))));
     $field->setAttribute('placeholder', $field->getConfig('dateformat'));
     return $field;
 }
 /**
  * @param array $filters
  *
  * @return array
  */
 protected function getData($filters = array())
 {
     $items = array();
     $folder = null;
     if (isset($filters['folder'])) {
         $folder = $filters['folder'];
     }
     $folder = $this->getFolder($folder);
     $count = 0;
     if ($folder->hasChildren()) {
         /** @var File[]|SS_List $files */
         $files = $folder->myChildren();
         if (isset($filters['name'])) {
             $files = $files->filterAny(array('Name:PartialMatch' => $filters['name'], 'Title:PartialMatch' => $filters['name']));
         }
         if (!empty($params['created_from'])) {
             $fromDate = new DateField(null, null, $params['created_from']);
             $files = $files->filter("Created:GreaterThanOrEqual", $fromDate->dataValue() . ' 00:00:00');
         }
         if (!empty($params['created_to'])) {
             $toDate = new DateField(null, null, $params['created_to']);
             $files = $files->filter("Created:LessThanOrEqual", $toDate->dataValue() . ' 23:59:59');
         }
         $files = $files->sort('(CASE WHEN "File"."ClassName" = \'Folder\' THEN 0 ELSE 1 END), "Name"');
         $count = $files->count();
         if (isset($filters['page']) && isset($filters['limit'])) {
             $page = $filters['page'];
             $limit = $filters['limit'];
             $offset = ($page - 1) * $limit;
             $files = $files->limit($limit, $offset);
         }
         foreach ($files as $file) {
             $items[] = $this->getObjectFromData($file);
         }
     }
     return array("items" => $items, "count" => $count);
 }
 public function validate($validator)
 {
     $dateValid = $this->dateField->validate($validator);
     $timeValid = $this->timeField->validate($validator);
     return $dateValid && $timeValid;
 }
 /**
  * Returns the files and subfolders contained in the currently selected folder,
  * defaulting to the root node. Doubles as search results, if any search parameters
  * are set through {@link SearchForm()}.
  *
  * @param array $params Unsanitised request parameters
  * @return DataList
  */
 protected function getList($params = array())
 {
     $context = $this->getSearchContext();
     // Overwrite name filter to search both Name and Title attributes
     $context->removeFilterByName('Name');
     // Lazy loaded list. Allows adding new filters through SearchContext.
     /** @var DataList $list */
     $list = $context->getResults($params);
     // Re-add previously removed "Name" filter as combined filter
     // TODO Replace with composite SearchFilter once that API exists
     if (!empty($params['Name'])) {
         $list = $list->filterAny(array('Name:PartialMatch' => $params['Name'], 'Title:PartialMatch' => $params['Name']));
     }
     // Optionally limit search to a folder (non-recursive)
     if (!empty($params['ParentID']) && is_numeric($params['ParentID'])) {
         $list = $list->filter('ParentID', $params['ParentID']);
     }
     // Date filtering
     if (!empty($params['CreatedFrom'])) {
         $fromDate = new DateField(null, null, $params['CreatedFrom']);
         $list = $list->filter("Created:GreaterThanOrEqual", $fromDate->dataValue() . ' 00:00:00');
     }
     if (!empty($params['CreatedTo'])) {
         $toDate = new DateField(null, null, $params['CreatedTo']);
         $list = $list->filter("Created:LessThanOrEqual", $toDate->dataValue() . ' 23:59:59');
     }
     // Categories
     if (!empty($filters['AppCategory']) && !empty(File::config()->app_categories[$filters['AppCategory']])) {
         $extensions = File::config()->app_categories[$filters['AppCategory']];
         $list = $list->filter('Name:PartialMatch', $extensions);
     }
     // Sort folders first
     $list = $list->sort('(CASE WHEN "File"."ClassName" = \'Folder\' THEN 0 ELSE 1 END), "Name"');
     // Pagination
     if (isset($filters['page']) && isset($filters['limit'])) {
         $page = $filters['page'];
         $limit = $filters['limit'];
         $offset = ($page - 1) * $limit;
         $list = $list->limit($limit, $offset);
     }
     // Access checks
     $list = $list->filterByCallback(function (File $file) {
         return $file->canView();
     });
     return $list;
 }
 /**
  * Note: This is mostly tested for legacy reasons
  */
 public function testMDYFormat()
 {
     $dateField = new DateField('Date', 'Date');
     $dateField->setConfig('dateformat', 'd/M/Y');
     $dateField->setValue('31/03/2003');
     $this->assertEquals($dateField->dataValue(), '2003-03-31', "We get MM-DD-YYYY format as the data value for YYYY-MM-DD input value");
     $dateField2 = new DateField('Date', 'Date');
     $dateField2->setConfig('dateformat', 'd/M/Y');
     $dateField2->setValue('04/3/03');
     $this->assertEquals($dateField2->dataValue(), '2003-03-04', "Even if input value hasn't got leading 0's in it we still get the correct data value");
 }
 /**
  * @param array $filters
  *
  * @return array
  */
 protected function getData($filters = array())
 {
     $items = array();
     $files = null;
     if (!empty($filters['folder']) && isset($filters['onlySearchInFolder']) && $filters['onlySearchInFolder'] == '1' || empty($filters["name"]) && empty($filters["type"]) && empty($filters["createdFrom"]) && empty($filters["createdTo"])) {
         $folder = null;
         if (isset($filters['folder'])) {
             $folder = $filters['folder'];
         }
         $folder = $this->getFolder($folder);
         if ($folder && $folder->hasChildren()) {
             // When there's a folder with stuff in it.
             /** @var File[]|SS_List $files */
             $files = $folder->myChildren();
         } else {
             if ($folder && !$folder->hasChildren()) {
                 // When there's an empty folder
                 $files = array();
             } else {
                 // When there's no folder (we're at the top level).
                 $files = File::get()->filter('ParentID', 0);
             }
         }
     } else {
         $files = File::get();
     }
     $count = 0;
     if ($files) {
         if (!empty($filters['name'])) {
             $files = $files->filterAny(array('Name:PartialMatch' => $filters['name'], 'Title:PartialMatch' => $filters['name']));
         }
         if (!empty($filters['createdFrom'])) {
             $fromDate = new DateField(null, null, $filters['createdFrom']);
             $files = $files->filter("Created:GreaterThanOrEqual", $fromDate->dataValue() . ' 00:00:00');
         }
         if (!empty($filters['createdTo'])) {
             $toDate = new DateField(null, null, $filters['createdTo']);
             $files = $files->filter("Created:LessThanOrEqual", $toDate->dataValue() . ' 23:59:59');
         }
         if (!empty($filters['type']) && !empty(File::config()->app_categories[$filters['type']])) {
             $extensions = File::config()->app_categories[$filters['type']];
             $files = $files->filter('Name:PartialMatch', $extensions);
         }
         $files = $files->sort('(CASE WHEN "File"."ClassName" = \'Folder\' THEN 0 ELSE 1 END), "Name"');
         $count = $files->count();
         if (isset($filters['page']) && isset($filters['limit'])) {
             $page = $filters['page'];
             $limit = $filters['limit'];
             $offset = ($page - 1) * $limit;
             $files = $files->limit($limit, $offset);
         }
         foreach ($files as $file) {
             $items[] = $this->getObjectFromData($file);
         }
     }
     return array("items" => $items, "count" => $count);
 }