/** * Preview the data in an uploaded file * * @throws \Exception */ public function preview() { try { $id = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'alnum'); $item = (new \Dsc\Mongo\Collections\Assets())->setState('filter.id', $id)->getItem(); if (empty($item->id)) { throw new \Exception('Invalid Item'); } $file = new \SplTempFileObject(); // TODO Push this to the Assets model switch ($item->storage) { case "s3": $contents = @file_get_contents($item->url); break; case "gridfs": default: $length = $item->length; $chunkSize = $item->chunkSize; $chunks = ceil($length / $chunkSize); $collChunkName = $item->collectionNameGridFS() . ".chunks"; $collChunks = $item->getDb()->{$collChunkName}; $contents = null; for ($i = 0; $i < $chunks; $i++) { $chunk = $collChunks->findOne(array("files_id" => $item->_id, "n" => $i)); $contents .= $chunk["data"]->bin; } break; } $file->fwrite($contents); $reader = new \Ddeboer\DataImport\Reader\CsvReader($file, ","); $reader->setHeaderRowNumber(0); $reader->rewind(); } catch (\Exception $e) { \Dsc\System::instance()->addMessage($e->getMessage(), 'error'); $this->app->reroute('/admin/redirect/import'); return; } $first_row = $reader->current(); $preview = \Dsc\Debug::dump($first_row); $this->app->set('preview', $preview); $this->app->set('count', count($reader)); $this->app->set('item', $item); echo $this->theme->render('Redirect/Admin/Views::importer/preview.php'); }
foreach ($item->history as $history) { ?> <li class="list-group-item"> <div class="row"> <div class="col-md-2"> <?php echo \Dsc\ArrayHelper::get($history, 'created.local'); ?> </div> <div class="col-md-10"> <?php $dump = $history; unset($dump['created']); ?> <?php echo \Dsc\Debug::dump($dump); ?> </div> </div> </li> <?php } ?> </ul> </div> </div> <!-- /.col-md-10 --> </div>
</b> failed to save. </h4> </div> <div class="col-md-6"> <?php if (!empty($errors)) { ?> <h3>Errors:</h3> <div class="list-group"> <div class="list-group-item list-group-item-warning"> These errors were encountered: </div> <?php foreach ($errors as $error) { ?> <div class="list-group-item list-group-item-danger"> <?php echo \Dsc\Debug::dump($error); ?> </div> <?php } ?> </div> <?php } ?> </div> </div>
/** * This method handles document-by-document * * @param $selected_model Selected * model to be updated * @param $where_part Array * condition operations * @param $update_data Array * update operations * @param $collection Collection * be updated * * @return Result of this operation */ private function handleDocumentByDocument($selected_model, $where_part, $update_data, $collection) { $params = array("dataset" => \Base::instance()->get("REQUEST")); $res = array('records' => 0, 'error' => false, 'error_msg' => ""); $model = $selected_model->getModel(); $cursor = $collection->find($where_part); $num = 0; foreach ($cursor as $doc) { $model->bind($doc); foreach ($update_data as $op) { $op[0]->setIndex($op[2]); $params['document'] = $model; $res_op = $op[0]->getUpdateClause($op[1], $params); // skip clauses which couldnt create a where condition if ($res_op == null) { continue; } else { $model = $res_op; } } $collection->update(array('_id' => new \MongoId((string) $model->get('id'))), $model->cast(), array('upsert' => true, 'multiple' => false)); $stats = \Dsc\System::instance()->get("mongo")->lastError(); if (empty($stats['err']) && isset($stats['ok']) && $stats['ok'] == 1) { $res['records']++; } else { $res['error'] = true; $res['error_msg'] .= "\n" . \Dsc\Debug::dump($stats); } } return $res; }
/** * Checks if the user has access to the requested resource and method pair * * @param unknown $resource * @param unknown $method * @param string $require_identity * @return boolean */ public function checkAccess($resource, $method, $require_identity = true) { $f3 = \Base::instance(); $identity = $this->getIdentity(); if ($require_identity) { $this->requireIdentity(); } // TODO If the user has multiple roles (is that possible) then loop through them if ($hasAccess = \Dsc\System::instance()->get('acl')->isAllowed($identity->role, $resource, $method)) { return $this; } if (\Base::instance()->get('DEBUG')) { \Dsc\System::addMessage(\Dsc\Debug::dump('Debugging is enabled := $role: ' . $identity->role . ", " . '$resource: ' . $resource . ", " . '$method: ' . $method)); } \Dsc\System::addMessage('You do not have access to perform that action.', 'error'); $global_app_name = strtolower($f3->get('APP_NAME')); switch ($global_app_name) { case "admin": \Base::instance()->reroute('/admin'); break; case "site": \Base::instance()->reroute('/'); break; default: throw new \Exception('No access and unkown application'); break; } return false; }
<div class="row"> <div class="col-md-2"> <h3>API</h3> </div> <!-- /.col-md-2 --> <div class="col-md-10"> <div class="form-group"> <label>Resource Design</label> <code><?php echo \Dsc\Debug::dump(json_encode($item->apiResourceDesign(), JSON_PRETTY_PRINT)); ?> </code> </div> <!-- /.form-group --> </div> <!-- /.col-md-10 --> </div> <!-- /.row -->
/** * Completes an order. * * Trigger this on newly-made orders to perform tasks such as: * Sending an email to the customer * Updating available product quantities. * Deduct giftcard.amount from any giftcards * Deduct credit.total from customer credit balance * * This does NOT do the following: * Enabling file downloads * Enabling subscriptions * as those would be triggered upon order fulfillment == $this->fulfill() * * Trigger a Listener event to notify observers */ public function accept() { // #. Update quantities foreach ($this->items as $item) { $found = false; $product = (new \Shop\Models\Products())->setState('filter.id', $item['product_id'])->getItem(); if (!empty($product->id) && (string) $product->id == (string) $item['product_id']) { foreach ($product->variants as $key => $variant) { if ((string) $variant['id'] == (string) $item['variant_id']) { $found = true; $product->{'variants.' . $key . '.quantity'} = $variant['quantity'] - 1; break; } } if ($found) { $product->save(); } } else { $message = 'Could not update variant quantities -- Invalid Product ID'; $message .= \Dsc\Debug::dump($item); $this->log($message); } } // #. Add an email to the Mailer if ($this->user_email) { $this->sendEmailNewOrder(); } $this->sendEmailNewOrderNotifications(); // #. Increase total spent and orders count $this->updateCustomerTotals(); // TODO #. Increase hit counts on coupons used in order, https://github.com/dioscouri/f3-shop/issues/90 // #. Decrease value of any used gift certificates $this->redeemGiftCards(); // #. Add a negative credit record for historical purposes $this->deductCredit(); // #. queue emails requesting product reviews \Shop\Models\ProductReviews::queueEmailForOrder($this); // trigger event $this->__accept_event = \Dsc\System::instance()->trigger('onShopAcceptOrder', array('order' => $this)); return $this; }
} } ?> </ul> <div class="tab-content padding-10"> <div class="tab-pane active" id="tab-basics"> <?php //echo $this->renderLayout('Mailer/Admin/Views::emails/fields_basics.php'); ?> <?php echo \Dsc\Debug::dump($item); ?> </div> <!-- /.tab-pane --> <?php if (!empty($this->event)) { foreach ((array) $this->event->getArgument('content') as $key => $content) { ?> <div class="tab-pane" id="tab-<?php echo $key; ?> "> <?php echo $content;
<div class="row"> <div class="col-md-2"> <h3>Data Dump</h3> </div> <!-- /.col-md-2 --> <div class="col-md-10"> <div class="form-group"> <?php echo \Dsc\Debug::dump($item->cast()); ?> </div> <!-- /.form-group --> </div> <!-- /.col-md-10 --> </div> <!-- /.row -->
<?php echo $key; ?> </div> <div class="list-group-item"> TTL: <?php echo $ttl; ?> </div> <div class="list-group-item"> Created: <?php echo date('Y-m-d H:i:s', $time); ?> </div> <div class="list-group-item"> Value: <?php echo \Dsc\Debug::dump($val); ?> </div> </div>