1 | <?php |
||
33 | class BillImportForm extends \yii\base\Model |
||
34 | { |
||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | public $data; |
||
39 | /** |
||
40 | * @var array Array of possible bill types. |
||
41 | * Key - full bill type |
||
42 | * Value - bill type title |
||
43 | */ |
||
44 | public $billTypes = []; |
||
45 | /** |
||
46 | * @var array map to find client id by login. |
||
47 | * Key - login |
||
48 | * Value - id |
||
49 | * |
||
50 | */ |
||
51 | private $clientsMap = []; |
||
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | public function attributes() |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | public function attributeLabels() |
||
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | */ |
||
74 | public function rules() |
||
80 | |||
81 | /** |
||
82 | * Parses [[data]] attribute and creates [[Bill]] model from each line. |
||
83 | * |
||
84 | * @return Bill[]|false Array of [[Bill]] models on success or `false` on parsing error |
||
85 | */ |
||
86 | public function parse() |
||
121 | |||
122 | /** |
||
123 | * Splits $line for chunks by `;` character. |
||
124 | * Ensures there are exactly 6 chunks. |
||
125 | * Trims each value before return. |
||
126 | * |
||
127 | * @param string $line to be exploded |
||
128 | * @return array |
||
129 | */ |
||
130 | protected function splitLine($line) |
||
139 | |||
140 | /** |
||
141 | * @param array $logins all logins used current import session to be pre-fetched |
||
142 | * @void |
||
143 | */ |
||
144 | private function resolveClients($logins) |
||
150 | |||
151 | /** |
||
152 | * Resolves $time to a UNIX epoch timestamp. |
||
153 | * |
||
154 | * @param $time |
||
155 | * @return int UNIX epoch timestamp |
||
156 | */ |
||
157 | protected function resolveTime($time) |
||
175 | |||
176 | /** |
||
177 | * Resolves payment $type to a normal form |
||
178 | * |
||
179 | * @param string $type |
||
180 | * @return string |
||
181 | * @throws InvalidValueException |
||
182 | */ |
||
183 | protected function resolveType($type) |
||
216 | |||
217 | /** |
||
218 | * Converts client login to ID. |
||
219 | * Note: [[resolveClients]]] must be called before calling this method. |
||
220 | * |
||
221 | * @param string $client |
||
222 | * @return string|int |
||
223 | * @see clientMap |
||
224 | */ |
||
225 | protected function convertClientToId($client) |
||
233 | } |
||
234 |