Ejemplo n.º 1
0
// Dummy data
$data = array('transcript_id' => 5, 'item_id' => 193, 'user_id' => 'username');
// Register save/load hooks
echo "Registering events...\n";
$eventManager = new EventManager();
$eventManager->register('load', 'transcript', 'onLoad');
$eventManager->register('save', 'transcript', 'onSave');
echo "Setting event manager...\n";
Transcript::setEventManager($eventManager);
// Register
echo "Registering transcript hooks...\n";
Transcript::register('load', 'myTranscriptLoadFunction');
Transcript::register('save', 'myTranscriptSaveFunction');
echo "Loading transcript...\n\n";
$transcript = new Transcript();
$transcript->load($data);
echo "Text for transcript: [" . $transcript->getText() . "]\n\n";
echo "Changing text...\n";
$myText = "Hallelujah, it worked!";
$transcript->setText($myText);
echo "Text for transcript: [" . $transcript->getText() . "]\n\n";
echo "Saving transcript...\n\n";
$transcript->save($data);
echo "Text for transcript: [" . $transcript->getText() . "]\n\n";
echo "Creating second transcript...\n";
$transcript2 = new Transcript();
$transcript2->setText("This is the second transcript.");
echo "Collating...\n";
$collated = Transcript::collate(array($transcript, $transcript2), "\n\n--**--\n\n");
echo "Collated version:\n";
echo $collated;
Ejemplo n.º 2
0
 public static function transcript($params)
 {
     $format = Utils::getFormat($params['args'], 0, 2);
     $projectType = Utils::getProjectType($params['args']);
     $projectSlugIndex = $projectType == 'system' ? 0 : 2;
     $projectSlug = $params['args'][$projectSlugIndex];
     $itemIndex = $projectType == 'system' ? 1 : 3;
     $itemId = $params['args'][$itemIndex];
     $owner = $projectType == 'user' ? $params['args'][1] : '';
     $user = User::getAuthenticatedUser();
     switch ($params['method']) {
         // POST: Post transcript for item
         case 'POST':
             $proofType = Utils::POST('proofType');
             $proofUser = Utils::POST('proofUser');
             $transcriptText = Utils::POST('transcript');
             $transcriptStatus = Utils::POST('status');
             // draft, completed, reviewed
             $fields = Utils::POST('fields');
             $role = $proofType . "er";
             // Make sure they have access to the item
             if ($proofType == 'edit' || $proofUser != '') {
                 // For editing an item or a specific proof/review, user must be project admin or site admin
                 RoleController::forceClearance(array('project.admin', 'project.owner', 'system.admin'), $user, array('project' => $project));
             } else {
                 // User has to be a member of the project
                 if (!$user->isMember($projectSlug, $role, $owner)) {
                     Utils::redirectToDashboard("", $i18n->t("error.not_a_member"));
                     return;
                 }
             }
             // If we're looking at an existing proof/review, load it for that user
             // Otherwise load it for the existing user
             $username = $proofUser != '' ? $proofUser : $user->username;
             // Load the item
             $itemObj = new Item($itemId, $projectSlug, $username, $proofType);
             // Make sure item exists (if it fails, it'll return a boolean)
             if ($itemObj->item_id == -1) {
                 Utils::redirectToDashboard("", $i18n->t("error.nonexistent_item"));
                 return;
             }
             // Make sure the user has this item in their queue
             // TODO: Finish
             if ($proofType == 'edit') {
                 // Set the transcript and save the item
                 $itemObj->transcript = $transcriptText;
                 $itemObj->save();
             } else {
                 // Save transcript to database
                 $transcript = new Transcript();
                 $transcript->load(array('item' => $itemObj, 'type' => $proofType));
                 $transcript->setText($transcriptText);
                 $transcript->setFields($fields);
                 $transcript->save(array('item' => $itemObj, 'status' => $transcriptStatus, 'type' => $proofType));
                 // If we're looking at a user's proof or review, or if the transcript has already been
                 // completed/reviewed, then we don't want to update scoring and move the item through
                 // the workflow index
                 if ($proofUser == '' && $transcriptStatus != 'draft') {
                     $scoring = Settings::getProtected('scoring');
                     // Notifications
                     if ($transcriptStatus == 'reviewed') {
                         // Bump user's score up if they haven't already reviewed this item
                         $user->updateScoreForItem($itemObj->item_id, $itemObj->project_id, $scoring['review'], 'review');
                         // Notify project owner that review is complete
                     } else {
                         if ($transcriptStatus == 'completed') {
                             // Bump user's score up if they haven't already proofed this item
                             $user->updateScoreForItem($itemObj->item_id, $itemObj->project_id, $scoring['proof'], 'proof');
                         }
                     }
                     // Remove from user's queue
                     $userQueue = new Queue("user.{$proofType}:{$user->username}");
                     $userQueue->remove($itemObj);
                     $userQueue->save();
                     // Increase item's workflow index
                     $itemObj->workflow_index += 1;
                     // And save it
                     $itemObj->save();
                     // Load the project
                     $project = new Project($itemObj->project_slug);
                     // Get next workflow step
                     $workflow = new Workflow($project->workflow);
                     $workflow->setIndex($itemObj->workflow_index);
                     $workflowQueue = $workflow->getWorkflow();
                     if ($itemObj->workflow_index < count($workflowQueue)) {
                         // Process next step
                         $workflow->next($itemObj);
                     } else {
                         // The item is complete
                         $itemObj->setStatus("completed");
                     }
                 }
             }
             echo json_encode(array("statuscode" => "success"));
             break;
     }
 }