コード例 #1
0
ファイル: item.php プロジェクト: saity74/com_catalogue
 /**
  * Batch copy items to a new category or current.
  *
  * @param   integer  $value     The new category.
  * @param   array    $pks       An array of row IDs.
  * @param   array    $contexts  An array of item contexts.
  *
  * @return  mixed  An array of new IDs on success, boolean false on failure.
  *
  * @since   11.1
  */
 protected function batchCopy($value, $pks, $contexts)
 {
     $categoryId = (int) $value;
     $newIds = array();
     if (!parent::checkCategoryId($categoryId)) {
         return false;
     }
     // Parent exists so we let's proceed
     while (!empty($pks)) {
         // Pop the first ID off the stack
         $pk = array_shift($pks);
         $this->table->reset();
         // Check that the row actually exists
         if (!$this->table->load($pk)) {
             if ($error = $this->table->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 // Not fatal error
                 $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
                 continue;
             }
         }
         // Alter the title & alias
         $data = $this->generateNewTitle($categoryId, $this->table->alias, $this->table->title);
         $this->table->title = $data['0'];
         $this->table->alias = $data['1'];
         // Reset the ID because we are making a copy
         $this->table->id = 0;
         // Reset hits because we are making a copy
         $this->table->hits = 0;
         // Unpublish because we are making a copy
         $this->table->state = 0;
         // New category ID
         $this->table->catid = $categoryId;
         // TODO: Deal with ordering?
         // $table->ordering	= 1;
         // Check the row.
         if (!$this->table->check()) {
             $this->setError($this->table->getError());
             return false;
         }
         parent::createTagsHelper($this->tagsObserver, $this->type, $pk, $this->typeAlias, $this->table);
         // Store the row.
         if (!$this->table->store()) {
             $this->setError($this->table->getError());
             return false;
         }
         // Get the new item ID
         $newId = $this->table->get('id');
         // Add the new ID to the array
         $newIds[$pk] = $newId;
     }
     // Clean the cache
     $this->cleanCache();
     return $newIds;
 }
コード例 #2
0
ファイル: article.php プロジェクト: 01J/topm
 /**
  * Batch copy items to a new category or current.
  *
  * @param   integer  $value     The new category.
  * @param   array    $pks       An array of row IDs.
  * @param   array    $contexts  An array of item contexts.
  *
  * @return  mixed  An array of new IDs on success, boolean false on failure.
  *
  * @since   11.1
  */
 protected function batchCopy($value, $pks, $contexts)
 {
     $categoryId = (int) $value;
     $i = 0;
     if (!parent::checkCategoryId($categoryId)) {
         return false;
     }
     // Parent exists so we let's proceed
     while (!empty($pks)) {
         // Pop the first ID off the stack
         $pk = array_shift($pks);
         $this->table->reset();
         // Check that the row actually exists
         if (!$this->table->load($pk)) {
             if ($error = $this->table->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 // Not fatal error
                 $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
                 continue;
             }
         }
         // Alter the title & alias
         $data = $this->generateNewTitle($categoryId, $this->table->alias, $this->table->title);
         $this->table->title = $data['0'];
         $this->table->alias = $data['1'];
         // Reset the ID because we are making a copy
         $this->table->id = 0;
         // New category ID
         $this->table->catid = $categoryId;
         // TODO: Deal with ordering?
         //$table->ordering	= 1;
         // Get the featured state
         $featured = $this->table->featured;
         // Check the row.
         if (!$this->table->check()) {
             $this->setError($this->table->getError());
             return false;
         }
         parent::createTagsHelper($this->tagsObserver, $this->type, $pk, $this->typeAlias, $this->table);
         // Store the row.
         if (!$this->table->store()) {
             $this->setError($this->table->getError());
             return false;
         }
         // Get the new item ID
         $newId = $this->table->get('id');
         // Add the new ID to the array
         $newIds[$i] = $newId;
         $i++;
         // Check if the article was featured and update the #__content_frontpage table
         if ($featured == 1) {
             $db = $this->getDbo();
             $query = $db->getQuery(true)->insert($db->quoteName('#__content_frontpage'))->values($newId . ', 0');
             $db->setQuery($query);
             $db->execute();
         }
     }
     // Clean the cache
     $this->cleanCache();
     return $newIds;
 }
コード例 #3
0
 /**
  * Batch copy items to a new category or current.
  *
  * @param   integer  $value     The new category.
  * @param   array    $pks       An array of row IDs.
  * @param   array    $contexts  An array of item contexts.
  *
  * @return  mixed  An array of new IDs on success, boolean false on failure.
  *
  * @since    11.1
  */
 protected function batchCopy($value, $pks, $contexts)
 {
     $categoryId = (int) $value;
     $newIds = [];
     /** @type ChurchDirectoryTableMember $table */
     $table = $this->getTable();
     $i = 0;
     if (!parent::checkCategoryId($categoryId)) {
         return false;
     }
     // Check that the category exists
     if ($categoryId) {
         $categoryTable = JTable::getInstance('Category');
         if (!$categoryTable->load($categoryId)) {
             if ($error = $categoryTable->getError()) {
                 // Fatal error
                 JFactory::getApplication()->enqueueMessage($error, 'error');
                 return false;
             } else {
                 $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
                 return false;
             }
         }
     }
     if (empty($categoryId)) {
         $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
         return false;
     }
     // Check that the user has create permission for the component
     $user = JFactory::getUser();
     if (!$user->authorise('core.create', 'com_churchdirectory.category.' . $categoryId)) {
         $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
         return false;
     }
     // Parent exists so we let's proceed
     while (!empty($pks)) {
         // Pop the first ID off the stack
         $pk = array_shift($pks);
         $this->table->reset();
         // Check that the row actually exists
         if (!$this->table->load($pk)) {
             if ($error = $this->table->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 // Not fatal error
                 $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
                 continue;
             }
         }
         // Alter the title & alias
         $data = $this->generateNewTitle($categoryId, $this->table->alias, $this->table->name);
         $this->table->name = $data['0'];
         $this->table->alias = $data['1'];
         // Reset the ID because we are making a copy
         $this->table->id = 0;
         // New category ID
         $this->table->catid = $categoryId;
         // Unpublish because we are making a copy
         $this->table->published = 0;
         // Check the row.
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         $this->createTagsHelper($this->tagsObserver, $this->type, $pk, $this->typeAlias, $this->table);
         // Store the row.
         if (!$this->table->store()) {
             $this->setError($this->table->getError());
             return false;
         }
         // Get the new item ID
         $newId = $this->table->get('id');
         // Add the new ID to the array
         $newIds[$i] = $newId;
     }
     // Clean the cache
     $this->cleanCache();
     return $newIds;
 }