本文整理汇总了PHP中Queue::isHydrated方法的典型用法代码示例。如果您正苦于以下问题:PHP Queue::isHydrated方法的具体用法?PHP Queue::isHydrated怎么用?PHP Queue::isHydrated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::isHydrated方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listjobs
public function listjobs()
{
$this->assertLoggedIn();
try {
//did we get a queue?
$queue = new Queue($this->args('id'));
if (!$queue->isHydrated()) {
throw new Exception("Could not find that queue.");
}
if (!$queue->isMine()) {
throw new Exception("You do not have permission to view this queue.");
}
$this->set('queue', $queue);
//what sort of jobs to view?
$status = $this->args('status');
if ($status == 'available') {
$this->setTitle($queue->getName() . "'s Available Jobs");
$collection = $queue->getJobs($status);
} else {
if ($status == 'taken') {
$this->setTitle($queue->getName() . "'s Working Jobs");
$collection = $queue->getJobs($status);
} else {
if ($status == 'complete') {
$this->setTitle($queue->getName() . "'s Finished Jobs");
$collection = $queue->getJobs($status);
} else {
if ($status == 'failure') {
$this->setTitle($queue->getName() . "'s Failed Jobs");
$collection = $queue->getJobs($status);
} else {
if ($status == 'all') {
$this->setTitle($queue->getName() . "'s Jobs");
$collection = $queue->getJobs(null);
} else {
throw new Exception("That is not a valid status!");
}
}
}
}
}
$per_page = 20;
$page = $collection->putWithinBounds($this->args('page'), $per_page);
$this->set('per_page', $per_page);
$this->set('total', $collection->count());
$this->set('page', $page);
$this->set('jobs', $collection->getPage($page, $per_page));
$this->set('status', $status);
} catch (Exception $e) {
$this->setTitle('View Queue - Error');
$this->set('megaerror', $e->getMessage());
}
}
示例2: getDefaultQueue
public function getDefaultQueue()
{
$sql = "SELECT id FROM queues\n\t\t\t\tWHERE name = 'Default'\n\t\t\t\tAND user_id = ?";
$q = new Queue(db()->getValue($sql, array($this->id)));
if (!$q->isHydrated()) {
$sql = "SELECT id FROM queues ORDER BY id LIMIT 1";
$q = new Queue(db()->getValue($sql));
}
return $q;
}
示例3: flush
public function flush()
{
$this->assertLoggedIn();
$this->set('area', 'queues');
try {
//how do we find them?
$queue = new Queue($this->args('id'));
//did we really get someone?
if (!$queue->isHydrated()) {
throw new Exception("Could not find that queue.");
}
if ($queue->get('user_id') != User::$me->id) {
throw new Exception("You do not own this queue.");
}
$this->set('queue', $queue);
$this->setTitle('Empty Queue - ' . $queue->getName());
if ($this->args('submit')) {
Activity::log("emptied the queue <strong>" . $queue->getName() . "</strong>.");
$queue->flush();
$this->forwardToUrl($queue->getUrl());
}
} catch (Exception $e) {
$this->setTitle('Empty Queue - Error');
$this->set('megaerror', $e->getMessage());
}
}
示例4: api_createjob
public function api_createjob()
{
$queue = new Queue($this->args('queue_id'));
if (!$queue->isHydrated()) {
$queue = User::$me->getDefaultQueue();
}
if (!$queue->isHydrated()) {
throw new Exception("Could not find a queue.");
}
if (!$queue->isMine()) {
throw new Exception("This is not your queue.");
}
//get our quantity and make sure its at least 1.
if ($this->args('quantity')) {
/* @var $quantity int */
$quantity = (int) $this->args('quantity');
} else {
$quantity = 1;
}
$quantity = max(1, $quantity);
$quantity = min(100, $quantity);
// there are 3 ways to create a job:
// #1 - existing job id
if ($this->args('job_id')) {
$oldjob = new Job($this->args('job_id'));
if (!$oldjob->isHydrated()) {
throw new Exception("Job does not exist.");
}
if (!$oldjob->getQueue()->isMine()) {
throw new Exception("This job is not in your queue.");
}
$file = $oldjob->getSourceFile();
if (!$file->isHydrated()) {
$file = $oldjob->getFile();
}
if (!$file->isHydrated()) {
throw new Exception("No file found!");
}
$jobs = $queue->addFile($file, $quantity);
} else {
if ($this->args('job_url')) {
//download our file.
$url = $this->args('job_url');
$data = Utility::downloadUrl($url);
//does it match?
if (!preg_match("/\\.(" . ACCEPTABLE_FILES . ")\$/i", $data['realname'])) {
throw new Exception("The file <a href=\"" . $url . "\">{$data['realname']}</a> is not valid for printing.");
}
//create our file object.
$file = Storage::newFile();
$file->set('user_id', User::$me->id);
$file->set('source_url', $url);
$file->upload($data['localpath'], StorageInterface::getNiceDir($data['realname']));
//okay, create our jobs.
$jobs = $queue->addFile($file, $quantity);
} else {
if (!empty($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
//upload our file
$file = $_FILES['file'];
$this->ensureGoodFile($file);
//does it match?
if (!preg_match("/\\.(" . ACCEPTABLE_FILES . ")\$/i", $file['name'])) {
throw new Exception("The file '{$file['name']}' is not valid for printing.");
}
//okay, we're good.. do it.
$data_file = Storage::newFile();
$data_file->set('user_id', User::$me->id);
$data_file->upload($file['tmp_name'], StorageInterface::getNiceDir($file['name']));
//okay, create our jobs.
$jobs = $queue->addFile($data_file, $quantity);
} else {
throw new Exception("Unknown job creation method.");
}
}
}
Activity::log("created " . count($jobs) . " new " . Utility::pluralizeWord('job', count($jobs)) . " via the API.");
//did we get a name?
if ($this->args('name')) {
foreach ($jobs as $job) {
/* @var $job Job */
$job->setName($this->args('name'));
$job->save();
}
}
//load our api data.
$data = array();
if (!empty($jobs)) {
foreach ($jobs as $job) {
$data[] = $job->getAPIData();
}
}
return $data;
}
示例5: _createJobsFromFile
/**
* @param $file StorageInterface
* @param $quantity mixed
* @param $queue_id mixed
* @param $priority mixed
* @return array
* @throws Exception
*/
private function _createJobsFromFile($file, $quantity, $queue_id, $priority)
{
//pull in our quantity
$quantity = (int) $quantity;
$quantity = max(1, $quantity);
$quantity = min(1000, $quantity);
//queue error checking.
$queue = new Queue($queue_id);
if (!$queue->isHydrated()) {
throw new Exception("That queue does not exist.");
}
if (!$queue->isMine()) {
throw new Exception("You do not have permission to add to that queue.");
}
//okay, we good?
$jobs = $queue->addFile($file, $quantity);
//priority or not?
if ($priority) {
if (!empty($jobs)) {
foreach ($jobs as $job) {
/* @var $job Job */
$job->pushToTop();
}
}
}
return $jobs;
}
示例6: create
public function create()
{
$this->assertLoggedIn();
if ($this->args('step2')) {
$this->setTitle('Step 2 of 2: Create Job');
} else {
$this->setTitle('Create new Job');
}
try {
if ($this->args('job_id')) {
$job = new Job($this->args('job_id'));
if (!$job->isHydrated()) {
throw new Exception("That job does not exist.");
}
if ($job->get('user_id') != User::$me->id) {
throw new Exception("You do not own this job.");
}
$file = $job->getFile();
$queue_id = $job->get('queue_id');
} else {
$file = new S3File($this->args('file_id'));
}
if (!$file->isHydrated()) {
throw new Exception("That file does not exist.");
}
if ($file->get('user_id') != User::$me->id) {
throw new Exception("You do not have access to this file.");
}
$this->set('file', $file);
//load up our form.
$form = $this->_createJobForm($file, $queue_id);
if (isset($job)) {
$form->action = "/job/create/job:{$job->id}";
} else {
$form->action = "/job/create/file:{$file->id}";
}
//handle our form
if ($form->checkSubmitAndValidate($this->args())) {
//pull in our quantity
$quantity = (int) $form->data('quantity');
$quantity = max(1, $quantity);
$quantity = min(1000, $quantity);
//queue error checking.
$queue = new Queue($form->data('queue_id'));
if (!$queue->isHydrated()) {
throw new Exception("That queue does not exist.");
}
if (!$queue->canAdd()) {
throw new Exception("You do not have permission to add to that queue.");
}
//okay, we good?
$queue->addGCodeFile($file, $quantity);
Activity::log("added {$quantity} new " . Utility::pluralizeWord('job', $quantity));
$this->forwardToUrl($queue->getUrl());
}
$this->set('form', $form);
} catch (Exception $e) {
$this->set('megaerror', $e->getMessage());
}
}