@@ -175,151 +175,156 @@ final class interneturok extends core
if ( ! empty ( $accounts )) {
// Initialized accounts
/* if ( shuffle( $accounts)) { */
// Shuffled accounts
if ( shuffle( $accounts)) {
// Shuffled accounts
foreach ( $accounts as $account ) {
// Iterating over accounts
// Waiting for processing the request
sleep ( $waiting );
if ( $this -> authentication ( $account ) -> wait ()) {
// Authenticated the account
// Writing into the output buffer
echo 'Аутентифицирован: ' . $account [ 'mail' ] . " \n " ;
foreach ( $accounts as $account ) {
// Iterating over accounts
// Waiting for processing the request
sleep ( $waiting );
// Initializing the user journal
$journal = $this -> journal ( grade : $grade ) -> wait ();
try {
if ( ! empty ( $journal )) {
// Initialized the user journal
if ( $this -> authentication ( $account ) -> wait ( )) {
// Authenticated the account
// Writing into the output buffer
echo " Инициализирован журнал \n " ;
// Writing into the output buffer
echo 'Аутентифицирован: ' . $account [ 'mail' ] . " \n " ;
// In itializing the actual date
$date = new datetime ( );
// Wa iting for processing the request
sleep ( $waiting );
// Initializing the homeworks database
$mode l = new homework ();
// Initializing the user journal
$journa l = $this -> journal ( grade : $grade ) -> wait ();
// Initializing the schedule subject events
$schedule = $journal ? -> schedule_events ;
if ( ! empty ( $journal )) {
// Initialized the user journal
foreach ( $schedule as $_subject ) {
// Iterating over scheduled subject events
// Writing into the output buffer
echo " Инициализирован журнал \n " ;
if ( $_subject -> subject ? -> name === $subject -> value ) {
// Found the target suject
// Initializing the actual date
$date = new datetime ();
foreach ( $_subject -> events as $event ) {
// Iterating over the target subject events
// Initializing the homeworks database
$model = new homework ();
// Norm alizing the event variable (events can be more than one)
$event = $event [ 0 ] ? ? null ;
// Initi alizing the schedule subject events
$schedule = $journal ? -> schedule_events ;
if ( ! empty ( $even t )) {
// Initialized the target subject event (the homework exists)
foreach ( $schedule as $_subjec t) {
// Iterating over scheduled subject events
if ( new datetime ( $event -> date ) <= $date && new datetime ( $event -> date ) -> modify ( '+6 days' ) >= $dat e) {
// Found the current even t
if ( $_subject -> subject ? -> name === $subject -> valu e) {
// Found the target sujec t
if ( $event -> subject ? ->name === $subject -> value && $event -> subject -> grade === $grade ) {
// Found the target subject
foreach ( $_ subject-> events as $event ) {
// Iterating over the target subject events
// Writing into the output buffer
echo " Найден школьный предмет: $subject->value для $grade класса (с " . new datetime ( $event -> date ) -> format ( 'd.m' ) . ' по ' . new datetime ( $event -> date ) -> modify ( '+6 days' ) -> format ( 'd.m' ) . " ) \n " ;
// Normalizing the event variable (events can be more than one)
$event = $event [ 0 ] ? ? null ;
// Initializing the unblock time
$unblock = svoboda :: timestamp () - 31536000 ;
if ( ! empty ( $event )) {
// Initialized the target subject event (the homework exists)
foreach ( $event -> homeworks as $homework ) {
// Iterating over scheduled event homeworks
if ( new datetime ( $event -> date ) <= $date && new datetime ( $event -> date ) -> modify ( '+6 days' ) >= $date ) {
// Found the current event
if ( $homework -> status === 'checked' && $homework -> mark === 5 ) {
// Homework checked and completed for a grade of 5
if ( $event -> subject ? -> name === $subject -> value && $event -> subject -> grade === $grade ) {
// Found the target subject
// Checking for the block record
$blocked = $model -> database -> read (
filter : fn ( record $record ) => $record -> identifier === $homework -> item_id && $record -> created > $unblock ,
amount : 1
)[ 0 ] ? ? null ;
// Writing into the output buffer
/* echo "Найден школьный предмет: $subject->value для $grade класса (с " . new datetime($event->date)->format('d.m') . ' по ' . new datetime($event->date)->modify('+6 days')->format('d.m') . ")\n"; */
if ( $blocked instanceof record ) {
// The account homework has been downloaded for 1 year
// Initializing the unblock time
$unblock = svoboda :: timestamp () - 31536000 ;
continue 3 ;
} else {
// The account homework has not been downloaded for 1 year
foreach ( $event -> homeworks as $homework ) {
// Iterating over scheduled event homeworks
// Writing into the output buffer
echo " Найдено домашнее задание: $homework->item_id с оценкой $homework->mark\n " ;
if ( $homework -> status === 'checked' && $homework -> mark === 5 ) {
// Homework checked and completed for a grade of 5
// Wait ing for processing the request
sleep ( $waiting );
// Check ing for the block record
$blocked = $model -> database -> read (
filter : fn ( record $record ) => $record -> identifier === $homework -> item_id && $record -> created > $unblock ,
amount : 1
)[ 0 ] ? ? null ;
// Initializing the homework files
$files = $this -> homework ( lesson : $event -> lesson -> id , homework : $homework -> item_id ) -> wait ();
if ( $blocked instanceof record ) {
// The account homework has been downloaded for 1 year
if ( ! empty ( $files )) {
// Initialized the homework files
continue 3 ;
} else {
// The account homework has not been downloaded for 1 year
// Writing into the output buffer
echo " Получ ено домашнее задание \n" ;
// Writing into the output buffer
echo " Найд ено домашнее задание: $homework->item_id с оценкой $homework->mark \n" ;
// Blocking the homework downloading for 1 year
$blocked = $model -> create ( identifier : $homework -> item_id );
// Waiting for processing the request
sleep ( $waiting );
if ( $blocked !== false ) {
// The homework was blocked for 1 year
// Initializing the homework files
$files = $this -> homework ( lesson : $event -> lesson -> id , homework : $homework -> item_id ) -> wait ();
// Writing into the output buffer
echo " Заблокировано на 1 год домашнее задание \n " ;
if ( ! empty ( $files )) {
// Initialized the homework files
// Exit (success)
return $files ;
// Writing into the output buffer
echo " Получено домашнее задание \n " ;
// Blocking the homework downloading for 1 year
$blocked = $model -> create ( identifier : $homework -> item_id );
if ( $blocked !== false ) {
// The homework was blocked for 1 year
// Writing into the output buffer
echo " Заблокировано на 1 год домашнее задание \n " ;
// Exit (success)
return $files ;
}
}
}
}
}
}
// Stopping processing events and starting processing the next account
break 2 ;
}
}
// Stopping processing events and starting processing the next account
break 2 ;
}
// Stopping processing events and starting processing the next account
break ;
}
}
} else {
// Not initialized the user journal
// Stopping processing events and starting processing the next account
break ;
// Writing into the output buffer
echo " Аккаунт не подходит под требования \n " ;
// Proceed to processing the next account
continue ;
}
} else {
// Not authenticated the account
// Writing into the output buffer
echo " Н е аутентифицирован\n " ;
// Proceed to processing the next account
continue ;
}
} else {
// Not initialized the user journal
// Writing into the output buffer
echo " Аккаунт не подходит под требования \n " ;
// Proceed to processing the next account
} catch ( exception $exception ) {
continue ;
}
} else {
// Not authenticated the account
// Writing into the output buffer
echo " Н е аутентифицирован\n " ;
// Proceed to processing the next account
continue ;
}
}
/* } */
}
// Exit (fail)
@@ -642,124 +647,29 @@ final class interneturok extends core
);
return $this -> browser -> sendAsync ( $request )
-> then ( function ( $response ) use ( $homework ) {
// Sended the request and received the response
-> then (
function ( $response ) use ( $homework ) {
// Sended the request and received the response
// Initializing the lesson
$lesson = json_decode (( string ) $response -> getBody ()) ? -> data ? -> homeschool ? -> response ;
// Initializing the lesson
$lesson = json_decode (( string ) $response -> getBody ()) ? -> data ? -> homeschool ? -> response ;
foreach ( $lesson -> items as $section ) {
// Iterating over the lesson sections
foreach ( $lesson -> items as $section ) {
// Iterating over the lesson sections
if ( $section -> id === $homework && $section -> item_type === 'homework' && $section -> homework_kind === 'homework_base' ) {
// Found the base homework section
if ( $section -> id === $homework && $section -> item_type === 'homework' && $section -> homework_kind === 'homework_base' ) {
// Found the base homework section
// Initializng the test identifier (string)
$test = $section -> homework_attributes ? -> parsed_content ? -> evo_test_id ? ? null ;
// Initializng the test identifier (string)
$test = $section -> homework_attributes ? -> parsed_content ? -> evo_test_id ? ? null ;
if ( ! empty ( $test )) {
// Initialized the test identifier
// Initializing the request to the test data API
$request = new request (
'GET' ,
static :: TESTS . " / $test /result " ,
[
'Authorization' => " Bearer $this->token "
]
);
return $this -> browser -> sendAsync ( $request )
-> then ( function ( $response ) use ( $homework ) {
// Sended the request and received the response
// Initializing the test result
$result = json_decode (( string ) $response -> getBody ()) ? -> data ? -> tests ? -> response ? -> data ;
if ( ! empty ( $result )) {
// Initialized the test result
// Initializing paths to the homework storage folder
$storage = STORAGE . DIRECTORY_SEPARATOR . 'homeworks' . DIRECTORY_SEPARATOR . $homework ;
// Initializing the homework storage folder
if ( ! file_exists ( $storage )) mkdir ( $storage , 0775 , true );
// Initializing the excel document
$excel = excel :: create ([ 'Домашнее задание' ]);
// Initializing the excel document sheet
$sheet = $excel -> sheet ();
// Writing settings of the excel document sheet
$sheet -> setColWidths ([ 'A' => 10 , 'B' => 80 , 'C' => 50 ]);
// Writing title
$sheet -> writeRow (
[ 'Номер' , 'Задание' , 'Ответ' ],
[
'font' => [
'style' => 'bold'
],
'text-align' => 'center' ,
'vertical-align' => 'center' ,
'border' => 'thin' ,
'height' => 24 ,
]
);
foreach ( $result -> test ? -> questions as $question ) {
// Iterating over questions
foreach ( $question -> answer_results as $answer ) {
// Iterating over question answers
if ( $answer -> is_correct ) {
// The answer is correct
if ( ! empty ( $answer -> section )) {
// Several sections for answers (expected)
// Writing questions and answers
$sheet -> writeRow ([ $question -> test_question_position , $question -> name , $answer -> section -> name . ' - ' . $answer -> value ]);
} else {
// One single answer (expected)
// Writing questions and answers
$sheet -> writeRow ([ $question -> test_question_position , $question -> name , $answer -> value ]);
}
}
}
}
// Initializing path to the excel document file
$path = $storage . DIRECTORY_SEPARATOR . 'homework.xlsx' ;
// Writing the excel document file to the storage
$excel -> save ( $path );
// Exit (success)
return [ $path ];
} else {
// Not initialized the test result
// Exit (fail)
return false ;
}
}) -> wait ();
} else {
// Not initialized the test identifier
// Initializing the attachment identifier
$attachment = $section -> result ? -> id ;
if ( ! empty ( $attachment )) {
// Initialized the attachment identifier
if ( ! empty ( $test )) {
// Initialized the test identifier
// Initializing the request to the test data API
$request = new request (
'GET' ,
static :: ATTACHMEN TS . " ?attachable_id= $attachment &attachable_type=Result::Homework " ,
static :: TES TS . " / $test /result " ,
[
'Authorization' => " Bearer $this->token "
]
@@ -769,71 +679,168 @@ final class interneturok extends core
-> then ( function ( $response ) use ( $homework ) {
// Sended the request and received the response
// Initializing attachments
$attachments = json_decode (( string ) $response -> getBody ()) ? -> data ? -> homeschool ? -> response ? -> attachments ;
// Initializing the test result
$result = json_decode (( string ) $response -> getBody ()) ? -> data ? -> tests ? -> response ? -> data ;
if ( ! empty ( $attachments )) {
// Initialized attachmetns
if ( ! empty ( $result )) {
// Initialized the test result
// Initializing paths to the homework attachments storage folder
$storage = STORAGE . DIRECTORY_SEPARATOR . 'homeworks' . DIRECTORY_SEPARATOR . $homework . DIRECTORY_SEPARATOR . 'attachments' ;
// Initializing paths to the homework storage folder
$storage = STORAGE . DIRECTORY_SEPARATOR . 'homeworks' . DIRECTORY_SEPARATOR . $homework ;
// Initializing the homework attachments storage folder
// Initializing the homework storage folder
if ( ! file_exists ( $storage )) mkdir ( $storage , 0775 , true );
// Declaring the buffer of files
$files = [] ;
// Initializing the excel document
$excel = excel :: create ([ 'Домашнее задание' ]) ;
foreach ( $attachments as $attachment ) {
// Iteration over attachments
// Initializing the excel document sheet
$sheet = $excel -> sheet ();
if ( $attachment -> uploader_role === 'student' && $attachment -> attachable_type === 'Result::Homework' ) {
// Found the homework attachment
// Writing settings of the excel document sheet
$sheet -> setColWidths ([ 'A' => 10 , 'B' => 80 , 'C' => 50 ]);
// In itializing path to the downloaded fi le
$path = $storage . DIRECTORY_SEPARATOR . $attachment -> attach_path ;
// Wr iting tit le
$sheet -> writeRow (
[ 'Номер' , 'Задание' , 'Ответ' ],
[
'font' => [
'style' => 'bold'
],
'text-align' => 'center' ,
'vertical-align' => 'center' ,
'border' => 'thin' ,
'height' => 24 ,
]
);
// Downloading the file
$this -> browser -> request ( 'GET' , $attachment -> attach , [ 'sink' => $path ]);
foreach ( $result -> test ? -> questions as $question ) {
// Iterating over questions
// Writing path to the downloaded file into the buffer of files
$files [] = $path ;
foreach ( $question -> answer_results as $answer ) {
// Iterating over question answers
if ( $answer -> is_correct ) {
// The answer is correct
if ( ! empty ( $answer -> section )) {
// Several sections for answers (expected)
// Writing questions and answers
$sheet -> writeRow ([ $question -> test_question_position , $question -> name , $answer -> section -> name . ' - ' . $answer -> value ]);
} else {
// One single answer (expected)
// Writing questions and answers
$sheet -> writeRow ([ $question -> test_question_position , $question -> name , $answer -> value ]);
}
}
}
}
// Initializing path to the excel document file
$path = $storage . DIRECTORY_SEPARATOR . 'homework.xlsx' ;
// Writing the excel document file to the storage
$excel -> save ( $path );
// Exit (success)
return $files ;
return [ $path ] ;
} else {
// Not initialized attachments
// Not initialized the test result
// Exit (fail)
return false ;
}
}) -> wait ();
} else {
// Not initialized the attachmen t identifier
// Not initialized the tes t identifier
// Exit (fail)
return false ;
// Initializing the attachment identifier
$attachment = $section -> result ? -> id ;
if ( ! empty ( $attachment )) {
// Initialized the attachment identifier
// Initializing the request to the test data API
$request = new request (
'GET' ,
static :: ATTACHMENTS . " ?attachable_id= $attachment &attachable_type=Result::Homework " ,
[
'Authorization' => " Bearer $this->token "
]
);
return $this -> browser -> sendAsync ( $request )
-> then ( function ( $response ) use ( $homework ) {
// Sended the request and received the response
// Initializing attachments
$attachments = json_decode (( string ) $response -> getBody ()) ? -> data ? -> homeschool ? -> response ? -> attachments ;
if ( ! empty ( $attachments )) {
// Initialized attachmetns
// Initializing paths to the homework attachments storage folder
$storage = STORAGE . DIRECTORY_SEPARATOR . 'homeworks' . DIRECTORY_SEPARATOR . $homework . DIRECTORY_SEPARATOR . 'attachments' ;
// Initializing the homework attachments storage folder
if ( ! file_exists ( $storage )) mkdir ( $storage , 0775 , true );
// Declaring the buffer of files
$files = [];
foreach ( $attachments as $attachment ) {
// Iteration over attachments
if ( $attachment -> uploader_role === 'student' && $attachment -> attachable_type === 'Result::Homework' ) {
// Found the homework attachment
// Initializing path to the downloaded file
$path = $storage . DIRECTORY_SEPARATOR . $attachment -> attach_path ;
// Downloading the file
$this -> browser -> request ( 'GET' , $attachment -> attach , [ 'sink' => $path ]);
// Writing path to the downloaded file into the buffer of files
$files [] = $path ;
}
}
// Exit (success)
return $files ;
} else {
// Not initialized attachments
// Exit (fail)
return false ;
}
}) -> wait ();
} else {
// Not initialized the attachment identifier
// Exit (fail)
return false ;
}
}
}
}
}
// Exit (fail)
return false ;
},
function ( $response ) use ( $homework ) {
if ( $response -> getStatusCode () === 402 ) {
// Fail (received the "Payment Required" status code)
// Writing into the output buffer
echo " Н е удалось скачать домашнее задание $homework потому, что не оплачен тариф \n " ;
// Exit (fail)
return false ;
},
function ( $response ) use ( $homework ) {
if ( $response -> getStatusCode () === 402 ) {
// Fail (received the "Payment Required" status code)
// Writing into the output buffer
echo " Н е удалось скачать домашнее задание $homework потому, что не оплачен тариф \n " ;
// Exit (fail)
return false ;
}
}
} );
);
}
// Exit (fail)
@@ -898,16 +905,21 @@ final class interneturok extends core
*/
public static function amount () : int
{
// Opening the interneturok accounts file
$file = new spl ( INTERNETUROK_ACCOUNTS_FILE , 'r' );
try {
// Opening the interneturok accounts file
$file = new spl ( INTERNETUROK_ACCOUNTS_FILE , 'r' );
// Move the cursor to the last row
$file -> seek ( PHP_INT_MAX );
// Move the cursor to the last row
$file -> seek ( PHP_INT_MAX );
// Initializing number of the last row
$rows = $file -> key ();
// Initializing number of the last row
$rows = $file -> key ();
// Exit (success)
return $rows ;
// Exit (success)
return $rows ;
} catch ( exception $exception ) {
// Exit (fail)
return 0 ;
}
}
}