function updateContentObjectAttribute($contentObjectAttribute)
 {
     $isbnNumber = $contentObjectAttribute->attribute('data_text');
     $isbnValue = trim($isbnNumber);
     $error = false;
     // If the number only consists of hyphen, it should be emty.
     if (preg_match("/^\\-+\$/", $isbnValue)) {
         $emtyValue = '';
         $this->updateContentISBNNumber($contentObjectAttribute, $emtyValue);
         return true;
     }
     // Validate the ISBN number.
     $digits = preg_replace("/\\-/", "", $isbnValue);
     if (trim($digits) != "") {
         // If the length of the number is 10, it is an ISBN-10 number and need
         // to be converted to ISBN-13.
         if (strlen($digits) == 10) {
             $ean = eZISBNType::convertISBN10toISBN13($digits);
         } else {
             if (strlen($digits) == 13) {
                 $ean = $digits;
             } else {
                 $error = true;
             }
         }
         if ($error === false) {
             $isbn13 = new eZISBN13();
             $formatedISBN13Value = $isbn13->formatedISBNValue($ean, $error);
         }
         if ($error === false) {
             $this->updateContentISBNNumber($contentObjectAttribute, $formatedISBN13Value);
         } else {
             $this->Cli->output($this->Cli->stylize('warning', 'Warning:') . ' ISBN: ' . $this->Cli->stylize('strong', $isbnNumber) . ' is not valid. You need to update contentobject: ' . $this->Cli->stylize('strong', $contentObjectAttribute->attribute('contentobject_id')) . ' version: ' . $this->Cli->stylize('strong', $contentObjectAttribute->attribute('version')) . ' manually.');
         }
     }
 }
Exemplo n.º 2
0
 function fetchObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     $classAttribute = $contentObjectAttribute->contentClassAttribute();
     $classContent = $classAttribute->content();
     if (isset($classContent['ISBN13']) and $classContent['ISBN13']) {
         $number13 = $http->hasPostVariable($base . "_isbn_13_" . $contentObjectAttribute->attribute("id")) ? $http->postVariable($base . "_isbn_13_" . $contentObjectAttribute->attribute("id")) : false;
         if ($number13 === false) {
             return true;
         }
         if (!$contentObjectAttribute->validateIsRequired() and (!$number13 or $number13 == '')) {
             return true;
         }
         // Test if we have an ISBN-10 number. This should be automatically converted to ISBN-13 if found.
         $isbn10TestNumber = preg_replace("/[\\s|\\-]/", "", trim($number13));
         if (strlen($isbn10TestNumber) == 10) {
             if ($contentObjectAttribute->IsValid == eZInputValidator::STATE_ACCEPTED) {
                 // Convert the ISBN-10 number to ISBN-13.
                 $number13 = $this->convertISBN10toISBN13($isbn10TestNumber);
             } else {
                 // Add the value so the added value will be shown back to the user with an error message.
                 $contentObjectAttribute->setAttribute(self::CONTENT_VALUE, $number13);
                 return true;
             }
         }
         // Extract the different parts and set the hyphens correctly.
         $isbn13 = new eZISBN13();
         $isbn13Value = $isbn13->formatedISBNValue($number13, $error);
         $contentObjectAttribute->setAttribute(self::CONTENT_VALUE, $isbn13Value);
         return true;
     }
     $field1 = $http->postVariable($base . "_isbn_field1_" . $contentObjectAttribute->attribute("id"));
     $field2 = $http->postVariable($base . "_isbn_field2_" . $contentObjectAttribute->attribute("id"));
     $field3 = $http->postVariable($base . "_isbn_field3_" . $contentObjectAttribute->attribute("id"));
     $field4 = $http->postVariable($base . "_isbn_field4_" . $contentObjectAttribute->attribute("id"));
     // If $fields are empty if should not store empty content to db.
     if (!$field1 and !$field2 and !$field3 and !$field4) {
         return true;
     }
     $isbn = $field1 . '-' . $field2 . '-' . $field3 . '-' . $field4;
     $isbn = strtoupper($isbn);
     $contentObjectAttribute->setAttribute(self::CONTENT_VALUE, $isbn);
     return true;
 }