1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22:
23: class cApiUserPasswordRequestCollection extends ItemCollection {
24:
25: 26: 27: 28: 29: 30: 31:
32: public function __construct($where = false) {
33: global $cfg;
34: parent::__construct($cfg['tab']['user_pw_request'], 'id_pwreq');
35: $this->_setItemClass('cApiUserPasswordRequest');
36: if ($where !== false) {
37: $this->select($where);
38: }
39: }
40:
41: 42: 43: 44: 45: 46:
47: public function createNewItem($data = NULL) {
48: $item = parent::createNewItem($data);
49:
50:
51:
52: if (false === ($expiration = getEffectiveSetting('pw_request', 'user_password_reset_expiration'))
53: || 0 === strlen($expiration)) {
54: $expiration = '+4 hour';
55: }
56: $time = new DateTime('+' . $expiration, new DateTimeZone('UTC'));
57: $item->set('expiration', $this->escape($time->format('Y-m-d H:i:s')));
58:
59: return $item;
60: }
61:
62: 63: 64: 65: 66: 67:
68: public function deleteByUserId($userid) {
69: $result = $this->deleteBy('user_id', $userid);
70: return ($result > 0) ? true : false;
71: }
72:
73: 74: 75: 76: 77: 78:
79: public function deleteByToken($token) {
80: $result = $this->deleteBy('validation_token', $token);
81: return ($result > 0) ? true : false;
82: }
83:
84: 85: 86: 87: 88: 89: 90:
91: public function fetchAvailableRequests($userid = false, $orderBy = 'id_pwreq ASC') {
92: $requests = array();
93:
94: if (false === $userid) {
95: $this->select('', '', $this->escape($orderBy));
96: } else {
97: $this->select('user_id = \'' . $this->escape($userid) . '\'', '', $this->escape($orderBy));
98: }
99: while (($oItem = $this->next()) !== false) {
100: $requests[] = clone $oItem;
101: }
102:
103: return $requests;
104: }
105:
106: 107: 108: 109: 110:
111: public function fetchCurrentRequests($userid = false) {
112: $requests = array();
113:
114: $now = new DateTime('now', new DateTimeZone('UTC'));
115: $this->select('expiration > \'' . $this->escape($now->format('Y-m-d H:i:s')) . '\'');
116: while (($oItem = $this->next()) !== false) {
117: if (false === $userid) {
118: $requests[] = clone $oItem;
119: } elseif ($oItem->get('user_id') === $userid) {
120: $requests[] = clone $oItem;
121: }
122: }
123:
124: return $requests;
125: }
126: }
127:
128: 129: 130: 131: 132: 133:
134: class cApiUserPasswordRequest extends Item {
135: 136: 137: 138: 139:
140: public function __construct($mId = false) {
141: global $cfg;
142: parent::__construct($cfg['tab']['user_pw_request'], 'id_pwreq');
143: $this->setFilters(array(), array());
144: if ($mId !== false) {
145: $this->loadByPrimaryKey($mId);
146: }
147: }
148: }
149: