本文整理汇总了PHP中Dsc\System::addMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP System::addMessage方法的具体用法?PHP System::addMessage怎么用?PHP System::addMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dsc\System
的用法示例。
在下文中一共展示了System::addMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
public function process()
{
try {
$item = $this->getItem();
if (empty($item->id)) {
throw new \Exception('Invalid ID');
}
// if the task is already locked by another process, fail
if (!empty($item->locked_by)) {
throw new \Exception('Task locked by another process');
}
// lock the task to this process
$mongo_id = (string) new \MongoId();
$item->locked_by = $mongo_id;
$item->locked_at = time();
$item->store();
// run the task
$this->app->call($item->task, $item->parameters);
$task = $item->complete();
\Dsc\System::addMessage('Task completed', 'success');
} catch (\Exception $e) {
\Dsc\System::addMessage($e->getMessage(), 'error');
}
$this->app->reroute($this->list_route);
}
示例2: parseExistingCrontab
/**
* Parse an existing crontab
*
* @param Crontab $crontab
*
* @return CrontabFileHandler
*/
public function parseExistingCrontab(Crontab $crontab)
{
$result = exec($this->crontabCommand($crontab) . ' -l', $output, $retval);
if (!empty($output)) {
//\Dsc\System::addMessage(\Dsc\Debug::dump($output));
foreach ($output as $line) {
if (trim($line) == '') {
continue;
}
try {
$job = \Dsc\Cron\Job::parse($line);
$crontab->addJob($job);
} catch (\Exception $e) {
\Dsc\System::addMessage('Encountered error (' . $e->getMessage() . ') when parsing cron job: ' . $line, 'error');
}
}
}
/*
// parsing cron file
$process = new Process($this->crontabCommand($crontab).' -l');
$process->run();
foreach ($this->parseString($process->getOutput()) as $job) {
$crontab->addJob($job);
}
$this->error = $process->getErrorOutput();
*/
return $this;
}
示例3: update
public function update()
{
$id = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'cmd');
try {
$item = (new \Shop\Models\PaymentMethods())->setState('filter.identifier', $id)->getItem();
if (empty($item->id)) {
throw new \Exception('Payment Method not found');
}
$enabled = $this->app->get('POST.enabled');
if (strlen($enabled)) {
$item->enabled = false;
if (!empty($enabled)) {
$item->enabled = true;
}
}
if ($settings_array = (array) $this->inputfilter->clean($this->app->get('POST.settings'), 'array')) {
$item->settings = $settings_array;
}
$item->save();
\Dsc\System::addMessage('Settings updated', 'success');
$this->app->reroute('/admin/shop/payment-method/edit/' . $id);
} catch (\Exception $e) {
\Dsc\System::addMessage("Invalid Payment Method", 'error');
\Dsc\System::addMessage($e->getMessage(), 'error');
$this->app->reroute('/admin/shop/payment-methods');
return;
}
}
示例4: displayEdit
protected function displayEdit()
{
$item = $this->getItem();
if (empty($item) || $item->product_type != 'giftcards') {
\Dsc\System::addMessage('Item is not a giftcard', 'error');
$this->app->reroute('/admin/shop/giftcards');
}
$f3 = \Base::instance();
$flash = \Dsc\Flash::instance();
$variants = array();
if ($flashed_variants = $flash->old('variants')) {
foreach ($flashed_variants as $variant) {
$key = implode("-", (array) $variant['attributes']);
if (empty($key)) {
$key = $variant['id'];
}
$variants[$key] = $variant;
}
}
$old = array_merge($flash->get('old'), array('variants' => $variants));
$flash->store($old);
$model = new \Shop\Models\Categories();
$categories = $model->getList();
\Base::instance()->set('categories', $categories);
\Base::instance()->set('selected', 'null');
$all_tags = $this->getModel()->getTags();
\Base::instance()->set('all_tags', $all_tags);
$this->app->set('meta.title', 'Edit Gift Card | Shop');
$view = \Dsc\System::instance()->get('theme');
$view->event = $view->trigger('onDisplayShopProductsEdit', array('item' => $this->getItem(), 'tabs' => array(), 'content' => array()));
echo $view->render('Shop\\Admin\\Views::giftcards/edit.php');
}
示例5: beforeRoute
public function beforeRoute()
{
parent::beforeRoute();
$this->requireIdentity();
//TODO remove this hack, after ACL is finished
$user = $this->auth->getIdentity();
//TODO maybe the Role gets stored in the session to avoid one more DB query every load, or maybe none of this makes it to the future
if (!empty($user->id) && $this->app->get('safemode.enabled') && $user->id == $this->app->get('safemode.id')) {
return;
}
$role = $user->getRole();
if (empty($role->slug)) {
$this->auth->logout();
\Dsc\System::addMessage('Not Authorized');
$this->app->reroute('/admin/login');
}
if ($role->slug == 'root') {
//root always has access no farther checks needed
} elseif (empty($role->adminaccess)) {
//if this role is not admin and not given admin permissions
$this->auth->logout();
\Dsc\System::addMessage('Not Authorized');
$this->app->reroute('/admin/login');
}
}
示例6: create
public function create()
{
// load the product
// is it valid?
// is the user logged in?
// can the user review this product?
// try/catch the save
try {
$slug = $this->inputfilter->clean($this->app->get('PARAMS.slug'), 'cmd');
$item = $this->model('products')->setState('filter.slug', $slug)->getItem();
if (empty($item->id)) {
throw new \Exception();
}
} catch (\Exception $e) {
if ($this->app->get('AJAX')) {
return $this->outputJson($this->getJsonResponse(array('result' => false, 'error' => true, 'message' => 'Invalid Product')));
} else {
$this->app->error('404', 'Invalid Product');
return;
}
}
$redirect = '/shop/product/' . $item->slug;
if ($custom_redirect = \Dsc\System::instance()->get('session')->get('shop.product_review.redirect')) {
$redirect = $custom_redirect;
}
try {
$user = $this->getIdentity();
if (empty($user->id)) {
throw new \Exception('Must be logged in to post a review');
}
$canReview = \Shop\Models\ProductReviews::canUserReview($user, $item);
if ($canReview !== true) {
throw new \Exception($canReview);
}
$post = $this->app->get('POST');
$post['description'] = !empty($post['description']) ? nl2br($post['description']) : null;
$review = (new \Shop\Models\ProductReviews($post))->set('product_id', $item->id)->set('user_id', $user->id)->set('user_name', $user->first_name)->set('publication.status', 'draft')->save();
// Add images, using a model method
$review->addImages($this->app->get('FILES'));
$successMessage = 'Thanks for the review! It will be published following review by our moderators.';
if ($this->app->get('AJAX')) {
return $this->outputJson($this->getJsonResponse(array('result' => true, 'message' => $successMessage)));
} else {
\Dsc\System::addMessage($successMessage, 'success');
$this->app->reroute($redirect);
return;
}
} catch (\Exception $e) {
if ($this->app->get('AJAX')) {
return $this->outputJson($this->getJsonResponse(array('result' => false, 'error' => true, 'message' => $e->getMessage())));
} else {
\Dsc\System::addMessage($e->getMessage(), 'error');
$this->app->reroute($redirect);
return;
}
}
}
示例7: invalidate
public function invalidate()
{
try {
$script = $this->input->get('script', '', 'raw');
opcache_invalidate($script, true);
\Dsc\System::addMessage('Invalidated ' . $script, 'success');
} catch (\Exception $e) {
\Dsc\System::addMessage($e->getMessage(), 'error');
}
$this->app->reroute('/admin/cache/opcache');
}
示例8: index
/**
* Primary entry-point for the report.
* Supports GET & POST
*/
public function index()
{
$model = (new \Shop\Models\Coupons())->emptyState()->populateState();
try {
$paginated = $model->paginate();
} catch (\Exception $e) {
\Dsc\System::addMessage($e->getMessage(), 'error');
$this->app->reroute('/admin/shop/reports/' . $this->slug());
return;
}
$this->app->set('state', $model->getState());
$this->app->set('paginated', $paginated);
echo $this->theme->render('Shop/Reports/OrdersByCouponCode/Views::index.php');
}
示例9: emailSubmit
public function emailSubmit()
{
// Validate the form inputs
// for each email address, send the email
// track that this user sent these invitations
// redirect back to /invite-friends/email
$recip_input = $this->app->split($this->input->get('recipients', null, 'string'));
$recipients = array();
foreach ($recip_input as $recip) {
$recip = trim(strtolower($recip));
if (!empty($recip) && \Mailer\Factory::instance()->sender()->isEmailAddress($recip)) {
$recipients[] = $recip;
}
}
$data = array('sender_name' => $this->input->get('sender_name', null, 'string'), 'sender_email' => trim(strtolower($this->input->get('sender_email', null, 'string'))), 'recipients' => $recipients, 'message' => $this->input->get('message', null, 'string'));
try {
if (empty($data['sender_email']) || !\Mailer\Factory::instance()->sender()->isEmailAddress($data['sender_email'])) {
throw new \Exception('Your email address is invalid');
}
if (empty($data['sender_name'])) {
throw new \Exception('Your name is invalid');
}
if (empty($data['recipients'])) {
throw new \Exception('Invalid recipient email(s)');
}
if (empty($data['message'])) {
throw new \Exception('Invalid message');
}
foreach ($data['recipients'] as $key => $recipient) {
try {
(new \Affiliates\Models\Invites())->bind(array('affiliate_id' => $this->getIdentity()->id, 'sender_email' => $data['sender_email'], 'sender_name' => $data['sender_name'], 'recipient_email' => $recipient, 'message' => $data['message']))->set('__send_email', true)->save();
unset($data['recipients'][$key]);
\Dsc\System::addMessage('Invitation sent to ' . $recipient, 'success');
} catch (\Exception $e) {
\Dsc\System::addMessage('Invitation not sent to ' . $recipient, 'warning');
\Dsc\System::addMessage($e->getMessage(), 'warning');
}
}
} catch (\Exception $e) {
\Dsc\System::addMessage('Failed to send invitation(s)', 'error');
\Dsc\System::addMessage($e->getMessage(), 'error');
\Dsc\System::instance()->setUserState('invite_friends.email.flash_filled', true);
$this->flash->store($data);
$this->app->reroute('/affiliate/invite-friends/email');
}
$this->flash->store(array());
$this->app->reroute('/affiliate/invite-friends/email');
}
示例10: deleteCart
/**
* Purge expired carts
*
*/
public function deleteCart()
{
$cart_id = $this->app->get('PARAMS.cart_id');
$item = (new \Shop\Models\Carts())->setState('filter.id', $cart_id)->getItem();
if (!empty($item->id)) {
try {
$item->remove();
\Dsc\System::addMessage('Removed cart', 'success');
} catch (\Exception $e) {
\Dsc\System::addMessage('Could not remove cart', 'error');
\Dsc\System::addMessage($e->getMessage(), 'error');
}
} else {
\Dsc\System::addMessage('Invalid Cart ID', 'error');
}
$this->app->reroute('/admin/shop/reports/' . $this->slug());
}
示例11: refreshTotals
public function refreshTotals()
{
$customer = $this->getItem();
if (empty($customer->id)) {
\Dsc\System::addMessage('Invalid ID', 'error');
$this->app->reroute('/admin/shop/customers');
}
$customer->{'shop.total_spent'} = $customer->totalSpent(true);
$customer->{'shop.orders_count'} = $customer->ordersCount(true);
try {
$customer->save();
$customer->checkCampaigns();
\Dsc\System::addMessage('Totals refreshed', 'success');
} catch (\Exception $e) {
\Dsc\System::addMessage($e->getMessage(), 'error');
}
$this->app->reroute('/admin/shop/customer/read/' . $customer->id);
}
示例12: read
public function read()
{
try {
$key = $this->input->get('key', '', 'raw');
if (empty($key) || !apcu_exists($key)) {
throw new \Exception('Invalid Key: ' . $key);
}
$data = apcu_fetch($key, $success);
if (!$success) {
\Dsc\System::addMessage('Fetching data unsuccessful', 'error');
}
$this->app->set('key', $key);
$this->app->set('data', $data);
echo \Dsc\System::instance()->get('theme')->renderTheme('Admin/Views::cache/apcu_read.php');
} catch (\Exception $e) {
\Dsc\System::addMessage($e->getMessage(), 'error');
$this->app->reroute('/admin/cache/apcu');
}
}
示例13: filteredSearch
/**
* Gets paginated results from a source
*/
protected function filteredSearch()
{
$current_source = array('id' => 'invalid', 'title' => '');
$paginated = null;
$q = trim($this->input->get('q', null, 'default'));
try {
if (!empty($q)) {
$current_source = \Search\Models\Source::current();
$paginated = \Search\Models\Source::paginate($current_source, $q);
\Dsc\Activities::track('Performed Search', array('Search Term' => $q, 'Search Source' => $current_source['title'], 'page_number' => $paginated->current_page, 'app' => 'search'));
}
} catch (\Exception $e) {
\Dsc\System::addMessage($e->getMessage(), 'error');
}
$this->app->set('current_source', $current_source);
$this->app->set('paginated', $paginated);
$this->app->set('q', $q);
$this->app->set('meta.title', trim('Search ' . $current_source['title']));
echo $this->theme->render('Search/Site/Views::search/index.php');
}
示例14: email
public function email()
{
$f3 = \Base::instance();
$id = $this->inputfilter->clean($f3->get('PARAMS.id'), 'alnum');
$email = $this->inputfilter->clean($f3->get('GET.email'), 'string');
$templateModel = (new \Mailer\Models\Templates())->setState('filter.id', $id);
$this->app->set('id', $id);
$mailer = \Dsc\System::instance()->get('mailer');
try {
$template = $templateModel->getItem();
if (empty($template->id)) {
throw new \Exception();
}
//get the event
$event = (new \Mailer\Models\Events())->setState('filter.id', $template->event_id)->getItem();
$listenerEvent = 'mailerPreview';
$parts = explode('.', $event->event_name);
foreach ($parts as $part) {
$listenerEvent .= ucfirst($part);
}
//the preview event should return the variables
$results = \Dsc\System::instance()->trigger($listenerEvent);
$variables = $results->getArgument('variables');
$view = \Dsc\System::instance()->get('theme');
if (!empty($variables)) {
$contents = \Mailer\Factory::getEmailContents($event->event_name, $variables);
$mailer->sendEvent($email, $contents);
\Dsc\System::addMessage('Sent Email to : ' . $email . '', 'success');
$this->app->set('contents', $contents);
echo $view->renderView('Mailer/Admin/Views::preview/index.php');
} else {
\Dsc\System::addMessage('No email sent', 'error');
$view = \Dsc\System::instance()->get('theme');
$this->app->set('event', $listenerEvent);
echo $view->renderView('Mailer/Admin/Views::preview/notsupported.php');
}
} catch (\Exception $e) {
\Dsc\System::instance()->addMessage("Invalid Item: " . $e->getMessage(), 'error');
return;
}
}
示例15: products
public function products()
{
$model = (new \Shop\Models\Products())->populateState();
$id = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'alnum');
try {
$collection = (new \Shop\Models\Collections())->setState('filter.id', $id)->getItem();
if (empty($collection->id)) {
throw new \Exception('Invalid Collection');
}
$conditions = \Shop\Models\Collections::getProductQueryConditions($collection->id);
if (!$model->getState('list.limit')) {
$model->setState('list.limit', '100');
}
$paginated = $model->setParam('conditions', $conditions)->setState('list.sort', array(array('collections.' . $id . '.ordering' => 1)))->paginate();
$this->app->set('paginated', $paginated);
$this->app->set('collection', $collection);
$this->app->set('state', $model->getState());
} catch (\Exception $e) {
\Dsc\System::addMessage((string) $e, 'error');
$this->app->reroute('/admin/shop/collections');
}
$this->app->set('meta.title', 'Manually Sort Products in Collection | Shop');
echo $this->theme->renderTheme('Shop/Admin/Views::collections/products.php');
}