Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @param int $attributeId
  * @param int $version
  *
  * @throw InvalidArgumentException if the attribute cannot be loaded
  */
 public function __construct($attributeId, $version)
 {
     $this->attribute = eZContentObjectAttribute::fetch($attributeId, $version);
     if (!$this->attribute instanceof eZContentObjectAttribute) {
         throw new InvalidArgumentException(ezpI18n::tr('extension/ezjscore/ajaxuploader', 'Provided attribute id and version number are invalid.'));
     }
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $http = eZHTTPTool::instance();
     //  @todo change hasVariable to hasPostVariable
     if (!$http->hasVariable('key') || !$http->hasVariable('image_id') || !$http->hasVariable('image_version') || !$http->hasVariable('history_version')) {
         //  @todo manage errors
         return;
     }
     $this->key = $http->variable('key');
     $this->image_id = $http->variable('image_id');
     $this->image_version = $http->variable('image_version');
     $this->history_version = $http->variable('history_version');
     // retieve the attribute image
     $this->original_image = eZContentObjectAttribute::fetch($this->image_id, $this->image_version)->attribute('content');
     if ($this->original_image === null) {
         //  @todo manage error (the image_id does not match any existing image)
         return;
     }
     // we could store the images in var/xxx/cache/public
     $this->working_folder = eZSys::cacheDirectory() . "/public/ezie/" . $this->key;
     $this->image_path = $this->working_folder . "/" . $this->history_version . "-" . $this->original_image->attributeFromOriginal('filename');
     // check if file exists (that will mean the data sent is correct)
     $absolute_image_path = eZSys::rootDir() . "/" . $this->image_path;
     $handler = eZClusterFileHandler::instance();
     if (!$handler->fileExists($this->image_path)) {
         // @todo manage error
         return;
     }
     $this->prepare_region();
 }
 /**
  * Rate content object attribute id
  *
  * @param array $args ( 0 => contentobjectattribute_id,  1 => contentobject_version, 2 => rating )
  * @return array
  */
 public static function rate($args)
 {
     $ret = array('id' => 0, 'rated' => false, 'already_rated' => false, 'stats' => false);
     if (isset($args[0])) {
         $ret['id'] = $args[0];
     }
     if (!isset($args[2]) || !is_numeric($args[0]) || !is_numeric($args[1]) || !is_numeric($args[2]) || $args[2] > 5 || $args[2] < 1) {
         return $ret;
     }
     // Provide extra session protection on 4.1 (not possible on 4.0) by expecting user
     // to have an existing session (new session = mostlikely a spammer / hacker trying to manipulate rating)
     if (class_exists('eZSession') && eZSession::userHasSessionCookie() !== true) {
         return $ret;
     }
     // Return if parameters are not valid attribute id + version numbers
     $contentobjectAttribute = eZContentObjectAttribute::fetch($ret['id'], $args[1]);
     if (!$contentobjectAttribute instanceof eZContentObjectAttribute) {
         return $ret;
     }
     // Return if attribute is not a rating attribute
     if ($contentobjectAttribute->attribute('data_type_string') !== ezsrRatingType::DATA_TYPE_STRING) {
         return $ret;
     }
     // Return if rating has been disabled on current attribute
     if ($contentobjectAttribute->attribute('data_int')) {
         return $ret;
     }
     // Return if user does not have access to object
     $contentobject = $contentobjectAttribute->attribute('object');
     if (!$contentobject instanceof eZContentObject || !$contentobject->attribute('can_read')) {
         return $ret;
     }
     $rateDataObj = ezsrRatingDataObject::create(array('contentobject_id' => $contentobjectAttribute->attribute('contentobject_id'), 'contentobject_attribute_id' => $ret['id'], 'rating' => $args[2]));
     $proiorRating = $rateDataObj->userHasRated(true);
     if ($proiorRating === true) {
         $ret['already_rated'] = true;
     } else {
         if ($proiorRating instanceof ezsrRatingDataObject) {
             $rateDataObj = $proiorRating;
             $rateDataObj->setAttribute('rating', $args[2]);
             $ret['already_rated'] = true;
             $proiorRating = false;
             // just to reuse code bellow
         }
     }
     if (!$proiorRating) {
         $rateDataObj->store();
         $avgRateObj = $rateDataObj->getAverageRating();
         $avgRateObj->updateFromRatingData();
         $avgRateObj->store();
         eZContentCacheManager::clearContentCacheIfNeeded($rateDataObj->attribute('contentobject_id'));
         $ret['rated'] = true;
         $ret['stats'] = array('rating_count' => $avgRateObj->attribute('rating_count'), 'rating_average' => $avgRateObj->attribute('rating_average'), 'rounded_average' => $avgRateObj->attribute('rounded_average'));
     }
     return $ret;
 }
 /**
  * Update blocks order based on AJAX data send after D&D operation is finished
  *
  * @param mixed $args
  * @return array
  */
 public static function updateblockorder($args)
 {
     $http = eZHTTPTool::instance();
     $contentObjectAttributeID = (int) $http->postVariable('contentobject_attribute_id', 0);
     $version = (int) $http->postVariable('version', 0);
     $zoneID = $http->postVariable('zone', '');
     $blockOrder = $http->postVariable('block_order', array());
     $contentObjectAttribute = eZContentObjectAttribute::fetch($contentObjectAttributeID, $version);
     if (!$contentObjectAttribute instanceof eZContentObjectAttribute) {
         return array();
     }
     $contentObject = $contentObjectAttribute->attribute('object');
     if (!$contentObject->attribute('can_edit')) {
         return array();
     }
     // checking that the version is a draft and belongs to the current user
     $contentVersion = $contentObjectAttribute->attribute('object_version');
     if ($contentVersion->attribute('status') != eZContentObjectVersion::STATUS_DRAFT && $contentVersion->attribute('status') != eZContentObjectVersion::STATUS_INTERNAL_DRAFT) {
         return array();
     }
     if ($contentVersion->attribute('creator_id') != eZUser::currentUserID()) {
         return array();
     }
     $sortArray = array();
     foreach ($blockOrder as $blockID) {
         $idArray = explode('_', $blockID);
         if (isset($idArray[1])) {
             $sortArray[] = $idArray[1];
         }
     }
     if ($contentObjectAttribute) {
         $page = $contentObjectAttribute->content();
     }
     if ($page) {
         $zone = $page->getZone($zoneID);
     }
     if ($zone) {
         $zone->sortBlocks($sortArray);
     }
     $contentObjectAttribute->setContent($page);
     $contentObjectAttribute->store();
     return array();
 }
 public static function attribute_edit()
 {
     $http = eZHTTPTool::instance();
     $objectId = $http->postVariable('objectId', 0);
     $attributeId = $http->postVariable('attributeId', 0);
     $version = $http->postVariable('version', 0);
     $content = $http->postVariable('content', '');
     $object = eZContentObject::fetch($objectId);
     if ($object instanceof eZContentObject && $object->attribute('can_edit')) {
         $attribute = eZContentObjectAttribute::fetch($attributeId, $version);
         if ($attribute instanceof eZContentObjectAttribute && $attribute->attribute('contentobject_id') == $objectId) {
             $params['attributes'] = array($attribute->attribute('contentclass_attribute_identifier') => $content);
             eZContentFunctions::updateAndPublishObject($object, $params);
             $object = eZContentObject::fetch($objectId);
             return $object->attribute('name');
         }
     }
     throw new Exception("Error");
 }
 /**
  * Update blocks order based on AJAX data send after D&D operation is finished
  * 
  * @param mixed $args
  * @return array
  */
 public static function updateblockorder($args)
 {
     $http = eZHTTPTool::instance();
     if ($http->hasPostVariable('contentobject_attribute_id')) {
         $contentObjectAttributeID = $http->postVariable('contentobject_attribute_id');
     }
     if ($http->hasPostVariable('version')) {
         $version = $http->postVariable('version');
     }
     if ($http->hasPostVariable('zone')) {
         $zoneID = $http->postVariable('zone');
     }
     if ($http->hasPostVariable('block_order')) {
         $blockOrder = $http->postVariable('block_order');
     }
     $contentObjectAttribute = eZContentObjectAttribute::fetch($contentObjectAttributeID, $version);
     $sortArray = array();
     foreach ($blockOrder as $blockID) {
         $idArray = explode('_', $blockID);
         if (isset($idArray[1])) {
             $sortArray[] = $idArray[1];
         }
     }
     if ($contentObjectAttribute) {
         $page = $contentObjectAttribute->content();
     }
     if ($page) {
         $zone = $page->getZone($zoneID);
     }
     if ($zone) {
         $zone->sortBlocks($sortArray);
     }
     $contentObjectAttribute->setContent($page);
     $contentObjectAttribute->store();
     return array();
 }
