Beispiel #1
0
 public static function onCCK_Storage_LocationSaveOrder($pks = array(), $order = array())
 {
     $table = static::_getTable();
     $tableClassName = get_class($table);
     $contentType = new JUcmType();
     $type = $contentType->getTypeByTable($tableClassName);
     $tagsObserver = $table->getObserverOfClass('JTableObserverTags');
     $conditions = array();
     if (empty($pks)) {
         return;
     }
     foreach ($pks as $i => $pk) {
         $table->load((int) $pk);
         /*
         			if ( !$this->canEditState( $table ) ) {
         				unset( $pks[$i] );
         			} else*/
         if ($table->ordering != $order[$i]) {
             $table->ordering = $order[$i];
             if ($type) {
                 if (!empty($tagsObserver) && !empty($type)) {
                     $table->tagsHelper = new JHelperTags();
                     $table->tagsHelper->typeAlias = $type->type_alias;
                     $table->tagsHelper->tags = explode(',', $table->tagsHelper->getTagIds($pk, $type->type_alias));
                 }
             }
             if (!$table->store()) {
                 JFactory::getApplication()->enqueueMessage($table->getError(), 'error');
                 return false;
             }
             // Remember to reorder within position and client_id
             $condition = static::_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 condition
     foreach ($conditions as $cond) {
         $table->load($cond[0]);
         $table->reorder($cond[1]);
     }
     return true;
 }
Beispiel #2
0
 /**
  * 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 JUcmType();
     $type = $contentType->getTypeByTable($tableClassName);
     $tagsObserver = $table->getObserverOfClass('JTableObserverTags');
     $conditions = array();
     if (empty($pks)) {
         return JError::raiseWarning(500, JText::_($this->text_prefix . '_ERROR_NO_ITEMS_SELECTED'));
     }
     // 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;
 }
Beispiel #3
0
 /**
  * Saves the manually set order of records.
  *
  * @param   array    $pks    An array of primary key ids.
  * @param   array    $order  THe new ordering list.
  *
  * @return  mixed
  */
 public function reorder($pks = null, $order = array())
 {
     $table = $this->getTable();
     $tableClassName = get_class($table);
     $contentType = new \JUcmType();
     $type = $contentType->getTypeByTable($tableClassName);
     $typeAlias = $type ? $type->type_alias : null;
     $tagsObserver = $table->getObserverOfClass('JTableObserverTags');
     $conditions = array();
     $errors = array();
     $orderCol = $this->state->get('reorder.column', 'ordering');
     // Update ordering values
     foreach ($pks as $i => $pk) {
         $table->load($pk);
         $table->{$orderCol} = $order[$i];
         $this->createTagsHelper($tagsObserver, $type, $pk, $typeAlias, $table);
         if (!$table->store()) {
             $errors[] = $table->getError();
             continue;
         }
         // Remember to reorder within position and client_id
         $condition = $this->getReorderConditions($table);
         $found = false;
         // Found reorder condition if is cached.
         foreach ($conditions as $cond) {
             if ($cond['cond'] == $condition) {
                 $found = true;
                 break;
             }
         }
         // If not found, we add this condition to cache.
         if (!$found) {
             $key = $table->getKeyName();
             $conditions[] = array('pk' => $table->{$key}, 'cond' => $condition);
         }
     }
     // Execute all reorder for each condition caches.
     foreach ($conditions as $cond) {
         $table->load($cond['pk']);
         $table->reorder($cond['cond']);
     }
     $this->state->set('error.message', $errors);
     // Clear the component's cache
     $this->cleanCache();
     return true;
 }