append() static public method

Appends new content to an existing file
static public append ( string $file, mixed $content ) : boolean
$file string The path for the file
$content mixed Either a string or an array. Arrays will be converted to JSON.
return boolean
Exemplo n.º 1
0
 public function testAppend()
 {
     $this->assertTrue(f::append($this->tmpFile, ' is awesome'));
 }
Exemplo n.º 2
0
 //if page is accessed thorugh ajax
 if (r::ajax()) {
     //store sanitized $_POST variables
     $currentTestData = r::postData(array('test', 'user', 'data'));
     //get logged user (if any)
     if ($user = Auth::loggedUser()) {
         //get user's session page
         $userSession = site()->find(implode(DS, array(c::get('sessions.folder'), $user->session())));
         //istantiate testSession object
         $tSession = new testSession($userSession, $user->username());
         //get user's current session status
         $userSessionStatus = $user->status();
         //if ajaxed $currentTestData equals user's current session status
         if (str::lower($currentTestData['test']) == str::lower($userSessionStatus)) {
             //if it was possitble to update user's results file (by appending $currentTestData)
             if (f::append($tSession->getUserResultsFile(), PHP_EOL . a::json($currentTestData))) {
                 //set updated user's session status to next avalibale test
                 $updatedStatus = $tSession->getNextTest($currentTestData['test']);
                 //if there aren't tests available, set user's session statuts to completed session
                 if (!$updatedStatus) {
                     $updatedStatus = c::get('session.status.completed');
                 }
                 //update user's session status to next avalibale test
                 $user->update(array('status' => $updatedStatus));
                 //return to tests page
                 $url = $pages->find(c::get('tests.folder'))->url();
             }
         }
     }
 } else {
     //go to errorPage, since page wasn't accessed through ajax