コード例 #1
0
ファイル: admin.php プロジェクト: joomlatools/joomla-platform
 /**
  * Saves the manually set order of records.
  *
  * @param   array    $pks    An array of primary key ids.
  * @param   integer  $order  +1 or -1
  *
  * @return  mixed
  *
  * @since   12.2
  */
 public function saveorder($pks = null, $order = null)
 {
     $table = $this->getTable();
     $tableClassName = get_class($table);
     $contentType = new ContentTableUcmType();
     $type = $contentType->getTypeByTable($tableClassName);
     $tagsObserver = $table->getObserverOfClass('TagsTableObserverTags');
     $conditions = array();
     if (empty($pks)) {
         JFactory::getApplication()->enqueueMessage(JText::_($this->text_prefix . '_ERROR_NO_ITEMS_SELECTED'), 'error');
         return false;
     }
     // Update ordering values
     foreach ($pks as $i => $pk) {
         $table->load((int) $pk);
         // Access checks.
         if (!$this->canEditState($table)) {
             // Prune items that you can't change.
             unset($pks[$i]);
             JLog::add(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), JLog::WARNING, 'jerror');
         } elseif ($table->ordering != $order[$i]) {
             $table->ordering = $order[$i];
             if ($type) {
                 $this->createTagsHelper($tagsObserver, $type, $pk, $type->type_alias, $table);
             }
             if (!$table->store()) {
                 $this->setError($table->getError());
                 return false;
             }
             // Remember to reorder within position and client_id
             $condition = $this->getReorderConditions($table);
             $found = false;
             foreach ($conditions as $cond) {
                 if ($cond[1] == $condition) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 $key = $table->getKeyName();
                 $conditions[] = array($table->{$key}, $condition);
             }
         }
     }
     // Execute reorder for each category.
     foreach ($conditions as $cond) {
         $table->load($cond[0]);
         $table->reorder($cond[1]);
     }
     // Clear the component's cache
     $this->cleanCache();
     return true;
 }