Ejemplo n.º 7
0
 static function clearCacheForObjectLink($urlID)
 {
     $urlObjectLinkList = eZPersistentObject::fetchObjectList(eZURLObjectLink::definition(), null, array('url_id' => $urlID), null, null, true);
     foreach ($urlObjectLinkList as $urlObjectLink) {
         $objectAttributeID = $urlObjectLink->attribute('contentobject_attribute_id');
         $objectAttributeVersion = $urlObjectLink->attribute('contentobject_attribute_version');
         $objectAttribute = eZContentObjectAttribute::fetch($objectAttributeID, $objectAttributeVersion);
         if ($objectAttribute) {
             $objectID = $objectAttribute->attribute('contentobject_id');
             $objectVersion = $objectAttribute->attribute('version');
             eZContentCacheManager::clearContentCacheIfNeeded($objectID, $objectVersion);
         }
     }
 }
 function addToBasket($objectID, $optionList, $quantity)
 {
     $object = eZContentObject::fetch($objectID);
     $nodeID = $object->attribute('main_node_id');
     $price = 0.0;
     $isVATIncluded = true;
     $attributes = $object->contentObjectAttributes();
     $priceFound = false;
     foreach ($attributes as $attribute) {
         $dataType = $attribute->dataType();
         if (eZShopFunctions::isProductDatatype($dataType->isA())) {
             $priceObj = $attribute->content();
             $price += $priceObj->attribute('price');
             $priceFound = true;
         }
     }
     if (!$priceFound) {
         eZDebug::writeError('Attempted to add object without price to basket.');
         return array('status' => eZModuleOperationInfo::STATUS_CANCELLED);
     }
     $currency = $priceObj->attribute('currency');
     // Check for 'option sets' in option list.
     // If found each 'option set' will be added as a separate product purchase.
     $hasOptionSet = false;
     foreach (array_keys($optionList) as $optionKey) {
         if (substr($optionKey, 0, 4) == 'set_') {
             $returnStatus = eZShopOperationCollection::addToBasket($objectID, $optionList[$optionKey]);
             // If adding one 'option set' fails we should stop immediately
             if ($returnStatus['status'] == eZModuleOperationInfo::STATUS_CANCELLED) {
                 return $returnStatus;
             }
             $hasOptionSet = true;
         }
     }
     if ($hasOptionSet) {
         return $returnStatus;
     }
     $unvalidatedAttributes = array();
     foreach ($attributes as $attribute) {
         $dataType = $attribute->dataType();
         if ($dataType->isAddToBasketValidationRequired()) {
             $errors = array();
             if ($attribute->validateAddToBasket($optionList[$attribute->attribute('id')], $errors) !== eZInputValidator::STATE_ACCEPTED) {
                 $description = $errors;
                 $contentClassAttribute = $attribute->contentClassAttribute();
                 $attributeName = $contentClassAttribute->attribute('name');
                 $unvalidatedAttributes[] = array("name" => $attributeName, "description" => $description);
             }
         }
     }
     if (count($unvalidatedAttributes) > 0) {
         return array('status' => eZModuleOperationInfo::STATUS_CANCELLED, 'reason' => 'validation', 'error_data' => $unvalidatedAttributes);
     }
     $basket = eZBasket::currentBasket();
     /* Check if the item with the same options is not already in the basket: */
     $itemID = false;
     $collection = $basket->attribute('productcollection');
     if (!$collection) {
         eZDebug::writeError('Unable to find product collection.');
         return array('status' => eZModuleOperationInfo::STATUS_CANCELLED);
     } else {
         $collection->setAttribute('currency_code', $currency);
         $collection->store();
         $count = 0;
         /* Calculate number of options passed via the HTTP variable: */
         foreach (array_keys($optionList) as $key) {
             if (is_array($optionList[$key])) {
                 $count += count($optionList[$key]);
             } else {
                 $count++;
             }
         }
         $collectionItems = $collection->itemList(false);
         foreach ($collectionItems as $item) {
             /* For all items in the basket which have the same object_id: */
             if ($item['contentobject_id'] == $objectID) {
                 $options = eZProductCollectionItemOption::fetchList($item['id'], false);
                 /* If the number of option for this item is not the same as in the HTTP variable: */
                 if (count($options) != $count) {
                     break;
                 }
                 $theSame = true;
                 foreach ($options as $option) {
                     /* If any option differs, go away: */
                     if (is_array($optionList[$option['object_attribute_id']]) && !in_array($option['option_item_id'], $optionList[$option['object_attribute_id']]) || !is_array($optionList[$option['object_attribute_id']]) && $option['option_item_id'] != $optionList[$option['object_attribute_id']]) {
                         $theSame = false;
                         break;
                     }
                 }
                 if ($theSame) {
                     $itemID = $item['id'];
                     break;
                 }
             }
         }
         if ($itemID) {
             /* If found in the basket, just increment number of that items: */
             $item = eZProductCollectionItem::fetch($itemID);
             $item->setAttribute('item_count', $quantity + $item->attribute('item_count'));
             $item->store();
         } else {
             $item = eZProductCollectionItem::create($basket->attribute("productcollection_id"));
             $item->setAttribute('name', $object->attribute('name'));
             $item->setAttribute("contentobject_id", $objectID);
             $item->setAttribute("item_count", $quantity);
             $item->setAttribute("price", $price);
             if ($priceObj->attribute('is_vat_included')) {
                 $item->setAttribute("is_vat_inc", '1');
             } else {
                 $item->setAttribute("is_vat_inc", '0');
             }
             $item->setAttribute("vat_value", $priceObj->attribute('vat_percent'));
             $item->setAttribute("discount", $priceObj->attribute('discount_percent'));
             $item->store();
             $priceWithoutOptions = $price;
             $optionIDList = array();
             foreach (array_keys($optionList) as $key) {
                 $attributeID = $key;
                 $optionString = $optionList[$key];
                 if (is_array($optionString)) {
                     foreach ($optionString as $optionID) {
                         $optionIDList[] = array('attribute_id' => $attributeID, 'option_string' => $optionID);
                     }
                 } else {
                     $optionIDList[] = array('attribute_id' => $attributeID, 'option_string' => $optionString);
                 }
             }
             $db = eZDB::instance();
             $db->begin();
             foreach ($optionIDList as $optionIDItem) {
                 $attributeID = $optionIDItem['attribute_id'];
                 $optionString = $optionIDItem['option_string'];
                 $attribute = eZContentObjectAttribute::fetch($attributeID, $object->attribute('current_version'));
                 $dataType = $attribute->dataType();
                 $optionData = $dataType->productOptionInformation($attribute, $optionString, $item);
                 if ($optionData) {
                     $optionData['additional_price'] = eZShopFunctions::convertAdditionalPrice($currency, $optionData['additional_price']);
                     $optionItem = eZProductCollectionItemOption::create($item->attribute('id'), $optionData['id'], $optionData['name'], $optionData['value'], $optionData['additional_price'], $attributeID);
                     $optionItem->store();
                     $price += $optionData['additional_price'];
                 }
             }
             if ($price != $priceWithoutOptions) {
                 $item->setAttribute("price", $price);
                 $item->store();
             }
             $db->commit();
         }
     }
     return array('status' => eZModuleOperationInfo::STATUS_CONTINUE);
 }
