本文整理汇总了PHP中Queue::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Queue::save方法的具体用法?PHP Queue::save怎么用?PHP Queue::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::save方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
$this->assertLoggedIn();
$this->setTitle('Create a New Queue');
if ($this->args('submit')) {
//did we get a name?
if (!$this->args('name')) {
$errors['name'] = "You need to provide a name.";
$errorfields['name'] = 'error';
}
//okay, we good?
if (empty($errors)) {
//woot!
$q = new Queue();
$q->set('name', $this->args('name'));
$q->set('user_id', User::$me->id);
$q->save();
//todo: send a confirmation email.
Activity::log("created a new queue named " . $q->getLink() . ".");
$this->forwardToUrl($q->getUrl());
} else {
$this->set('errors', $errors);
$this->set('errorfields', $errorfields);
$this->setArg('name');
}
}
}
示例2: addToQueque
/**
*
* @param string $type
* @param string $description
* @param string $function
* @param array $args
* @param int $priority
* @return type
*/
static function addToQueque($type, $description, $function, $args, $priority = 0)
{
$queue = new Queue();
$queue->setCreatedAt(time());
$queue->setStatus(self::STATUS_QUEUED);
$queue->setArguments(serialize($args));
$queue->setFunction($function);
$queue->setType($type);
$queue->setDescription($description);
$queue->setPriority($priority);
return $queue->save();
}
示例3: actionCreate
/**
* Создает новую модель задание.
* Если создание прошло успешно - перенаправляет на просмотр.
*
* @return void
*/
public function actionCreate()
{
$model = new Queue();
if (($data = Yii::app()->getRequest()->getPost('Queue')) !== null) {
$model->setAttributes($data);
if ($model->save()) {
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('QueueModule.queue', 'Record was created!'));
$this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create']));
}
}
$this->render('create', ['model' => $model]);
}
示例4: actionCreate
/**
* Создает новую модель задание.
* Если создание прошло успешно - перенаправляет на просмотр.
*
* @return void
*/
public function actionCreate()
{
$model = new Queue();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (($data = Yii::app()->getRequest()->getPost('Queue')) !== null) {
$model->setAttributes($data);
if ($model->save()) {
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('QueueModule.queue', 'Record was created!'));
$this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', array('create')));
}
}
$this->render('create', array('model' => $model));
}
示例5: parse
public static function parse($item, $action)
{
$auth = Settings::getProtected('auth');
$auth->forceAuthentication();
$username = $auth->getUsername();
$user = new User($username);
// Parse the action
switch (trim($action)) {
case '@proofer':
$destinationQueue = "project.proof:" . $item->project_slug;
break;
case '@reviewer':
$destinationQueue = "project.review:" . $item->project_slug;
break;
default:
// username (defaults to proof, TODO: allow review as well)
$destinationQueue = "user.proof:" . $action;
break;
}
$queue = new Queue($destinationQueue);
$queue->add($item);
$queue->save();
}
示例6: createItems
public function createItems()
{
// Load the queue
$projectQueue = new Queue("project.proof:{$this->projectSlug}", false);
// Now go through the item info array
foreach ($this->itemData as $itemInfo) {
// Create a new item
$item = new Item();
// Populate it
$item->title = $itemInfo['title'];
$item->project_id = $itemInfo['project_id'];
$item->transcript = $itemInfo['transcript'];
$item->type = $itemInfo['type'];
$item->href = $itemInfo['href'];
// And add it to the database
$item->save();
// Save it to our $this->items array
array_push($this->items, $item);
// Add it to the queue
$projectQueue->add($item);
}
// Save the project queue
$projectQueue->save();
}
示例7: register
public function register()
{
$registerForm = $this->_createRegisterForm();
$this->set('register_form', $registerForm);
if ($registerForm->checkSubmitAndValidate($this->args())) {
$username = $this->args('username');
if (!Verify::username($username, $reason)) {
/** @var FormField $field */
$field = $registerForm->get('username');
$field->error($reason);
}
$email = $this->args('email');
$testUser = User::byEmail($email);
if ($testUser->isHydrated()) {
/** @var FormField $emailField */
$emailField = $registerForm->get('email');
$emailField->error("That email is already being used");
}
if ($this->args('pass1') != $this->args('pass2')) {
/** @var FormField $field */
$field = $registerForm->get('pass2');
$field->error("Your passwords do not match");
}
if (!$registerForm->hasError()) {
//woot!
$user = new User();
$user->set('username', $username);
$user->set('email', $email);
$user->set('pass_hash', User::hashPass($this->args('pass1')));
$user->set('registered_on', date("Y-m-d H:i:s"));
$user->save();
//create a default queue for them
$q = new Queue();
$q->set("name", 'Default');
$q->set("user_id", $user->id);
$q->save();
Activity::log("registered a new account on BotQueue.", $user);
$text = Controller::byName('email')->renderView('new_user', array('user' => $user));
$html = Controller::byName('email')->renderView('new_user_html', array('user' => $user));
Email::queue($user, "Welcome to " . RR_PROJECT_NAME . "!", $text, $html);
//automatically log them in.
$token = $user->createToken();
$token->setCookie();
$this->forwardToURL("/");
}
}
}
示例8: api_createqueue
public function api_createqueue()
{
if (!$this->args('name')) {
throw new Exception('Queue name is a required parameter.');
}
$q = new Queue();
$q->set('name', $this->args('name'));
$q->set('user_id', User::$me->id);
$q->save();
Activity::log("created a queue named " . $q->getLink() . " via the API.");
return $q->getAPIData();
}
示例9: json_encode
try {
Queue::register('compare', array('Point', 'compareItems'));
Queue::register('destroy', 'destroyQueue');
} catch (Exception $e) {
echo "FAIL\n";
echo $e->getMessage();
}
$queue = new Queue('2');
echo "queue 1 loaded\n";
$item = $queue->getFirstItem();
echo 'first item: ' . $item . "\n";
$item = $queue->remove(new Point(4, 0));
echo 'fourth item: ' . $item . "\n";
$item = $queue->getFirstItem();
echo 'second item: ' . $item . "\n";
if ($queue->save()) {
echo "\nsaved.\n";
}
echo json_encode($queue->getItems());
echo "\n";
$items = $queue->getItems();
$items[] = new Point(4, 3);
$items[] = new Point(5, 3);
$items[] = new Point(1, 1);
$queue->setItems($items);
$queue->add(new Point(42, 222));
if ($queue->save()) {
echo "\nsaved.\n";
}
echo "test 2 done\n\n";
$queue->destroy();
示例10: getNewItem
public static function getNewItem($params)
{
$format = Utils::getFormat($params['args'], 0, 2);
$projectPage = Utils::getProjectType($params['args']);
$projectSlugIndex = $projectPage == 'system' ? 0 : 2;
$projectSlug = $params['args'][$projectSlugIndex];
$user = User::getAuthenticatedUser();
switch ($params['method']) {
// POST: Get next available item
case 'POST':
$type = Utils::POST('type');
// proof or review
$dispatch = Settings::getProtected('dispatch');
$dispatch->init(array('username' => $user->username, 'projectSlug' => $projectSlug, 'type' => $type));
$response = $dispatch->next();
if ($response['status'] == true) {
$itemId = $response['code'];
// Load the item to make sure it's real
$item = new Item('', $itemId, $projectSlug, $user->username, $type);
// Verification check
if ($item->status == 'available') {
// Put it in the user's queue
$queue = new Queue("user.{$type}:{$user->username}", true);
$queue->add($item);
$queue->save();
}
}
echo json_encode($response);
break;
}
}
示例11: register
public function register()
{
if ($this->args('submit') && $this->args('action') == 'register') {
//validate username
$username = $this->args('username');
if (!Verify::username($username, $reason)) {
$errors['username'] = $reason;
$errorfields['username'] = 'error';
}
//validate email
$email = $this->args('email');
if (!Verify::email($email)) {
$errors['email'] = "You must supply a valid email.";
$errorfields['email'] = 'error';
} else {
$testUser = User::byEmail($email);
if ($testUser->isHydrated()) {
$errors['email'] = "That email is already being used.";
$errorfields['email'] = 'error';
}
}
//check passwords
if ($this->args('pass1') != $this->args('pass2')) {
$errors['password'] = "Your passwords do not match.";
$errorfields['password'] = 'error';
} else {
if (!strlen($this->args('pass1'))) {
$errors['password'] = "You must enter a password.";
$errorfields['password'] = 'error';
}
}
//okay, we good?
if (empty($errors)) {
//woot!
$user = new User();
$user->set('username', $username);
$user->set('email', $email);
$user->set('pass_hash', User::hashPass($this->args('pass1')));
$user->set('registered_on', date("Y-m-d H:i:s"));
$user->save();
//create them a default queue.
$q = new Queue();
$q->set("name", 'Default');
$q->set("user_id", $user->id);
$q->save();
//todo: send a confirmation email.
Activity::log("registered a new account on BotQueue.", $user);
//automatically log them in.
$token = $user->createToken();
$token->setCookie();
$this->forwardToUrl('/');
} else {
$this->set('errors', $errors);
$this->set('errorfields', $errorfields);
$this->setArg('username');
$this->setArg('email');
$this->setArg('pass1');
$this->setArg('pass2');
}
}
}
示例12: queue_record_delete
public function queue_record_delete($p)
{
/*
* Find out if we received var domain_id or domain_name
*/
$dDeps = $this->get_DepsBeforeQueue($p);
$domain_id = $dDeps["domain_id"];
$domain_name = $dDeps["domain_name"];
$record_id = NULL;
/*
* Check if we received record_id else it's not possible to edit this record
*/
if ($p->id != NULL) {
$record_id = $p->id;
} else {
throw new Exception('Unable to queue this record, no valid record_id!');
}
/*
* Check for same pending record change
*/
if (Queue::is_pendingRecord($domain_name, $p)) {
throw new Exception('Already pending change for this record!');
}
/*
* Create queueItemRecord for deletion of this record
*/
$qir = new QueueItemRecord(array('ch_date' => date("Y-m-d\\TH:i:s"), 'user_id' => '1', 'function' => 'record_delete', 'domain_name' => $domain_name, 'record_id' => $record_id, 'name' => $p->name, 'type' => $p->type, 'content' => $p->content, 'ttl' => $p->ttl, 'prio' => $p->prio));
/*
* Get a pending queue for same domain if there isn't any create new Queue.
*/
$q = Queue::get_pendingQueue($domain_name);
if (!isset($q)) {
$q = new Queue(array('ch_date' => date("Y-m-d\\TH:i:s"), 'domain_name' => $domain_name, 'archived' => '0', 'closed' => '0', 'comment' => 'Deleting record(s) for domain: ' . $domain_name));
}
$q->queue_item_records_push($qir);
$q->save();
return $q->id;
}
示例13: Queue
$objEditItem->save();
$pMessage = $arrLanguageMessage['done_updated'];
} else {
$objEditItem->add();
$pMessage = $arrLanguageMessage['done_added'];
}
$objEditItem = new Queue();
} else {
$hasErrors = 1;
}
}
} else {
if ($objEditItem->check()) {
if ($objEditItem->isLoaded()) {
//$objEditItem->save($oldPriority, $testbed);
$objEditItem->save();
$pMessage = $arrLanguageMessage['done_updated'];
} else {
$objEditItem->add();
$pMessage = $arrLanguageMessage['done_added'];
}
$objEditItem = new Queue();
} else {
$hasErrors = 1;
}
}
}
} else {
$hasErrors = 2;
}
}
示例14: getNextAvailableItem
public static function getNextAvailableItem($params)
{
$username = $params['username'];
$projectSlug = $params['projectSlug'];
$type = $params['type'];
$role = $type . "er";
$success = false;
$errorCode = '';
$db = Settings::getProtected('db');
$auth = Settings::getProtected('auth');
// Make sure we're authenticated as the user we say we are
$auth->forceAuthentication();
$loggedInUsername = $auth->getUsername();
if ($username != $loggedInUsername) {
$code = "not-authenticated-as-correct-user";
}
// Load user
$user = new User($username);
// Does this user belong to the project?
if (!$user->isMember($projectSlug, $role)) {
$code = "not-a-member";
}
// Does this user already have an item from this project?
if ($user->hasProjectItem($projectSlug)) {
$code = "has-unfinished-item";
}
// Load the user's queue
$userQueue = new Queue("user.{$type}:{$username}", false, array('include-removed' => true));
$userQueueItems = $userQueue->getItems();
// Load the project's queue
$queue = new Queue("project.{$type}:{$projectSlug}");
$queueItems = $queue->getItems();
// Go through the project queue and get the first item the user hasn't yet done
foreach ($queueItems as $item) {
if (!in_array($item, $userQueueItems)) {
$nextItem = $item;
break;
}
}
if (isset($nextItem) && $nextItem->item_id != -1) {
// Concatenate proofed transcripts
if ($type == 'review') {
// Get proofed transcripts for the new item
$transcripts = $db->loadItemTranscripts($nextItem->project_id, $nextItem->item_id, 'proof');
// Only diff them if there's more than one
if (count($transcripts) > 1) {
$transcriptText = Transcript::diff($transcripts);
} else {
$transcriptText = $transcripts[0]['transcript'];
}
// Only get the fields for the first transcript
$transcriptFields = $transcripts[0]['fields'];
// Create transcript and add to the database
$transcript = new Transcript();
$transcript->setText($transcriptText);
$transcript->setFields($transcriptFields);
$transcript->save(array('item' => $nextItem, 'status' => 'draft', 'type' => 'review'));
}
// Reload the user's queue, this time ignoring items they've already done
// Add it to the user's queue
$userQueue = new Queue("user.{$type}:{$username}", false);
$userQueue->add($nextItem);
$userQueue->save();
// Remove it from the project queue
$queue->remove($nextItem);
$queue->save();
$success = true;
$code = $nextItem->item_id;
} else {
$code = "no-item-available";
}
return array('status' => $success, 'code' => $code);
}