english/administrator/components/com_content/models/article.php
/**
	 * Method to toggle the featured setting of articles.
	 *
	 * @param	array	The ids of the items to toggle.
	 * @param	int		The value to toggle to.
	 *
	 * @return	boolean	True on success.
	 */
Method to toggle the featured setting of articles.
@param       array   The ids of the items to toggle.
@param       int             The value to toggle to.

@return      boolean True on success.
Method to toggle the featured setting of articles . @param array The ids of the items to toggle . @param int The value to toggle to . @return boolean True on success .
public function featured($pks, $value = 0)
	{
		$pks = (array) $pks;
		JArrayHelper::toInteger($pks);
		if (empty($pks)) {
			$this->setError(JText::_('COM_CONTENT_NO_ITEM_SELECTED'));
			return false;
		}
		$table = $this->getTable('Featured', 'ContentTable');
		try {
			$db = $this->getDbo();
			$db->setQuery(
				'UPDATE #__content AS a' .
				' SET a.featured = '.(int) $value.
				' WHERE a.id IN ('.implode(',', $pks).')'
			);
			if (!$db->query()) {
				throw new Exception($db->getErrorMsg());
			}
			if ((int)$value == 0) {
				$db->setQuery(
					'DELETE FROM #__content_frontpage' .
					' WHERE content_id IN ('.implode(',', $pks).')'
				);
				if (!$db->query()) {
					throw new Exception($db->getErrorMsg());
				}
			} else {
				$query = $db->getQuery(true);
				$query->select('f.content_id');
				$query->from('#__content_frontpage AS f');
				$query->where('content_id IN ('.implode(',', $pks).')');
				$db->setQuery($query);
				if (!is_array($old_featured = $db->loadResultArray())) {
					throw new Exception($db->getErrorMsg());
				}
				$new_featured = array_diff($pks, $old_featured);
				$tuples = array();
				foreach ($new_featured as $pk) {
					$tuples[] = '('.$pk.', 0)';
				}
				if (count($tuples)) {
					$db->setQuery(
						'INSERT INTO #__content_frontpage (`content_id`, `ordering`)' .
						' VALUES '.implode(',', $tuples)
					);
					if (!$db->query()) {
						$this->setError($db->getErrorMsg());
						return false;
					}
				}
			}
		} catch (Exception $e) {
			$this->setError($e->getMessage());
			return false;
		}
		$table->reorder();
		$this->cleanCache();
		return true;
	}
public function featured ( $ pks , $ value = 0 ) { $ pks = ( array ) $ pks ; JArrayHelper :: toInteger ( $ pks ) ; if ( empty ( $ pks ) ) { $ this -> setError ( JText :: _ ( 'COM_CONTENT_NO_ITEM_SELECTED' ) ) ; return false ; } $ table = $ this -> getTable ( 'Featured' , 'ContentTable' ) ; try { $ db = $ this -> getDbo ( ) ; $ db -> setQuery ( 'UPDATE #__content AS a' . ' SET a.featured = ' . ( int ) $ value . ' WHERE a.id IN (' . implode ( ',' , $ pks ) . ')' ) ; if ( ! $ db -> query ( ) ) { throw new Exception ( $ db -> getErrorMsg ( ) ) ; } if ( ( int ) $ value == 0 ) { $ db -> setQuery ( 'DELETE FROM #__content_frontpage' . ' WHERE content_id IN (' . implode ( ',' , $ pks ) . ')' ) ; if ( ! $ db -> query ( ) ) { throw new Exception ( $ db -> getErrorMsg ( ) ) ; } } else { $ query = $ db -> getQuery ( true ) ; $ query -> select ( 'f.content_id' ) ; $ query -> from ( '#__content_frontpage AS f' ) ; $ query -> where ( 'content_id IN (' . implode ( ',' , $ pks ) . ')' ) ; $ db -> setQuery ( $ query ) ; if ( ! is_array ( $ old_featured = $ db -> loadResultArray ( ) ) ) { throw new Exception ( $ db -> getErrorMsg ( ) ) ; } $ new_featured = array_diff ( $ pks , $ old_featured ) ; $ tuples = array ( ) ; foreach ( $ new_featured as $ pk ) { $ tuples [ ] = '(' . $ pk . ', 0)' ; } if ( count ( $ tuples ) ) { $ db -> setQuery ( 'INSERT INTO #__content_frontpage (`content_id`, `ordering`)' . ' VALUES ' . implode ( ',' , $ tuples ) ) ; if ( ! $ db -> query ( ) ) { $ this -> setError ( $ db -> getErrorMsg ( ) ) ; return false ; } } } } catch ( Exception $ e ) { $ this -> setError ( $ e -> getMessage ( ) ) ; return false ; } $ table -> reorder ( ) ; $ this -> cleanCache ( ) ; return true ; }
Method to toggle the featured setting of articles.
Method to toggle the featured setting of articles .
// Sanitize the ids. // Adjust the mapping table. // Clear the existing features settings. // first, we find out which of our new featured articles are already featured. //echo $query; // we diff the arrays to get a list of the articles that are newly featured // Featuring.