Ejemplo n.º 9
0
 function storeDOMTree($domTree, $storeAttribute, $contentObjectAttributeRef)
 {
     if (!$domTree) {
         return false;
     }
     $this->ContentObjectAttributeData['DataTypeCustom']['dom_tree'] = $domTree;
     $this->ContentObjectAttributeData['DataTypeCustom']['is_storage_required'] = false;
     $xmlString = $domTree->saveXML();
     $this->ContentObjectAttributeData['data_text'] = $xmlString;
     if ($storeAttribute) {
         if (is_object($contentObjectAttributeRef)) {
             $contentObjectAttribute = $contentObjectAttributeRef;
         } else {
             $contentObjectAttribute = eZContentObjectAttribute::fetch($this->ContentObjectAttributeData['id'], $this->ContentObjectAttributeData['version']);
         }
         if (is_object($contentObjectAttribute)) {
             $contentObjectAttribute->setAttribute('data_text', $xmlString);
             $contentObjectAttribute->storeData();
         } else {
             eZDebug::writeError("Invalid objectAttribute: id = " . $this->ContentObjectAttributeData['id'] . " version = " . $this->ContentObjectAttributeData['version'], __METHOD__);
         }
     }
     return true;
 }
        $classAttribute->store();
        $classAttribute->setAttribute('data_int1', 0);
        $classAttribute->setAttribute('data_text1', '');
        $classAttribute->store();
        unset($classAttribute);
    }
} else {
    $cli->output('No class attributes to update!');
}
$IDs = $db->arrayQuery("SELECT id, version\n    FROM ezcontentobject_attribute\n    WHERE data_type_string = 'ezenhancedselection'");
$cli->output();
$cli->output($cli->stylize('bold', 'Updating object attributes'));
if (is_array($IDs) and count($IDs) > 0) {
    foreach ($IDs as $id) {
        $cli->output('Updating object attribute: id - ' . $id['id'] . ' & version - ' . $id['version']);
        $objectAttribute = eZContentObjectAttribute::fetch($id['id'], $id['version']);
        $textString = $objectAttribute->attribute('data_text');
        $textArray = explode('***', $textString);
        $objectAttribute->setAttribute('data_type_string', 'sckenhancedselection');
        $objectAttribute->DataTypeString = 'sckenhancedselection';
        $objectAttribute->setAttribute('data_text', serialize($textArray));
        $objectAttribute->store();
        $objectAttribute->updateSortKey();
        $object = $objectAttribute->attribute('object');
        $class = $object->attribute('content_class');
        // Reset the name
        $object->setName($class->contentObjectName($object));
        // Update the nodes
        $nodes = $object->attribute('assigned_nodes');
        foreach ($nodes as $node) {
            eZContentOperationCollection::publishNode($node->attribute('parent_node_id'), $object->attribute('id'), $object->attribute('current_version'), $object->attribute('main_node_id'));
 function contentObjectAttribute()
 {
     $contentObject = $this->contentObject();
     return eZContentObjectAttribute::fetch( $this->attribute( 'contentobject_attribute_id' ), $contentObject->attribute( 'current_version' ) );
 }
 * File containing the ezie no save & quit menu item handler
 *
 * @copyright Copyright (C) eZ Systems AS.
 * @license For full copyright and license information view LICENSE file distributed with this source code.
 * @version //autogentag//
 * @package ezie
 */
$prepare_action = new eZIEImagePreAction();
$imageId = $prepare_action->getImageId();
$imageVersion = $prepare_action->getImageVersion();
$imageAttribute = eZContentObjectAttribute::fetch($imageId, $imageVersion);
// Save the class attribute
$imageHandler = $prepare_action->getImageHandler();
$imageHandler->initializeFromFile($prepare_action->getImagePath(), $imageHandler->attribute('alternative_text'), $imageHandler->attribute('original_filename'));
// TODO: what's $contentobjectattribute (ask jerome) ?
$imageHandler->store($imageAttribute);
// remove view cache if needed
eZContentCacheManager::clearObjectViewCacheIfNeeded($imageAttribute->attribute('contentobject_id'));
// delete all the images in working directory
// delete working directory
$working_folder = eZDir::dirpath($prepare_action->getImagePath());
// deletes the working folder recursively
eZDir::recursiveDelete($working_folder);
// new attribute
$imageAttribute = eZContentObjectAttribute::fetch($imageId, $imageVersion);
// @todo Use proper JSON, but this will do for now.
$tpl = eZTemplate::factory();
$tpl->setVariable('ezie_ajax_response', true);
$tpl->setVariable('attribute', $imageAttribute);
echo $tpl->fetch("design:content/datatype/edit/ezimage.tpl");
eZExecution::cleanExit();
Ejemplo n.º 13
0
 function publish($contentObjectID, $contentObjectVersion)
 {
     // fetch object
     $object = eZContentObject::fetch($contentObjectID);
     // get content class object
     $contentClass = $object->attribute('content_class');
     if ($contentClass->attribute('identifier') == 'file' || $contentClass->attribute('identifier') == 'nettopp') {
         $contentObjectAttributes = $object->contentObjectAttributes();
         $loopLenght = count($contentObjectAttributes);
         // Find image and file attribute
         for ($i = 0; $i < $loopLenght; $i++) {
             switch ($contentObjectAttributes[$i]->attribute('contentclass_attribute_identifier')) {
                 case 'image':
                     $image = $contentObjectAttributes[$i];
                     break;
                 case 'file':
                     $file = $contentObjectAttributes[$i];
                     break;
             }
         }
         if (!$file->hasContent()) {
             return;
         }
         if (!is_object($image)) {
             eZDebug::writeNotice("Image field was not found", "pdf2image");
             return;
         }
         // Get previous version and check that file has changed
         if ((int) $file->Version > 0 && $image->hasContent()) {
             $previousFile = eZContentObjectAttribute::fetch($file->ID, $file->Version - 1, true);
             if (is_object($previousFile) && $previousFile->hasContent()) {
                 if ($previousFile->content()->Filename == $file->content()->Filename) {
                     eZDebug::writeNotice("File hasn't changed", "pdf2image");
                     return;
                 }
             }
         }
         // Check that file is PDF
         if ($file->content()->MimeType != "application/pdf") {
             eZDebug::writeNotice("File not application/pdf", "pdf2image");
             return;
         }
         $source = $file->content()->filePath();
         if (!file_exists($source) or !is_readable($source)) {
             eZDebug::writeError("File not readable or doesn't exist", "pdf2image");
             return;
         }
         $page = 0;
         $width = 1000;
         $height = 1000;
         $target = eZSys::cacheDirectory() . "/" . md5(time() . 'pdf2image') . ".jpg";
         // Run conversion and redirect error to stdin
         $cmd = "convert " . "-density 200 " . eZSys::escapeShellArgument($source . "[" . $page . "]") . " " . "-colorspace rgb " . "-resize " . eZSys::escapeShellArgument($width . "x" . $height) . " " . eZSys::escapeShellArgument($target) . " 2>&1";
         eZDebug::writeNotice("Converting '" . $cmd . "'", "pdf2image");
         $out = shell_exec($cmd);
         // If we got a message somthing went wrong
         if ($out) {
             eZDebug::writeError("Conversion return error message '" . $out . "'", "pdf2image");
             // but it doesn't necessarily mean that it failed
             if (!is_readable($target)) {
                 return;
             }
         }
         // Add imagefile to image handler and save
         $imageContent = $image->content();
         $imageContent->initializeFromFile($target, $object->Name);
         if ($imageContent->isStorageRequired()) {
             $imageContent->store($image);
         }
         unlink($target);
     }
 }
Ejemplo n.º 14
0
<?php

$return = true;
$attributeId = (int) $_REQUEST['attribute_id'];
$versionId = (int) $_REQUEST['version_id'];
$content = $_REQUEST['data'];
if ($attributeId && $versionId) {
    $attribute = eZContentObjectAttribute::fetch($attributeId, $versionId);
    switch ($attribute->attribute('data_type_string')) {
        case 'ezxmltext':
            if (eZOEXMLInput::browserSupportsDHTMLType() === 'Trident') {
                $content = str_replace("\t", '', $content);
            }
            $parser = new eZOEInputParser();
            $document = $parser->process($content);
            // Remove last empty paragraph (added in the output part)
            $parent = $document->documentElement;
            $lastChild = $parent->lastChild;
            while ($lastChild && $lastChild->nodeName !== 'paragraph') {
                $parent = $lastChild;
                $lastChild = $parent->lastChild;
            }
            if ($lastChild && $lastChild->nodeName === 'paragraph') {
                $textChild = $lastChild->lastChild;
                // $textChild->textContent == "�" : string(2) whitespace in Opera
                if (!$textChild || $lastChild->childNodes->length == 1 && $textChild->nodeType == XML_TEXT_NODE && ($textChild->textContent == "�" || $textChild->textContent == ' ' || $textChild->textContent == '' || $textChild->textContent == '&nbsp;')) {
                    $parent->removeChild($lastChild);
                }
            }
            $xmlString = eZXMLTextType::domString($document);
            $attribute->setAttribute('data_text', $xmlString);
 /**
  * Return contentObjectAttribute.
  * 
  * @return void
  */
 public function contentObjectAttribute()
 {
     $object = $this->contentObject();
     $version = $object->attribute('current_version');
     return eZContentObjectAttribute::fetch($this->attribute('contentobjectattribute_id'), $version);
 }
Ejemplo n.º 16
0
 /**
  * Fetch data from list
  *
  * @todo check if objects exists
  * @return unknown_type
  */
 function getListAttributeContent()
 {
     // current
     $editionSendAttribute = eZContentObjectAttribute::fetch($this->attribute('contentobject_attribute_id'), $this->attribute('contentobject_attribute_version'), true);
     $objectVersion = $editionSendAttribute->attribute('object_version');
     $mainParentNodeId = $objectVersion->attribute('main_parent_node_id');
     // fetch outputformats from list
     $listNode = eZContentObjectTreeNode::fetch($mainParentNodeId);
     $listDataMap = $listNode->DataMap();
     $listAttributeContent = NULL;
     foreach ($listDataMap as $attribute) {
         if ($attribute->attribute('data_type_string') == 'cjwnewsletterlist' or $attribute->attribute('data_type_string') == 'cjwnewsletterlistvirtual') {
             $listAttributeContent = $attribute->attribute('content');
         }
     }
     return $listAttributeContent;
 }
Ejemplo n.º 17
0
     $optionIDList = array();
     foreach (array_keys($optionList) as $key) {
         $attributeID = $key;
         $optionString = $optionList[$key];
         if (is_array($optionString)) {
             foreach ($optionString as $optionID) {
                 $optionIDList[] = array('attribute_id' => $attributeID, 'option_string' => $optionID);
             }
         } else {
             $optionIDList[] = array('attribute_id' => $attributeID, 'option_string' => $optionString);
         }
     }
     foreach ($optionIDList as $optionIDItem) {
         $attributeID = $optionIDItem['attribute_id'];
         $optionString = $optionIDItem['option_string'];
         $attribute = eZContentObjectAttribute::fetch($attributeID, $object->attribute('current_version'));
         $dataType = $attribute->dataType();
         $optionData = $dataType->productOptionInformation($attribute, $optionString, $item);
         if ($optionData) {
             $optionItem = eZProductCollectionItemOption::create($item->attribute('id'), $optionData['id'], $optionData['name'], $optionData['value'], 0, $attributeID);
             $optionItem->store();
             //$price += $optionData['additional_price'];
         }
     }
     $db->commit();
     //if ( $price != $priceWithoutOptions )
     //{
     //    $item->setAttribute( "price", $price );
     //    $item->store();
     //}
 }
    /**
     * Rate content object attribute id
     *
     * @param array $args ( 0 => contentobjectattribute_id,  1 => contentobject_version, 2 => rating )
     * @return array
     */
    public static function rate( $args )
    {
        $ret = array( 'id' => 0, 'rated' => false, 'already_rated' => false, 'stats' => false );
        if ( !isset( $args[2] ) )
            throw new LengthException( 'Rating expects 3 arguments: attr_id, version, rating' );
        else if ( !is_numeric( $args[0] ) )
            throw new InvalidArgumentException( 'Rating argument[0] attr_id must be a number' );
        else if ( !is_numeric( $args[1] ) )
            throw new InvalidArgumentException( 'Rating argument[1] version must be a number' );
        else if ( !is_numeric( $args[2] ) )
            throw new InvalidArgumentException( 'Rating argument[2] rating must be a number' );
        else if ( $args[2] > 5 || $args[2] < 1 )
            throw new UnexpectedValueException( 'Rating argument[2] rating must be between 1 and 5' );

        $ret['id'] = (int) $args[0];

        // Provide extra session protection on 4.1 (not possible on 4.0) by expecting user
        // to have an existing session (new session = mostlikely a spammer / hacker trying to manipulate rating)
        if (
            eZSession::userHasSessionCookie() !== true
            && eZINI::instance()->variable( 'eZStarRating', 'AllowAnonymousRating' ) === 'disabled'
        )
            return $ret;

        // Return if parameters are not valid attribute id + version numbers
        $contentobjectAttribute = eZContentObjectAttribute::fetch( $ret['id'], $args[1] );
        if ( !$contentobjectAttribute instanceof eZContentObjectAttribute )
            return $ret;

        // Return if attribute is not a rating attribute
        if ( $contentobjectAttribute->attribute('data_type_string') !== ezsrRatingType::DATA_TYPE_STRING )
            return $ret;

        // Return if rating has been disabled on current attribute
        if ( $contentobjectAttribute->attribute('data_int') )
            return $ret;

        // Return if user does not have access to object
        $contentobject = $contentobjectAttribute->attribute('object');
        if ( !$contentobject instanceof eZContentObject || !$contentobject->attribute('can_read') )
            return $ret;

        $rateDataObj = ezsrRatingDataObject::create( array( 'contentobject_id' => $contentobjectAttribute->attribute('contentobject_id'),
                                                    'contentobject_attribute_id' =>  $ret['id'],
                                                    'rating' => $args[2]
        ));

        $proiorRating = $rateDataObj->userHasRated( true );

        if ( $proiorRating === true )
        {
            $ret['already_rated'] = true;
        }
        else if ( $proiorRating instanceof ezsrRatingDataObject )
        {
            $rateDataObj = $proiorRating;
            $rateDataObj->setAttribute( 'rating', $args[2] );
            $ret['already_rated'] = true;
            $proiorRating = false;// just to reuse code bellow
        }

        if ( !$proiorRating )
        {
            $rateDataObj->store();
            $avgRateObj = $rateDataObj->getAverageRating();
            $avgRateObj->updateFromRatingData();
            $avgRateObj->store();
            eZContentCacheManager::clearContentCacheIfNeeded( $rateDataObj->attribute('contentobject_id') );
            $ret['rated'] = true;
            $ret['stats'] = array(
               'rating_count' => $avgRateObj->attribute('rating_count'),
               'rating_average' => $avgRateObj->attribute('rating_average'),
               'rounded_average' => $avgRateObj->attribute('rounded_average'),
            );
        }
        return $ret;
    }
function updateClass($classId)
{
    global $cli, $script, $db, $scheduledScript;
    // If the class is not stored yet, store it now
    $class = eZContentClass::fetch($classId, true, eZContentClass::VERSION_STATUS_TEMPORARY);
    if ($class) {
        $cli->output("Storing class");
        $class->storeDefined($class->fetchAttributes());
    }
    // Fetch the stored class
    $class = eZContentClass::fetch($classId);
    if (!$class) {
        $cli->error('Could not fetch class with ID: ' . $classId);
        return;
    }
    $classAttributes = $class->fetchAttributes();
    $classAttributeIDs = array();
    foreach ($classAttributes as $classAttribute) {
        $classAttributeIDs[] = $classAttribute->attribute('id');
    }
    $objectCount = eZContentObject::fetchSameClassListCount($classId);
    $cli->output('Number of objects to be processed: ' . $objectCount);
    $counter = 0;
    $offset = 0;
    $limit = 100;
    $objects = eZContentObject::fetchSameClassList($classId, true, $offset, $limit);
    // Add and/or remove attributes for all versions and translations of all objects of this class
    while (count($objects) > 0) {
        // Run a transaction per $limit objects
        $db->begin();
        foreach ($objects as $object) {
            $contentObjectID = $object->attribute('id');
            $objectVersions = $object->versions();
            foreach ($objectVersions as $objectVersion) {
                $versionID = $objectVersion->attribute('version');
                $translations = $objectVersion->translations();
                foreach ($translations as $translation) {
                    $translationName = $translation->attribute('language_code');
                    // Class attribute IDs of object attributes (not necessarily the same as those in the class, hence the manual sql)
                    $objectClassAttributeIDs = array();
                    $rows = $db->arrayQuery("SELECT id,contentclassattribute_id, data_type_string\n                                              FROM ezcontentobject_attribute\n                                              WHERE contentobject_id = '{$contentObjectID}' AND\n                                                    version = '{$versionID}' AND\n                                                    language_code='{$translationName}'");
                    foreach ($rows as $row) {
                        $objectClassAttributeIDs[$row['id']] = $row['contentclassattribute_id'];
                    }
                    // Quick array diffs
                    $attributesToRemove = array_diff($objectClassAttributeIDs, $classAttributeIDs);
                    // Present in the object, not in the class
                    $attributesToAdd = array_diff($classAttributeIDs, $objectClassAttributeIDs);
                    // Present in the class, not in the object
                    // Remove old attributes
                    foreach ($attributesToRemove as $objectAttributeID => $classAttributeID) {
                        $objectAttribute = eZContentObjectAttribute::fetch($objectAttributeID, $versionID);
                        if (!is_object($objectAttribute)) {
                            continue;
                        }
                        $objectAttribute->remove($objectAttributeID);
                    }
                    // Add new attributes
                    foreach ($attributesToAdd as $classAttributeID) {
                        $objectAttribute = eZContentObjectAttribute::create($classAttributeID, $contentObjectID, $versionID, $translationName);
                        if (!is_object($objectAttribute)) {
                            continue;
                        }
                        $objectAttribute->setAttribute('language_code', $translationName);
                        $objectAttribute->initialize();
                        $objectAttribute->store();
                        $objectAttribute->postInitialize();
                    }
                }
            }
            // Progress bar and Script Monitor progress
            $cli->output('.', false);
            $counter++;
            if ($counter % 70 == 0 or $counter >= $objectCount) {
                $progressPercentage = $counter / $objectCount * 100;
                $cli->output(sprintf(' %01.1f %%', $progressPercentage));
                if ($scheduledScript) {
                    $scheduledScript->updateProgress($progressPercentage);
                }
            }
        }
        $db->commit();
        $offset += $limit;
        $objects = eZContentObject::fetchSameClassList($classId, true, $offset, $limit);
    }
    // Set the object name to the first attribute, if not set
    $classAttributes = $class->fetchAttributes();
    // Fetch the first attribute
    if (count($classAttributes) > 0 && trim($class->attribute('contentobject_name')) == '') {
        $db->begin();
        $identifier = $classAttributes[0]->attribute('identifier');
        $identifier = '<' . $identifier . '>';
        $class->setAttribute('contentobject_name', $identifier);
        $class->store();
        $db->commit();
    }
}
 /**
  * Helper function to get the current objects contentObjectAttribute
  *
  * @return contentObjectAttribute of the current object
  * @access protected
  * @author ymc-dabe
  */
 protected function contentObjectAttribute()
 {
     if (is_object($this->attribute('contentObject'))) {
         return eZContentObjectAttribute::fetch($this->attribute('contentobjectattribute_id'), $this->attribute('contentObject')->attribute('current_version'));
     } else {
         return NULL;
     }
 }
Ejemplo n.º 21
0
 * @version //autogentag//
 * @package ezie
 */
$Module = $Params['Module'];
$Params = $Module->getNamedParameters();
$objectId = (int) $Params['object_id'];
$editLanguage = (int) $Params['edit_language'];
$attributeID = (int) $Params['attribute_id'];
$version = (int) $Params['version'];
// Check for permissions
$contentObject = eZContentObject::fetch($objectId);
if (!$contentObject instanceof eZContentObject || !$contentObject->canEdit(false, false, false, $editLanguage)) {
    die('// @todo fixme :)');
}
// retrieve the original image path
$img = eZContentObjectAttribute::fetch($attributeID, $version)->attribute('content');
$image_path = $img->attributeFromOriginal('url');
$absolute_image_path = eZSys::rootDir() . "/{$image_path}";
// Creation of the editing arborescence
// /{cache folder}/public/ezie/user_id/image_id-version_id
$user = eZUser::instance();
$working_folder_path = eZSys::cacheDirectory() . '/public/ezie/' . $user->id() . "/{$attributeID}-{$version}";
$working_folder_absolute_path = eZSys::rootDir() . "/{$working_folder_path}";
$handler = eZClusterFileHandler::instance();
if (!$handler->fileExists($working_folder_absolute_path)) {
    // @todo DB Based handlers have no knowledge of folders !
    $res = eZDir::mkdir($working_folder_absolute_path, false, true);
}
// Copy the original file in the temp directory
// $work_folder/{history_id}-{file_name}
// (thumb: $working_folder/thumb_{history_id}-{file_name}
Ejemplo n.º 22
0
 /**
  * Create image alias variation by contentObjectAttribute
  *
  * @param object $contentObjectAttribute object of class eZContentObjectAtribute
  * @param array $class Array of object class identifiers to create aliases for only these classes. Optional. Defaults to false
  * @param array $attributes Array of object image attribute identifiers to create aliases. Optional. Defaults to false
  * @param array $aliases Array of object image attribute image aliases to create. Optional. Defaults to false
  *
  * @return bool true if any image alias generation is called, false if not
  * @static
  */
 static function createByAttribute($contentObjectAttribute = false, $classes = false, $attributes = false, $aliases = false)
 {
     if (!$contentObjectAttribute) {
         return false;
     }
     // Test that content object class attribute identifier matches provided classes
     if ($classes != false && is_array($classes) && !in_array($contentObjectAttribute->attribute('object')->attribute('class_identifier'), $classes)) {
         return false;
     }
     // Test that content object class attribute identifier matches provided classes
     if ($attributes != false && is_array($attributes) && !in_array($contentObjectAttribute->attribute('contentclass_attribute_identifier'), $attributes)) {
         return false;
     }
     $results = array();
     $result = array();
     $createAliases = array();
     $executionOptions = self::executionOptions();
     // Default image alias settings
     $relatedSiteAccesses = eZINI::instance('site.ini')->variable('SiteAccessSettings', 'RelatedSiteAccessList');
     // Fetch aliases for current siteaccess
     if ($executionOptions['current-siteaccess']) {
         if (!$aliases) {
             // Default image alias settings
             $createAliases = eZINI::instance('image.ini')->variable('AliasSettings', 'AliasList');
         } else {
             // Parameter image alias to create
             $createAliases = $aliases;
         }
     } else {
         if (!$aliases) {
             // Fetch aliases for current siteaccess relateded siteaccesses
             if (is_array($relatedSiteAccesses)) {
                 foreach ($relatedSiteAccesses as $relatedSiteAccess) {
                     $relatedSiteaccessImageINIOverrideFile = 'settings/siteaccess/' . $relatedSiteAccess . '/image.ini.append.php';
                     if (file_exists($relatedSiteaccessImageINIOverrideFile)) {
                         // Optional debug output
                         if ($executionOptions['troubleshoot']) {
                             self::displayMessage('Fetching related siteaccess ' . "'" . $relatedSiteAccess . "'" . ' image.ini:[AliasSettings] AliasList[] image aliases defined', "\n");
                         }
                         $siteaccessAliases = eZINI::getSiteAccessIni($relatedSiteAccess, 'image.ini')->variable('AliasSettings', 'AliasList');
                         // Test for siteaccesses
                         if ($siteaccessAliases != false) {
                             // Add siteaccess aliases into array
                             foreach ($siteaccessAliases as $siteaccessAlias) {
                                 if (!in_array($siteaccessAlias, $aliases)) {
                                     $aliases[] = $siteaccessAlias;
                                 }
                             }
                             // Add default settings aliases into array
                             foreach (eZINI::instance('image.ini', 'settings', null, null, false, true)->variable('AliasSettings', 'AliasList') as $defaultSettingAlias) {
                                 if (!in_array($defaultSettingAlias, $aliases)) {
                                     $aliases[] = $defaultSettingAlias;
                                 }
                             }
                             // Optional debug output
                             if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 2 && !$executionOptions['iterate']) {
                                 self::displayMessage('All siteaccess ' . "'" . $relatedSiteAccess . "'" . ' image.ini:[AliasSettings] AliasList[] image aliases defined');
                                 print_r($aliases);
                                 self::displayMessage('', "\n");
                             }
                         }
                     }
                 }
             }
         } else {
             // Parameter image alias to create
             $createAliases = $aliases;
         }
     }
     // Optional debug output
     if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 2) {
         self::displayMessage('All related siteaccess image.ini:[AliasSettings] AliasList[] image aliases defined:');
         print_r($createAliases);
         self::displayMessage('', "\n");
     }
     // Don't try to create original image alias
     unset($createAliases['original']);
     // Default datatypes to create image alias variations
     $imageDataTypeStrings = eZINI::instance('bcimagealias.ini')->variable('BCImageAliasSettings', 'ImageDataTypeStringList');
     // Check that content object attribute data type string matches allowed datatype settings
     if (!in_array($contentObjectAttribute->attribute('data_type_string'), $imageDataTypeStrings) || !$contentObjectAttribute->attribute('has_content')) {
         return false;
     }
     // Fetch content object attribute content the image alias handler object
     $imageHandler = $contentObjectAttribute->content();
     // Fetch eZImageManager instance
     $imageManager = eZImageManager::factory();
     // Fetch all related siteaccess image.ini:[AliasSettings] AliasList[] image aliases defined
     if (is_array($relatedSiteAccesses) && !$executionOptions['current-siteaccess'] && !$executionOptions['iterate']) {
         // Fetch all default image aliases for imageManager
         // $imageManager->readImageAliasesFromINI( 'settings/image.ini' );
         // Fetch all siteaccess image aliases for imageManager
         foreach ($relatedSiteAccesses as $relatedsiteaccess) {
             $relatedSiteaccessImageINIFileFolder = 'settings/siteaccess/' . $relatedsiteaccess;
             $relatedSiteaccessImageINIFile = $relatedSiteaccessImageINIFileFolder . '/image.ini.append.php';
             if (file_exists($relatedSiteaccessImageINIFile)) {
                 // $imageManager->readImageAliasesFromOverrideINI( 'image.ini.append.php', $relatedSiteaccessImageINIFileFolder );
                 $imageManager->readImageAliasesFromOverrideINI($relatedsiteaccess, 'image.ini');
             }
         }
         // Optional debug output
         if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 2) {
             self::displayMessage("\n" . 'Image manager image aliases', "\n");
             print_r(array_keys($imageManager->AliasList));
         }
     } elseif (!$executionOptions['current-siteaccess'] && $executionOptions['iterate']) {
         $imageManager->readImageAliasesFromOriginalINI('image.ini');
     }
     // Fetch the image alias handler object's alias list
     $aliasList = $imageHandler->aliasList();
     $original = $aliasList['original'];
     $basename = $original['basename'];
     // Optional debug output
     if ($executionOptions['troubleshoot']) {
         if ($executionOptions['verboseLevel'] >= 4) {
             self::displayMessage('Current content object image attribute image alias list entries within attribute handler content:', "\n");
             print_r($imageHandler->ContentObjectAttributeData['DataTypeCustom']['alias_list']);
             self::displayMessage('', "\n\n");
         } elseif ($executionOptions['verboseLevel'] >= 3) {
             self::displayMessage('Current content object image attribute image alias list entries within attribute handler content:', "\n");
             print_r(array_keys($imageHandler->ContentObjectAttributeData['DataTypeCustom']['alias_list']));
             self::displayMessage('', "\n\n");
         } else {
             self::displayMessage('', "\n");
         }
         self::displayMessage('Number of ini image aliases: ' . count($createAliases), "\n\n");
     }
     // Initialize alias foreach counter at one, 1
     $aliasCounter = 1;
     // Iterate through image alias list from settings
     foreach ($createAliases as $aliasItem) {
         // Test $aliasItem from $createAliases is in $aliases array
         if ($aliases != false && is_array($aliases) && !in_array($aliasItem, $aliases)) {
             continue;
         }
         // Optional debug output
         if ($executionOptions['troubleshoot']) {
             self::displayMessage('Iteration ' . $aliasCounter . ' of ' . count($createAliases) . ' | Preparing to attempt to create the "' . $aliasItem . '" image alias variation', "\n");
         }
         // Store a temporary record of the alias not yet created this iteration
         $result[$aliasItem] = false;
         // Iterate alias foreach counter
         $aliasCounter++;
         /**
          * Test image alias exists according to imageManager
          */
         if (!$imageManager->hasAlias($aliasItem)) {
             // Optional debug output
             if ($executionOptions['troubleshoot']) {
                 self::displayMessage("\n" . 'eZImageManger claims: ' . '"' . $aliasItem . '"' . ' does not exist in system', "\n\n");
             }
             continue;
         }
         // Skip generating aliases which already exist if force option is false
         if (isset($aliasList[$aliasItem]) && !$executionOptions['regenerate']) {
             continue;
         }
         // Skip generation if force is not true and dry is true
         if (!$executionOptions['regenerate'] && $executionOptions['dry']) {
             // Optional debug output
             if ($executionOptions['troubleshoot']) {
                 // Alert user of dry alias calculation
                 $message = "Dry run: Calculating generation of datatype " . $contentObjectAttribute->attribute('data_type_string') . "type image alias " . '"' . $aliasItem . '"' . ' image variation' . "\n";
                 self::displayMessage($message);
             }
             continue;
         }
         // Create $aliasItem the image alias image variation image file on disk immediately
         if ($imageManager->createImageAlias($aliasItem, $aliasList, array('basename' => $basename))) {
             // Optional debug output
             if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 3) {
                 self::displayMessage('Specific alias added to aliasList (in attribute):');
                 print_r($aliasList[$aliasItem]);
                 self::displayMessage('', "\n");
             }
             // Store a record of the alias created this iteration
             $result[$aliasItem] = true;
             // Uncomment the following line to write a error log entry (for debug)
             // error_log( __CLASS__ . __METHOD__ . ": Created alias $aliasItem" );
         } else {
             // Store a record of the alias not created this iteration
             $result[$aliasItem] = false;
             // Uncomment the following line to write a error log entry (for debug)
             // error_log( __CLASS__ . __METHOD__ . ": Fail creating alias $aliasItem" );
         }
         // Optional debug output
         if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 3) {
             self::displayMessage('Leaving create image alias if block');
             self::displayMessage('Looping to next image alias from ini settings', "\n");
         }
     }
     $aliasesCreated = array_keys($result, true);
     $aliasesCreatedCount = count($aliasesCreated);
     // Only prepare alias meta data when alias(s) have been created
     if (is_array($result) && in_array(true, array_keys($result, true))) {
         $aliasAlertnativeText = $imageHandler->displayText(isset($original['alertnative_text']) ? $original['alertnative_text'] : '');
         $aliasOriginalFilename = $original['original_filename'];
         self::displayMessage('', "\n");
         foreach ($aliasList as $aliasKey => $aliasListItem) {
             if ($aliases != false && is_array($aliases) && !in_array($aliasKey, $aliases)) {
                 continue;
             }
             // Test for newly added alias
             // if( ( !isset( $aliasListItem['is_new'] ) or $aliasListItem['is_new'] == '' ) && $executionOptions[ 'regenerate' ] )
             if ($executionOptions['regenerate']) {
                 $aliasListItem['is_new'] = true;
                 $aliasListItem['is_valid'] = true;
             }
             // Prepare meta data
             $aliasListItem['original_filename'] = $aliasOriginalFilename;
             $aliasListItem['text'] = $aliasAlertnativeText;
             // Test for alias file url and add meta data
             if ($aliasListItem['url']) {
                 $aliasListItemFile = eZClusterFileHandler::instance($aliasListItem['url']);
                 if ($aliasListItemFile->exists()) {
                     $aliasListItem['filesize'] = $aliasListItemFile->size();
                 }
             }
             // Test for newly added alias
             if ($aliasListItem['is_new']) {
                 eZImageFile::appendFilepath($imageHandler->ContentObjectAttributeData['id'], $aliasListItem['url']);
             }
             // Add alias image variation image file meta data back into aliasList
             $aliasList[$aliasKey] = $aliasListItem;
             // Track successful generation attempts
             if (isset($result[$aliasKey]) && $result[$aliasKey]) {
                 $results[] = true;
                 $message = "Created datatype " . $contentObjectAttribute->attribute('data_type_string') . "type image alias " . '"' . $aliasListItem['name'] . '"' . " image variation " . $aliasListItem['url'];
                 self::scriptIterate($message, "\n");
             } elseif (!isset($result[$aliasKey])) {
                 $results[] = true;
             } else {
                 $results[] = false;
             }
         }
         /**
          * Note: The following code replaces the use of this example private method unavailable at the time of publishing
          *
          * $imageHandler->setAliasList( $aliasList );
          */
         $imageHandler->ContentObjectAttributeData['DataTypeCustom']['alias_list'] = $aliasList;
         $imageHandler->addImageAliases($aliasList);
         // Optional debug output
         if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 3) {
             self::displayMessage('Created image alias list array:');
             print_r($aliasList);
             self::displayMessage('', "\n\n");
             self::displayMessage('Created image alias handler object:');
             print_r($imageHandler);
             self::displayMessage('', "\n\n");
         }
     }
     // Optional debug output
     if ($executionOptions['troubleshoot']) {
         self::displayMessage("\n" . 'Content object attribute image alias image variation generation attempts completed', "\n\n");
         $coaID = $contentObjectAttribute->attribute('id');
         $coaVersion = (int) $contentObjectAttribute->attribute('version');
         $contentObjectAttributeRefetched = eZContentObjectAttribute::fetch($coaID, $coaVersion);
         if ($executionOptions['verboseLevel'] >= 3) {
             self::displayMessage('Displaying saved re-feched data_text of attribute image handler. You should see this list fully populated with all created image alias file urls');
             print_r($contentObjectAttributeRefetched->attribute('content')->aliasList());
             self::displayMessage('', "\n");
             $objectLookup = eZContentObject::fetch($contentObjectAttribute->attribute('contentobject_id'));
             $objectLookupDM = $objectLookup->dataMap();
             self::displayMessage('Displaying saved re-feched object attribute aliasList from image handler. You should see this list fully populated with all created image alias file urls');
             print_r($objectLookupDM['image']->content()->aliasList(true));
             self::displayMessage('', "\n");
         }
         if ($executionOptions['verboseLevel'] >= 3 && !$executionOptions['iterate']) {
             self::displayMessage('Here are the content object image attribute image alias generation attempt results:');
             self::displayMessage('Created aliases will show up as a 1. Theses results do not affect workflow completion as image aliases will not always be created', "\n");
             print_r($result);
             self::displayMessage('', "\n");
         } elseif ($executionOptions['verboseLevel'] >= 2 && $executionOptions['iterate']) {
             self::displayMessage('Here are the content object image attribute image alias generation attempt results:');
             self::displayMessage('Created aliases will show up as a 1. Theses results do not affect workflow completion as image aliases will not always be created', "\n");
             print_r($result);
             self::displayMessage('', "\n");
         }
     }
     // Calculate return results based on execution options and results comparison
     if (in_array(true, $results) && count($createAliases) == count($result) && !$executionOptions['dry'] && $executionOptions['regenerate']) {
         // Optional debug output
         if ($executionOptions['troubleshoot']) {
             self::displayMessage('Creation attempts calculate as successful, at least once. All aliases possible attempted');
             self::displayMessage('Variation images created: ' . $aliasesCreatedCount . ' out of ' . count($result), "\n");
         }
         return true;
     } elseif (in_array(true, $results) && !$executionOptions['dry'] && !$executionOptions['regenerate']) {
         // Optional debug output
         if ($executionOptions['troubleshoot']) {
             self::displayMessage('Creation attempts calculate as successful, at least once. All aliases possible attempted', "\n\n");
             self::displayMessage('Variations images created: ' . $aliasesCreatedCount . ' out of ' . count($result), "\n\n");
         }
         return true;
     }
     return false;
 }
 function calculatePriceWithOptions($currency = false)
 {
     $optionList = eZProductCollectionItemOption::fetchList($this->attribute('id'));
     $contentObject = $this->contentObject();
     $contentObjectVersion = $contentObject->attribute('current_version');
     $optionsPrice = 0.0;
     if (count($optionList) > 0) {
         $db = eZDB::instance();
         $db->begin();
         foreach ($optionList as $option) {
             $objectAttribute = eZContentObjectAttribute::fetch($option->attribute('object_attribute_id'), $contentObjectVersion);
             if ($objectAttribute == null) {
                 $optionsPrice += 0.0;
                 continue;
             }
             $dataType = $objectAttribute->dataType();
             $optionData = $dataType->productOptionInformation($objectAttribute, $option->attribute('option_item_id'), $this);
             if ($optionData) {
                 $optionData['additional_price'] = eZShopFunctions::convertAdditionalPrice($currency, $optionData['additional_price']);
                 $option->setAttribute('price', $optionData['additional_price']);
                 $option->store();
                 $optionsPrice += $optionData['additional_price'];
             }
         }
         $db->commit();
     }
     return $optionsPrice;
 }
