Ejemplo n.º 1
0
 /**
  * Method to duplicate slider.
  *
  * @param   array   &$pks   An array of primary key IDs.
  *
  * @return  boolean True if successful.
  */
 public function duplicate(&$pks)
 {
     // Initialise variables.
     $user = JFactory::getUser();
     $db = $this->getDbo();
     // Access checks.
     if (!$user->authorise('core.create', 'com_easyslider')) {
         throw new Exception(JText::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
     }
     $table = $this->getTable();
     $checkEditionLimit = true;
     foreach ($pks as $pk) {
         $edition = defined('JSN_EASYSLIDER_EDITION') ? JSN_EASYSLIDER_EDITION : "free";
         if (strtolower($edition) == 'free') {
             $dataListSlider = JSNEasySliderHelper::getSliders();
             if (count($dataListSlider) >= 3) {
                 $checkEditionLimit = false;
             }
         }
         if ($checkEditionLimit) {
             if ($table->load($pk, true)) {
                 // Reset the id to create a new record
                 $table->slider_id = 0;
                 $m = null;
                 if (preg_match('#\\((\\d+)\\)$#', $table->slider_title, $m)) {
                     $table->slider_title = preg_replace('#\\(\\d+\\)$#', '(' . ($m[1] + 1) . ')', $table->slider_title);
                 } else {
                     $table->slider_title .= ' (2)';
                 }
                 $table->published = 0;
                 $table->access = 1;
                 if (!$table->check() || !$table->store()) {
                     throw new Exception($table->getError());
                 }
             } else {
                 throw new Exception($table->getError());
             }
         }
     }
     if (!$checkEditionLimit) {
         $msg = JText::sprintf('JSN_EASYSLIDER_YOU_HAVE_REACHED_THE_LIMITATION_OF_3_SLIDER_IN_FREE_EDITION', 0) . ' <a class="jsn-link-action" href="index.php?option=com_easyslider&view=upgrade">' . JText::_("JSN_EASYSLIDER_UPGRADE_EDITION") . '</a>';
         throw new Exception($msg);
     }
     return true;
 }