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