Пример #1
0
 /**
  * Stores an ISSN Range.
  *
  * @param   boolean  $updateNulls  True to update fields even if they are null.
  *
  * @return  boolean  True on success, false on failure.
  *
  * @since   1.6
  */
 public function store($updateNulls = false)
 {
     // Transform the params field
     if (isset($this->params) && is_array($this->params)) {
         $registry = new Registry();
         $registry->loadArray($this->params);
         $this->params = (string) $registry;
     }
     // Get date and user
     $date = JFactory::getDate();
     $user = JFactory::getUser();
     if ($this->id) {
         // Existing item
         $this->modified_by = $user->get('username');
         $this->modified = $date->toSql();
         // If this object is active, disactivate all the others
         if (!$this->is_closed && $this->is_active) {
             self::disactivateOther($this->id);
         }
     } else {
         // New item
         $this->created_by = $user->get('username');
         $this->created = $date->toSql();
         $this->free = $this->range_end - $this->range_begin + 1;
         // Add ISSN range helper file
         require_once JPATH_COMPONENT . '/helpers/issnrange.php';
         // Get range begin check digit
         $rangeBeginCheckDigit = IssnrangeHelper::countIssnCheckDigit($this->block . $this->range_begin);
         // Set range begin check digit
         $this->range_begin .= $rangeBeginCheckDigit;
         // Set next pointer
         $this->next = $this->range_begin;
         // Get range end check digit
         $rangeEndCheckDigit = IssnrangeHelper::countIssnCheckDigit($this->block . $this->range_end);
         // Set range end check digit
         $this->range_end .= $rangeEndCheckDigit;
         // If this object is active, disactivate all the others
         if ($this->is_active) {
             self::disactivateOther(0);
         }
     }
     return parent::store($updateNulls);
 }
Пример #2
0
 /**
  * Updates the range matching the given identifier id and decreases its
  * next pointer by one. Also free and taken properties are updated 
  * accordingly.
  * @param integer $rangeId id of the range to be updated
  * @return boolean true if and only if the operation succeeds; otherwise
  * false
  */
 public function decreaseByOne($rangeId)
 {
     // Get db access
     $table = $this->getTable();
     // Get ISBN range object
     $range = $table->getRange($rangeId, false);
     // Check that we have a result
     if ($range != null) {
         // Update free
         $range->free += 1;
         // Update taken
         $range->taken -= 1;
         // Check if closed
         if ($range->is_closed) {
             // Update is_closed and is_active
             $range->is_closed = false;
             $range->is_active = true;
             // Range reopened, range end becomes next pointer
             $range->next = $range->range_end;
         } else {
             // Decrease next pointer
             $range->next = substr($range->next, 0, 3) - 1;
             // Next pointer is a string, add left padding
             $range->next = str_pad($range->next, 3, "0", STR_PAD_LEFT);
             // Add ISSN range helper file
             require_once JPATH_COMPONENT . '/helpers/issnrange.php';
             // Get next pointer check digit
             $rangeNextCheckDigit = IssnrangeHelper::countIssnCheckDigit($range->block . $range->next);
             // Set next pointer check digit
             $range->next .= $rangeNextCheckDigit;
             // Validate next pointer
             if (!IssnrangeHelper::validateIssn($range->block . $range->next)) {
                 $this->setError(JText::_('COM_ISSNREGISTRY_ERROR_ISSN_RANGE_UPDATE_INVALID_NEXT_POINTER'));
                 return false;
             }
         }
         // Update to db
         if ($table->updateDecrease($range)) {
             return true;
         }
     }
     return false;
 }