1 | <?php |
||
39 | class BillImportForm extends \yii\base\Model |
||
40 | { |
||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | public $data; |
||
45 | /** |
||
46 | * @var array Array of possible bill types. |
||
47 | * Key - full bill type |
||
48 | * Value - bill type title |
||
49 | */ |
||
50 | public $billTypes = []; |
||
51 | /** |
||
52 | * @var array map to find client id by login. |
||
53 | * Key - login |
||
54 | * Value - id |
||
55 | */ |
||
56 | private $clientsMap = []; |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function attributes() |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function attributeLabels() |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | public function rules() |
||
85 | |||
86 | /** |
||
87 | * Parses [[data]] attribute and creates [[Bill]] model from each line. |
||
88 | * |
||
89 | * @return Bill[]|false Array of [[Bill]] models on success or `false` on parsing error |
||
90 | */ |
||
91 | public function parse() |
||
128 | |||
129 | /** |
||
130 | * Splits $line for chunks by `;` character. |
||
131 | * Ensures there are exactly 6 chunks. |
||
132 | * Trims each value before return. |
||
133 | * |
||
134 | * @param string $line to be exploded |
||
135 | * @return array |
||
136 | */ |
||
137 | protected function splitLine($line) |
||
146 | |||
147 | /** |
||
148 | * @param array $logins all logins used current import session to be pre-fetched |
||
149 | * @void |
||
150 | */ |
||
151 | private function resolveClients($logins) |
||
157 | |||
158 | /** |
||
159 | * Resolves $time to a UNIX epoch timestamp. |
||
160 | * |
||
161 | * @param $time |
||
162 | * @return int UNIX epoch timestamp |
||
163 | */ |
||
164 | protected function resolveTime($time) |
||
182 | |||
183 | /** |
||
184 | * Resolves payment $type to a normal form. |
||
185 | * |
||
186 | * @param string $type |
||
187 | * @throws InvalidValueException |
||
188 | * @return string |
||
189 | */ |
||
190 | protected function resolveType($type) |
||
223 | |||
224 | /** |
||
225 | * Converts client login to ID. |
||
226 | * Note: [[resolveClients]]] must be called before calling this method. |
||
227 | * |
||
228 | * @param string $client |
||
229 | * @return string|int |
||
230 | * @see clientMap |
||
231 | */ |
||
232 | protected function convertClientToId($client) |
||
240 | } |
||
241 |