本文整理汇总了PHP中Pimcore\Model\Object\Service类的典型用法代码示例。如果您正苦于以下问题:PHP Service类的具体用法?PHP Service怎么用?PHP Service使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($offerClass, $offerItemClass, $parentFolderPath)
{
$this->offerClass = $offerClass;
$this->offerItemClass = $offerItemClass;
$this->parentFolderPath = strftime($parentFolderPath, time());
\Pimcore\Model\Object\Service::createFolderByPath($this->parentFolderPath);
}
示例2: copyAction
public function copyAction()
{
$success = false;
$message = "";
$sourceId = intval($this->getParam("sourceId"));
$source = Object::getById($sourceId);
$session = Tool\Session::get("pimcore_copy");
$targetId = intval($this->getParam("targetId"));
if ($this->getParam("targetParentId")) {
$sourceParent = Object::getById($this->getParam("sourceParentId"));
// this is because the key can get the prefix "_copy" if the target does already exists
if ($session->{$this->getParam("transactionId")}["parentId"]) {
$targetParent = Object::getById($session->{$this->getParam("transactionId")}["parentId"]);
} else {
$targetParent = Object::getById($this->getParam("targetParentId"));
}
$targetPath = preg_replace("@^" . $sourceParent->getFullPath() . "@", $targetParent . "/", $source->getPath());
$target = Object::getByPath($targetPath);
} else {
$target = Object::getById($targetId);
}
if ($target->isAllowed("create")) {
$source = Object::getById($sourceId);
if ($source != null) {
try {
if ($this->getParam("type") == "child") {
$newObject = $this->_objectService->copyAsChild($target, $source);
$session->{$this->getParam("transactionId")}["idMapping"][(int) $source->getId()] = (int) $newObject->getId();
// this is because the key can get the prefix "_copy" if the target does already exists
if ($this->getParam("saveParentId")) {
$session->{$this->getParam("transactionId")}["parentId"] = $newObject->getId();
Tool\Session::writeClose();
}
} else {
if ($this->getParam("type") == "replace") {
$this->_objectService->copyContents($target, $source);
}
}
$success = true;
} catch (\Exception $e) {
\Logger::err($e);
$success = false;
$message = $e->getMessage() . " in object " . $source->getFullPath() . " [id: " . $source->getId() . "]";
}
} else {
\Logger::error("could not execute copy/paste, source object with id [ {$sourceId} ] not found");
$this->_helper->json(array("success" => false, "message" => "source object not found"));
}
} else {
\Logger::error("could not execute copy/paste because of missing permissions on target [ " . $targetId . " ]");
$this->_helper->json(array("error" => false, "message" => "missing_permission"));
}
$this->_helper->json(array("success" => $success, "message" => $message));
}
示例3: prepare
/**
* Prepare a Cart
*
* @return CoreShopCart
* @throws \Exception
*/
public static function prepare()
{
$cartsFolder = Service::createFolderByPath("/coreshop/carts/" . date("Y/m/d"));
$cart = CoreShopCart::create();
$cart->setKey(uniqid());
$cart->setParent($cartsFolder);
$cart->setPublished(true);
if (Tool::getUser() instanceof CoreShopUser) {
$cart->setUser(Tool::getUser());
}
$cart->save();
return $cart;
}
示例4: createPayment
/**
* Create a new Payment
*
* @param Payment $provider
* @param $amount
* @return Object\CoreShopPayment
* @throws \Exception
*/
public function createPayment(Payment $provider, $amount)
{
$payment = new Object\CoreShopPayment();
$payment->setKey(uniqid());
$payment->setPublished(true);
$payment->setParent(Object\Service::createFolderByPath($this->getFullPath() . "/payments/"));
$payment->setAmount($amount);
$payment->setTransactionIdentifier(uniqid());
$payment->setProvider($provider->getIdentifier());
$payment->save();
$this->addPayment($payment);
return $payment;
}
示例5: getById
/**
* @param $id
* @return mixed|null|CustomLayout
* @throws \Exception
*/
public static function getById($id)
{
if ($id === null) {
throw new \Exception("CustomLayout id is null");
}
$cacheKey = "customlayout_" . $id;
try {
$customLayout = \Zend_Registry::get($cacheKey);
if (!$customLayout) {
throw new \Exception("Custom Layout in registry is null");
}
} catch (\Exception $e) {
try {
$customLayout = new self();
$customLayout->getDao()->getById($id);
Object\Service::synchronizeCustomLayout($customLayout);
\Zend_Registry::set($cacheKey, $customLayout);
} catch (\Exception $e) {
\Logger::error($e);
return null;
}
}
return $customLayout;
}
示例6: getValueForFieldName
/**
* @param string $key
* @return mixed
*/
public function getValueForFieldName($key)
{
if (isset($this->{$key})) {
return $this->{$key};
} elseif ($this->getClass()->getFieldDefinition($key) instanceof Model\Object\ClassDefinition\Data\CalculatedValue) {
$value = new Model\Object\Data\CalculatedValue($key);
$value = Service::getCalculatedFieldValue($this, $value);
return $value;
}
return false;
}
示例7: findAction
/**
* @return void
*/
public function findAction()
{
$user = $this->getUser();
$query = $this->getParam("query");
if ($query == "*") {
$query = "";
}
$query = str_replace("%", "*", $query);
$types = explode(",", $this->getParam("type"));
$subtypes = explode(",", $this->getParam("subtype"));
$classnames = explode(",", $this->getParam("class"));
if ($this->getParam("type") == "object" && is_array($classnames) && empty($classnames[0])) {
$subtypes = array("object", "variant", "folder");
}
$offset = intval($this->getParam("start"));
$limit = intval($this->getParam("limit"));
$offset = $offset ? $offset : 0;
$limit = $limit ? $limit : 50;
$searcherList = new Data\Listing();
$conditionParts = array();
$db = \Pimcore\Db::get();
//exclude forbidden assets
if (in_array("asset", $types)) {
if (!$user->isAllowed("assets")) {
$forbiddenConditions[] = " `type` != 'asset' ";
} else {
$forbiddenAssetPaths = Element\Service::findForbiddenPaths("asset", $user);
if (count($forbiddenAssetPaths) > 0) {
for ($i = 0; $i < count($forbiddenAssetPaths); $i++) {
$forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")";
}
$forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths);
}
}
}
//exclude forbidden documents
if (in_array("document", $types)) {
if (!$user->isAllowed("documents")) {
$forbiddenConditions[] = " `type` != 'document' ";
} else {
$forbiddenDocumentPaths = Element\Service::findForbiddenPaths("document", $user);
if (count($forbiddenDocumentPaths) > 0) {
for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) {
$forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")";
}
$forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths);
}
}
}
//exclude forbidden objects
if (in_array("object", $types)) {
if (!$user->isAllowed("objects")) {
$forbiddenConditions[] = " `type` != 'object' ";
} else {
$forbiddenObjectPaths = Element\Service::findForbiddenPaths("object", $user);
if (count($forbiddenObjectPaths) > 0) {
for ($i = 0; $i < count($forbiddenObjectPaths); $i++) {
$forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")";
}
$forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths);
}
}
}
if ($forbiddenConditions) {
$conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")";
}
if (!empty($query)) {
$queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )";
// the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index
// if the query is numeric the user might want to search by id
//if(is_numeric($query)) {
//$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )";
//}
$conditionParts[] = $queryCondition;
}
//For objects - handling of bricks
$fields = array();
$bricks = array();
if ($this->getParam("fields")) {
$fields = $this->getParam("fields");
foreach ($fields as $f) {
$parts = explode("~", $f);
if (substr($f, 0, 1) == "~") {
// $type = $parts[1];
// $field = $parts[2];
// $keyid = $parts[3];
// key value, ignore for now
} else {
if (count($parts) > 1) {
$bricks[$parts[0]] = $parts[0];
}
}
}
}
// filtering for objects
if ($this->getParam("filter") && $this->getParam("class")) {
$class = Object\ClassDefinition::getByName($this->getParam("class"));
//.........这里部分代码省略.........
示例8: findAction
/**
* @return void
*/
public function findAction()
{
$user = $this->getUser();
$query = $this->getParam("query");
if ($query == "*") {
$query = "";
}
$query = str_replace("%", "*", $query);
$query = preg_replace("@([^ ])\\-@", "\$1 ", $query);
$types = explode(",", $this->getParam("type"));
$subtypes = explode(",", $this->getParam("subtype"));
$classnames = explode(",", $this->getParam("class"));
if ($this->getParam("type") == "object" && is_array($classnames) && empty($classnames[0])) {
$subtypes = ["object", "variant", "folder"];
}
$offset = intval($this->getParam("start"));
$limit = intval($this->getParam("limit"));
$offset = $offset ? $offset : 0;
$limit = $limit ? $limit : 50;
$searcherList = new Data\Listing();
$conditionParts = [];
$db = \Pimcore\Db::get();
//exclude forbidden assets
if (in_array("asset", $types)) {
if (!$user->isAllowed("assets")) {
$forbiddenConditions[] = " `type` != 'asset' ";
} else {
$forbiddenAssetPaths = Element\Service::findForbiddenPaths("asset", $user);
if (count($forbiddenAssetPaths) > 0) {
for ($i = 0; $i < count($forbiddenAssetPaths); $i++) {
$forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")";
}
$forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths);
}
}
}
//exclude forbidden documents
if (in_array("document", $types)) {
if (!$user->isAllowed("documents")) {
$forbiddenConditions[] = " `type` != 'document' ";
} else {
$forbiddenDocumentPaths = Element\Service::findForbiddenPaths("document", $user);
if (count($forbiddenDocumentPaths) > 0) {
for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) {
$forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")";
}
$forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths);
}
}
}
//exclude forbidden objects
if (in_array("object", $types)) {
if (!$user->isAllowed("objects")) {
$forbiddenConditions[] = " `type` != 'object' ";
} else {
$forbiddenObjectPaths = Element\Service::findForbiddenPaths("object", $user);
if (count($forbiddenObjectPaths) > 0) {
for ($i = 0; $i < count($forbiddenObjectPaths); $i++) {
$forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")";
}
$forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths);
}
}
}
if ($forbiddenConditions) {
$conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")";
}
if (!empty($query)) {
$queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )";
// the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index
// if the query is numeric the user might want to search by id
//if(is_numeric($query)) {
//$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )";
//}
$conditionParts[] = $queryCondition;
}
//For objects - handling of bricks
$fields = [];
$bricks = [];
if ($this->getParam("fields")) {
$fields = $this->getParam("fields");
foreach ($fields as $f) {
$parts = explode("~", $f);
if (substr($f, 0, 1) == "~") {
// $type = $parts[1];
// $field = $parts[2];
// $keyid = $parts[3];
// key value, ignore for now
} elseif (count($parts) > 1) {
$bricks[$parts[0]] = $parts[0];
}
}
}
// filtering for objects
if ($this->getParam("filter") && $this->getParam("class")) {
$class = Object\ClassDefinition::getByName($this->getParam("class"));
// add Localized Fields filtering
//.........这里部分代码省略.........
示例9: getObjectConcreteById
/**
* @param $id
* @throws \Exception
*/
public function getObjectConcreteById($id)
{
try {
$object = Object::getById($id);
if ($object instanceof Object\Concrete) {
// load all data (eg. lazy loaded fields like multihref, object, ...)
Object\Service::loadAllObjectFields($object);
$apiObject = Webservice\Data\Mapper::map($object, "\\Pimcore\\Model\\Webservice\\Data\\Object\\Concrete\\Out", "out");
return $apiObject;
}
throw new \Exception("Object with given ID (" . $id . ") does not exist.");
} catch (\Exception $e) {
\Logger::error($e);
throw $e;
}
}
示例10: getDataForEditmode
/**
* @see Object\ClassDefinition\Data::getDataForEditmode
* @param array $data
* @param null|Model\Object\AbstractObject $object
* @return array
*/
public function getDataForEditmode($data, $object = null)
{
$return = array();
$visibleFieldsArray = explode(",", $this->getVisibleFields());
$gridFields = (array) $visibleFieldsArray;
// add data
if (is_array($data) && count($data) > 0) {
foreach ($data as $metaObject) {
$object = $metaObject->getObject();
if ($object instanceof Object\Concrete) {
$columnData = Object\Service::gridObjectData($object, $gridFields);
foreach ($this->getColumns() as $c) {
$getter = "get" . ucfirst($c['key']);
$columnData[$c['key']] = $metaObject->{$getter}();
}
$return[] = $columnData;
}
}
}
return $return;
}
示例11: getValueFromParent
/**
* @return mixed
*/
public function getValueFromParent($key)
{
$parent = Object\Service::hasInheritableParentObject($this->getObject());
if (!empty($parent)) {
$containerGetter = "get" . ucfirst($this->fieldname);
$brickGetter = "get" . ucfirst($this->getType());
$getter = "get" . ucfirst($key);
if ($parent->{$containerGetter}()->{$brickGetter}()) {
return $parent->{$containerGetter}()->{$brickGetter}()->{$getter}();
}
}
return null;
}
示例12: objectbrickListAction
public function objectbrickListAction()
{
$list = new Object\Objectbrick\Definition\Listing();
$list = $list->load();
if ($this->hasParam("class_id") && $this->hasParam("field_name")) {
$filteredList = [];
$classId = $this->getParam("class_id");
$fieldname = $this->getParam("field_name");
foreach ($list as $type) {
/** @var $type Object\Objectbrick\Definition */
$clsDefs = $type->getClassDefinitions();
if (!empty($clsDefs)) {
foreach ($clsDefs as $cd) {
if ($cd["classname"] == $classId && $cd["fieldname"] == $fieldname) {
$filteredList[] = $type;
continue;
}
}
}
$layout = $type->getLayoutDefinitions();
Object\Service::enrichLayoutDefinition($layout);
$type->setLayoutDefinitions($layout);
}
$list = $filteredList;
}
$returnValueContainer = new Model\Tool\Admin\EventDataContainer($list);
\Pimcore::getEventManager()->trigger("admin.class.objectbrickList.preSendData", $this, ["returnValueContainer" => $returnValueContainer, "objectId" => $this->getParam('object_id')]);
$this->_helper->json(["objectbricks" => $list]);
}
示例13: getDataForEditmode
/**
* @see Object_Class_Data::getDataForEditmode
* @param float $data
* @return float
*/
public function getDataForEditmode($data, $object = null)
{
if ($data instanceof Model\Object\Data\CalculatedValue) {
$data = Model\Object\Service::getCalculatedFieldValueForEditMode($object, $data);
}
return $data;
}
示例14: adminElementGetPreSendData
/**
* Fired before information is sent back to the admin UI about an element
* @param \Zend_EventManager_Event $e
* @throws \Exception
*/
public static function adminElementGetPreSendData($e)
{
$element = self::extractElementFromEvent($e);
$returnValueContainer = $e->getParam('returnValueContainer');
$data = $returnValueContainer->getData();
//create a new namespace for WorkflowManagement
//set some defaults
$data['workflowManagement'] = ['hasWorkflowManagement' => false];
if (Workflow\Manager::elementCanAction($element)) {
$data['workflowManagement']['hasWorkflowManagement'] = true;
//see if we can change the layout
$currentUser = Admin::getCurrentUser();
$manager = Workflow\Manager\Factory::getManager($element, $currentUser);
$data['workflowManagement']['workflowName'] = $manager->getWorkflow()->getName();
//get the state and status
$state = $manager->getElementState();
$data['workflowManagement']['state'] = $manager->getWorkflow()->getStateConfig($state);
$status = $manager->getElementStatus();
$data['workflowManagement']['status'] = $manager->getWorkflow()->getStatusConfig($status);
if ($element instanceof ConcreteObject) {
$workflowLayoutId = $manager->getObjectLayout();
//check for !is_null here as we might want to specify 0 in the workflow config
if (!is_null($workflowLayoutId)) {
//load the new layout into the object container
$validLayouts = Object\Service::getValidLayouts($element);
//check that the layout id is valid before trying to load
if (!empty($validLayouts)) {
//todo check user permissions again
if ($validLayouts && $validLayouts[$workflowLayoutId]) {
$customLayout = ClassDefinition\CustomLayout::getById($workflowLayoutId);
$customLayoutDefinition = $customLayout->getLayoutDefinitions();
Object\Service::enrichLayoutDefinition($customLayoutDefinition, $e->getParam('object'));
$data["layout"] = $customLayoutDefinition;
}
}
}
}
}
$returnValueContainer->setData($data);
}
示例15: import
/**
* @param $shopConfigurations Object\OnlineShopConfiguration
*/
public function import($shopConfigurations)
{
if ($shopConfigurations && !is_array($shopConfigurations)) {
$shopConfigurations = array($shopConfigurations);
}
$pageSize = 20;
$page = 0;
/** @var $shopConfiguration Object\OnlineShopConfiguration */
foreach ($shopConfigurations as $shopConfiguration) {
$importDirectory = $shopConfiguration->getTrustedShopReviewsimportDirectory();
$startTime = time();
if ($this->logToConsole) {
echo "Importing reviews for " . $shopConfiguration->getFullPath() . " ...\n";
}
/** @var $startDate Pimcore\Date */
$startDate = $shopConfiguration->getLastSync();
while (true) {
if ($this->logToConsole) {
echo "Page=" . $page . "\n";
}
$uri = "https://%s:%s@api.trustedshops.com/rest/restricted/v2/shops/%s/reviews.json?page=" . $page . "&size=" . $pageSize;
if ($startDate) {
$uri .= "&startDate=" . date('Y-m-d', $startDate->getTimestamp() - 3600 * 24 * 30);
//get ratins from last 30 days - for some reasons trusted shop sometimes dont show all ratings imediately
}
$uri = sprintf($uri, $shopConfiguration->getTrustedShopUser(), $shopConfiguration->getTrustedShopPassword(), $shopConfiguration->getTrustedShopKey());
if ($this->logToConsole) {
echo $uri . "\n";
}
$this->client->setUri($uri);
$result = $this->client->request();
if ($result->getStatus() != 200) {
$this->logger->error("Status code " . $result->getStatus(), null, null, self::COMPONENT);
throw new \Exception("Status Code: " . $result->getStatus());
}
$body = $result->getBody();
$data = json_decode($body);
if (!$data) {
$this->logger->error("Could not decode data " . $body, null, null, self::COMPONENT);
throw new \Exception("Could not decode data");
}
$response = $data->response;
$data = $response->data;
$shop = $data->shop;
if ($shop->tsId != $shopConfiguration->getTrustedShopKey()) {
$this->logger->error("Tsid mismatch", null, null, self::COMPONENT);
throw new \Exception("Tsid mismatch");
}
$reviews = $shop->reviews;
foreach ((array) $reviews as $review) {
$uid = $review->UID;
$comment = $review->comment;
$criterias = $review->criteria;
$consumerEmail = $review->consumerEmail;
$mark = $review->mark;
$markDescription = $review->markDescription;
$orderReference = $review->orderReference;
$changeDate = $review->changeDate;
$creationDate = $review->creationDate;
$confirmationDate = $review->confirmationDate;
$changeDate = $changeDate ? strtotime($changeDate) : 0;
$creationDate = $creationDate ? strtotime($creationDate) : 0;
$confirmationDate = $confirmationDate ? strtotime($confirmationDate) : 0;
$fc = new Object\Fieldcollection();
foreach ($criterias as $criteria) {
$mark = $criteria->mark;
$criteriaMarkDescription = $criteria->markDescription;
$type = $criteria->type;
$item = new Object\Fieldcollection\Data\TrustedShopCriteria();
$item->setMark($mark);
$item->setMarkDescription($criteriaMarkDescription);
$item->setCriteriaType($type);
$fc->add($item);
}
$reviewObject = $this->getReview($shopConfiguration, $uid, $consumerEmail, $creationDate);
$reviewObject->setShopConfig($shopConfiguration);
$reviewObject->setUid($uid);
$reviewObject->setComment($comment);
$reviewObject->setConsumerEmail($consumerEmail);
$reviewObject->setReviewConfirmationDate(new Pimcore\Date($confirmationDate));
$reviewObject->setReviewCreationDate(new Pimcore\Date($creationDate));
$reviewObject->setReviewChangeDate(new Pimcore\Date($changeDate));
$reviewObject->setMark($mark);
$reviewObject->setMarkDescription($markDescription);
$reviewObject->setCritera($fc);
$reviewObject->setOrderReference($orderReference);
if (!$creationDate) {
$path = '/unknown';
} else {
$path = '/' . date('Y/m/d', $creationDate);
}
$path = $importDirectory . $path;
$reviewObject->setParent(Object\Service::createFolderByPath($path));
$reviewObject->save();
if ($this->logToConsole) {
echo "Saved review " . $reviewObject->getId() . " " . $reviewObject->getFullPath() . "\n";
}
//.........这里部分代码省略.........