GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gv-collection-entry-sort.php
Go to the documentation of this file.
1 <?php
2 namespace GV;
3 
4 /** If this file is called directly, abort. */
5 if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6  die();
7 }
8 
9 /**
10  * Entry sorting.
11  */
12 class Entry_Sort {
13 
14  /**
15  * @var string An enum of sorts, sort direction identifier - ascending.
16  */
17  const ASC = 'ASC';
18 
19  /**
20  * @var string An enum of sorts, sort direction identifier - descending.
21  */
22  const DESC = 'DESC';
23 
24  /**
25  * @var string An enum of sorts, sort direction identifier - random.
26  */
27  const RAND = 'RAND';
28 
29  /**
30  * @var string Numeric sort mode.
31  */
32  const NUMERIC = 'NUMERIC';
33 
34  /**
35  * @var string Alpabetic sort mode.
36  */
37  const ALPHA = 'ALPHA';
38 
39  /**
40  * @var \GV\Field The field that this sort is for.
41  */
42  public $field;
43 
44  /**
45  * @var string The direction (see self::ASC, self::DESC).
46  */
47  public $direction;
48 
49  /**
50  * @var string The sort mode (see self::NUMERIC, self::ALPHA).
51  */
52  public $mode;
53 
54  /**
55  * Instantiate a sort for a field.
56  *
57  * @param \GV\Field $field The field we're sorting by.
58  * @param string $direction The direction of this sort (\GV\Entry_Sort::ASC, \GV\Entry_Sort::DESC, etc.). Default: self::ASC.
59  * @param string $mode The sort mode (self::NUMERIC). Default: self::ALPHA.
60  *
61  * @api
62  * @since 2.0
63  *
64  * @return \GV\Entry_Sort An instance of this class, pass to \GV\Entry_Collection::sort()
65  */
66  public function __construct( \GV\Field $field, $direction = self::ASC, $mode = self::ALPHA ) {
67  $this->field = $field;
68  $this->direction = $direction;
69  $this->mode = $mode;
70  }
71 
72  /**
73  * Return search_criteria-compatible array.
74  *
75  * @return array [`key`, `direction`, `is_numeric`]
76  */
77  public function to_sorting() {
78  if ( $this->field ) {
79  return array(
80  'key' => $this->field->ID,
81  'direction' => $this->direction ? : self::ASC,
82  'is_numeric' => self::ALPHA ? true : false,
83  );
84  }
85  return array();
86  }
87 }
__construct(\GV\Field $field, $direction=self::ASC, $mode=self::ALPHA)
Instantiate a sort for a field.
to_sorting()
Return search_criteria-compatible array.
If this file is called directly, abort.
If this file is called directly, abort.
$direction
$mode
$field