Skip to content

Commit

Permalink
Set fetch order during query
Browse files Browse the repository at this point in the history
  • Loading branch information
Max13 committed Nov 2, 2020
1 parent 230e504 commit cb43ff2
Showing 1 changed file with 68 additions and 4 deletions.
72 changes: 68 additions & 4 deletions src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class Query {
/** @var int $fetch_flags */
protected $fetch_flags = true;

/** @var int $fetch_order */
protected $fetch_order;

/** @var string $date_format */
protected $date_format;

Expand All @@ -75,6 +78,12 @@ public function __construct(Client $client, $charset = 'UTF-8') {

if(ClientManager::get('options.fetch') === IMAP::FT_PEEK) $this->leaveUnread();

if (ClientManager::get('options.fetch_order') === 'desc') {
$this->fetch_order = 'desc';
} else {
$this->fetch_order = 'asc';
}

$this->date_format = ClientManager::get('date_format', 'd M y');

$this->charset = $charset;
Expand Down Expand Up @@ -193,9 +202,7 @@ public function get() {

$messages->total($available_messages_count);

$options = ClientManager::get('options');

if(strtolower($options['fetch_order']) === 'desc'){
if ($this->fetch_order === 'desc') {
$available_messages = $available_messages->reverse();
}

Expand Down Expand Up @@ -468,4 +475,61 @@ public function setFetchFlags($fetch_flags) {
$this->fetch_flags = $fetch_flags;
return $this;
}
}

/**
* @param string $fetch_order
* @return Query
*/
public function setFetchOrder($fetch_order) {
$fetch_order = strtolower($fetch_order);

if (in_array($fetch_order, ['asc', 'desc'])) {
$this->fetch_order = $fetch_order;
}

return $this;
}

/**
* @param string $fetch_order
* @return Query
*/
public function fetchOrder($fetch_order) {
return $this->setFetchOrder($fetch_order);
}

/**
* @return string
*/
public function getFetchOrder() {
return $this->fetch_order;
}

/**
* @return Query
*/
public function setFetchOrderAsc() {
return $this->setFetchOrder('asc');
}

/**
* @return Query
*/
public function fetchOrderAsc($fetch_order) {
return $this->setFetchOrderAsc();
}

/**
* @return Query
*/
public function setFetchOrderDesc() {
return $this->setFetchOrder('desc');
}

/**
* @return Query
*/
public function fetchOrderDesc($fetch_order) {
return $this->setFetchOrderDesc();
}
}

0 comments on commit cb43ff2

Please sign in to comment.