Revize 18ac9009
Přidáno uživatelem Ondřej Fibich před asi 9 roky(ů)
application/models/email_queue.php | ||
---|---|---|
* @property string $body
|
||
* @property integer $state
|
||
* @property timestamp $access_time
|
||
* @property string $hash
|
||
*/
|
||
class Email_queue_Model extends ORM
|
||
{
|
||
... | ... | |
/**
|
||
* Unsuccessfully sent e-mail, almost same as new
|
||
*/
|
||
const STATE_FAIL = 2;
|
||
const STATE_FAIL = 2;
|
||
|
||
/**
|
||
* E-mail has been read by recipient
|
||
*/
|
||
const STATE_READ = 3;
|
||
|
||
/**
|
||
* Returns current email queue, by default 10 e-mails to send
|
||
... | ... | |
*/
|
||
public function get_current_queue($count = 10)
|
||
{
|
||
return $this->where('state <> ',self::STATE_OK)
|
||
return $this
|
||
->in('state',
|
||
array(
|
||
self::STATE_NEW,
|
||
self::STATE_FAIL
|
||
)
|
||
)
|
||
->orderby('access_time')
|
||
->limit($count,0)
|
||
->find_all();
|
||
... | ... | |
$order_by = 'id', $order_by_direction = 'ASC', $filter_sql='')
|
||
{
|
||
// args
|
||
$args = array(Contact_Model::TYPE_EMAIL, Contact_Model::TYPE_EMAIL, self::STATE_OK);
|
||
$args = array(Contact_Model::TYPE_EMAIL, Contact_Model::TYPE_EMAIL, self::STATE_OK, self::STATE_READ);
|
||
|
||
// sql body
|
||
$body = "SELECT eq.id, eq.from, eq.to, eq.subject, eq.state, eq.access_time,
|
||
... | ... | |
LEFT JOIN contacts tc ON eq.to = tc.value AND tc.type = ?
|
||
LEFT JOIN users_contacts tuc ON tc.id = tuc.contact_id
|
||
LEFT JOIN users tu ON tuc.user_id = tu.id
|
||
WHERE eq.state = ?
|
||
GROUP BY eq.id";
|
||
WHERE eq.state = ? OR eq.state = ? ";
|
||
|
||
// filter
|
||
if (empty($filter_sql))
|
||
{
|
||
return $this->db->query("
|
||
$body
|
||
GROUP BY eq.id
|
||
ORDER BY ".$this->db->escape_column($order_by)." $order_by_direction
|
||
LIMIT " . intval($limit_from) . "," . intval($limit_results) . "
|
||
", $args);
|
||
... | ... | |
return $this->db->query("
|
||
SELECT COUNT(*) AS total
|
||
FROM email_queues eq
|
||
WHERE eq.state = ?
|
||
", self::STATE_OK)->current()->total;
|
||
WHERE eq.state = ? OR eq.state = ?
|
||
", self::STATE_OK, self::STATE_READ)->current()->total;
|
||
}
|
||
|
||
// filter
|
||
... | ... | |
LEFT JOIN contacts tc ON eq.to = tc.value AND tc.type = ?
|
||
LEFT JOIN users_contacts tuc ON tc.id = tuc.contact_id
|
||
LEFT JOIN users tu ON tuc.user_id = tu.id
|
||
WHERE eq.state = ?
|
||
GROUP BY eq.id
|
||
WHERE eq.state = ? OR eq.state = ?
|
||
$having
|
||
", array
|
||
(
|
||
Contact_Model::TYPE_EMAIL, Contact_Model::TYPE_EMAIL,
|
||
self::STATE_OK
|
||
self::STATE_OK, self::STATE_READ
|
||
))->count();
|
||
}
|
||
|
||
... | ... | |
LEFT JOIN contacts tc ON eq.to = tc.value AND tc.type = ?
|
||
LEFT JOIN users_contacts tuc ON tc.id = tuc.contact_id
|
||
LEFT JOIN users tu ON tuc.user_id = tu.id
|
||
WHERE eq.state = ?
|
||
GROUP BY eq.id
|
||
WHERE eq.state = ? OR eq.state = ?
|
||
$having
|
||
) eq
|
||
", Contact_Model::TYPE_EMAIL, Contact_Model::TYPE_EMAIL, self::STATE_OK);
|
||
", Contact_Model::TYPE_EMAIL, Contact_Model::TYPE_EMAIL, self::STATE_OK, self::STATE_READ);
|
||
}
|
||
|
||
/**
|
||
... | ... | |
LEFT JOIN contacts tc ON eq.to = tc.value AND tc.type = ?
|
||
LEFT JOIN users_contacts tuc ON tc.id = tuc.contact_id
|
||
LEFT JOIN users tu ON tuc.user_id = tu.id
|
||
WHERE eq.state = ?
|
||
GROUP BY eq.id
|
||
WHERE eq.state = ? OR eq.state = ?
|
||
$having
|
||
", array
|
||
(
|
||
Contact_Model::TYPE_EMAIL, Contact_Model::TYPE_EMAIL,
|
||
self::STATE_OK
|
||
self::STATE_OK, self::STATE_READ
|
||
))->as_array();
|
||
|
||
$pids = array();
|
||
... | ... | |
LEFT JOIN contacts tc ON eq.to = tc.value AND tc.type = ?
|
||
LEFT JOIN users_contacts tuc ON tc.id = tuc.contact_id
|
||
LEFT JOIN users tu ON tuc.user_id = tu.id
|
||
WHERE eq.state <> ?
|
||
GROUP BY eq.id
|
||
WHERE eq.state <> ? AND eq.state <> ?
|
||
$having
|
||
ORDER BY ".$this->db->escape_column($order_by)." $order_by_direction
|
||
LIMIT " . intval($limit_from) . "," . intval($limit_results) . "
|
||
", Contact_Model::TYPE_EMAIL, Contact_Model::TYPE_EMAIL, self::STATE_OK);
|
||
", Contact_Model::TYPE_EMAIL, Contact_Model::TYPE_EMAIL, self::STATE_OK, self::STATE_READ);
|
||
}
|
||
|
||
/**
|
||
... | ... | |
return $this->db->query("
|
||
SELECT COUNT(*) AS total
|
||
FROM email_queues eq
|
||
WHERE eq.state <> ?
|
||
", self::STATE_OK)->current()->total;
|
||
WHERE eq.state <> ? AND eq.state <> ?
|
||
", self::STATE_OK, self::STATE_READ)->current()->total;
|
||
}
|
||
|
||
// filter
|
||
... | ... | |
LEFT JOIN contacts tc ON eq.to = tc.value AND tc.type = ?
|
||
LEFT JOIN users_contacts tuc ON tc.id = tuc.contact_id
|
||
LEFT JOIN users tu ON tuc.user_id = tu.id
|
||
WHERE eq.state <> ?
|
||
GROUP BY eq.id
|
||
WHERE eq.state <> ? AND eq.state <> ?
|
||
$having
|
||
", array
|
||
(
|
||
Contact_Model::TYPE_EMAIL, Contact_Model::TYPE_EMAIL,
|
||
self::STATE_OK
|
||
self::STATE_OK, self::STATE_READ
|
||
))->count();
|
||
}
|
||
|
Také k dispozici: Unified diff
Fix merge issue that removed all staff from developer branch :-).