Ejemplo n.º 24
0
    function nonTranslatableAttributesToUpdate( )
    {
        $object = $this->contentObject();
        $version = $this->attribute( 'version' );
        $objectID = $object->attribute( 'id' );
        $initialLanguageID = $object->attribute( 'initial_language_id' );
        $db = eZDB::instance();

        $attributeRows = $db->arrayQuery( "SELECT ezcontentobject_attribute.id, ezcontentobject_attribute.version
            FROM ezcontentobject_version,
                 ezcontentobject_attribute,
                ezcontentclass_attribute
            WHERE
                    ezcontentobject_version.contentobject_id='$objectID'
                AND ( ezcontentobject_version.status in ( " .
                      eZContentObjectVersion::STATUS_DRAFT . ", " . eZContentObjectVersion::STATUS_PENDING . ", " . eZContentObjectVersion::STATUS_INTERNAL_DRAFT .
                      " ) OR ( ezcontentobject_version.status = '" . self::STATUS_PUBLISHED . "' AND ezcontentobject_version.version = '$version' ) )
                AND ezcontentobject_attribute.contentobject_id=ezcontentobject_version.contentobject_id
                AND ezcontentobject_attribute.version=ezcontentobject_version.version
                AND ezcontentobject_attribute.language_id!='$initialLanguageID'
                AND ezcontentobject_attribute.contentclassattribute_id=ezcontentclass_attribute.id
                AND ezcontentclass_attribute.can_translate=0" );

        $attributes = array();
        foreach( $attributeRows as $row )
        {
            $attributes[] = eZContentObjectAttribute::fetch( $row['id'], $row['version'] );
        }
        return $attributes;
    }
Ejemplo n.º 25
0
 * @version  2012.8
 * @package kernel
 */
$contentObjectID = $Params['ContentObjectID'];
$contentObjectAttributeID = $Params['ContentObjectAttributeID'];
$contentObject = eZContentObject::fetch($contentObjectID);
if (!is_object($contentObject)) {
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
$currentVersion = $contentObject->attribute('current_version');
if (isset($Params['Version']) && is_numeric($Params['Version'])) {
    $version = $Params['Version'];
} else {
    $version = $currentVersion;
}
$contentObjectAttribute = eZContentObjectAttribute::fetch($contentObjectAttributeID, $version, true);
if (!is_object($contentObjectAttribute)) {
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
$contentObjectIDAttr = $contentObjectAttribute->attribute('contentobject_id');
if ($contentObjectID != $contentObjectIDAttr or !$contentObject->attribute('can_read')) {
    return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
}
// Get locations.
$nodeAssignments = $contentObject->attribute('assigned_nodes');
if (count($nodeAssignments) === 0) {
    // oops, no locations. probably it's related object. Let's check his owners
    $ownerList = eZContentObject::fetch($contentObjectID)->reverseRelatedObjectList(false, false, false, false);
    foreach ($ownerList as $owner) {
        if (is_object($owner)) {
            $ownerNodeAssignments = $owner->attribute('assigned_nodes');
Ejemplo n.º 26
0
<?php

$module = $Params['Module'];
$id = $Params['ContentObjectAttributeID'];
$version = $Params['ContentObjectVersion'];
$parentNodeID = $Params['ParentNodeID'];
$http = eZHTTPTool::instance();
$attribute = eZContentObjectAttribute::fetch($id, $version);
$response = array();
if ($attribute instanceof eZContentObjectAttribute && $attribute->attribute('object')->attribute('can_edit')) {
    $siteaccess = eZSiteAccess::current();
    $options['upload_dir'] = eZSys::cacheDirectory() . '/fileupload/';
    $options['download_via_php'] = true;
    $options['param_name'] = "files";
    $options['image_versions'] = array();
    $options['max_file_size'] = $http->variable("upload_max_file_size_{$id}", null);
    $uploadHandler = new UploadHandler($options, false);
    $data = $uploadHandler->post(false);
    foreach ($data[$options['param_name']] as $file) {
        $filePath = $options['upload_dir'] . $file->name;
        $upload = new eZContentUpload();
        $upload->handleLocalFile($response, $filePath, $parentNodeID, false);
    }
    $file = eZClusterFileHandler::instance($filePath);
    if ($file->exists()) {
        $file->delete();
    }
} else {
    $response = array('errors' => array('Not Allowed'));
}
header('Content-Type: application/json');