Example #1
0
 /**
  * Return float number that will position widget in requested position.
  *
  * @param int $revisionId
  * @param int $languageId
  * @param int $widgetId
  * @param string $newBlockName
  * @param int $newPosition Real position of widget starting with 0
  * @return float
  */
 private static function _calcWidgetPositionNumber($revisionId, $languageId, $widgetId, $newBlockName, $newPosition)
 {
     $allWidgets = Model::getBlockWidgetRecords($newBlockName, $revisionId, $languageId);
     $widgets = array();
     foreach ($allWidgets as $widget) {
         if ($widgetId === null || $widget['id'] != $widgetId) {
             $widgets[] = $widget;
         }
     }
     if (count($widgets) == 0) {
         $positionNumber = 0;
     } else {
         if ($newPosition <= 0) {
             $positionNumber = $widgets[0]['position'] - 40;
         } else {
             if ($newPosition >= count($widgets)) {
                 $positionNumber = $widgets[count($widgets) - 1]['position'] + 40;
             } else {
                 $positionNumber = ($widgets[$newPosition - 1]['position'] + $widgets[$newPosition]['position']) / 2;
             }
         }
     }
     return $positionNumber;
 }