Skip to main content
Skip table of contents

PHP Scripts Actions Examples

In this section you can find examples covering a variety of job management options. These examples should give you an idea about how to use the PHP scripting in MyQ. You can also substitute the properties and methods in the examples to use them as building blocks of more complex scripts.

Actions based on the number of pages
Move jobs with a higher number of color pages to a monochrome queue.

PHP
if ($this->colorCount>20) {
 $this->moveToQueue("ForceMonochrome");
 }

Delete jobs with a large number of pages.

PHP
if ($this->pageCount>500) {
 $this->delete();
 }

Actions based on the size of the job
Move large jobs to a dedicated queue.

PHP
if ($this->dataSize>1000000) {
 $this->moveToQueue("LargeJobs");
 }

Delete oversized jobs.

PHP
if ($this->dataSize>5000000) {
 $this->delete();
 }

Actions based on paper format
Move jobs with the A3 paper format to a dedicated queue.

PHP
if ($this->paper===6) {
 $this->moveToQueue("LargePaperFormat");
 }

Actions based on the job owner
Move jobs of a certain owner to a dedicated queue.

PHP
if ($this->owner->name==="eliot.kate") {
 $this->moveToQueue("EliotKate");
 }

Change the owner of the job.

PHP
if ($this->owner->name==="eliot.kate") {
 $this->owner=MyQ()->getUserByUserName("simon.kate");
 }

Actions based on the duplex property
Move duplex jobs to a duplex queue.

PHP
if ($this->duplex) {
 $this->moveToQueue("Duplex");
 }

Move simplex jobs to a simplex queue.

PHP
if ($this->duplex===false) {
 $this->moveToQueue("Simplex");
 }

Actions based on the color property
Move color jobs to a color queue.

PHP
if ($this->color) {
 $this->moveToQueue("Color");
 }

Actions based on the job name or the source application
Move jobs printed in MS Word to a dedicated queue.

PHP
if (strpos($this->name,"Microsoft Word")!==false) {
 $this->moveToQueue("MSWord");
 }

Delete jobs sent from Facebook.

PHP
if (strpos($this->name,'Facebook')!==false) {
 $this->delete();
 }

Actions based on the rights to a queue
Move jobs of users who are not allowed to print to one queue to a different queue

PHP
if ($this->owner->canPrintToQueue(Color)===false) {
 $this->moveToQueue(Monochrome);
 }

Actions based on group membership
Move jobs sent by members of a group to a dedicated queue

PHP
if ($this->owner->hasGroup(Clerks)) {
 $this->moveToQueue(Clerks);
 }

Actions based on the PDL of the job
Move all jobs sent in a certain PDL to a dedicated queue

PHP
if ($this->lang===0) {
 $this->moveToQueue(UnknownPDL);
 }

Sending custom log messages to MyQ
Send a log info message to MyQ Log

PHP
MyQ()->logInfo("This message appears in the MyQ log.");

Complex actions

If the number of pages multiplied by the number of copies exceeds a certain number, delete the job and inform the user

PHP
// get the number of pages and the number of copies
$pages_number = $this->pageCount; $copies_number = $this->copies;
// if total (pagescopies) exceeds 500, delete the job and notify its owner
if ( $pages_number $copies_number>500) {
 $this->delete(); $this->owner->sendNotification("error","Job refused", "Cannot
 print jobs exceeding 500 pages.");
}

Move the job to a queue, if allowed

PHP
if ($this->color) {
  if ($this->owner->canPrintToQueue("JPS2")) {
     $this->moveToQueue("JPS2");
  } else {
     $this->owner->sendEmail("Job error", "Color printing denied");
     $this->delete();
  }
}

Move the job to the first available personal queue

PHP
// get all user's queues sorted by priority
$personalQueues = $this->owner->personalQueues;
 
// loop them
foreach ($personalQueues as $q) {
    // skip queue if no printer is available
    if ($q->isAnyPrinterAvailable() === false) {
        continue;
    }
 
    // queue printer is available, move job to queue
    $this->moveToQueue($q->name);
    // job is moved, stop the loop
    break;
}

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.