Example #1
0
	/**
	 * Test for getKeyName returning an array
	 *
	 * @covers JTable::getKeyName
	 *
	 * @return  void
	 *
	 * @since   12.3
	 */
	public function testGetKeyNameComposite()
	{
		$this->assertEquals(
			array('id1', 'id2'),
			$this->object->getKeyName(true)
		);
	}
Example #2
0
 /**
  * Method to delete the history for an item.
  *
  * @param   JTable  $table  JTable object being versioned
  *
  * @return  boolean  true on success, otherwise false.
  *
  * @since   3.2
  */
 public function deleteHistory($table)
 {
     $key = $table->getKeyName();
     $id = $table->{$key};
     $typeTable = JTable::getInstance('Contenttype', 'JTable');
     $typeId = $typeTable->getTypeId($this->typeAlias);
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->delete($db->quoteName('#__ucm_history'))->where($db->quoteName('ucm_item_id') . ' = ' . (int) $id)->where($db->quoteName('ucm_type_id') . ' = ' . (int) $typeId);
     $db->setQuery($query);
     return $db->execute();
 }
 /**
  * clearPrimaryKeys
  *
  * @param \JTable $itemTable
  *
  * @return  \JTable
  */
 public function clearPrimaryKeys(\JTable $itemTable)
 {
     foreach ($itemTable->getKeyName(true) as $key) {
         $itemTable->{$key} = null;
     }
     return $itemTable;
 }
Example #4
0
 /**
  * Method to untag an item
  *
  * @param   integer  $contentId  ID of the content item being untagged
  * @param   JTable   $table      JTable object being untagged
  * @param   array    $tags       Array of tags to be untagged. Use an empty array to untag all existing tags.
  *
  * @return  boolean  true on success, otherwise false.
  *
  * @since   3.1
  */
 public function unTagItem($contentId, $table, $tags = array())
 {
     $key = $table->getKeyName();
     $id = $table->{$key};
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->delete('#__contentitem_tag_map')->where($db->quoteName('type_alias') . ' = ' . $db->quote($this->typeAlias))->where($db->quoteName('content_item_id') . ' = ' . (int) $id);
     if (is_array($tags) && count($tags) > 0) {
         $query->where($db->quoteName('tag_id') . ' IN ' . implode(',', $tags));
     }
     $db->setQuery($query);
     return (bool) $db->execute();
 }
 /**
  * Method to load a row for editing from the version history table.
  *
  * @param   integer  $version_id  Key to the version history table.
  * @param   JTable   &$table      Content table object being loaded.
  *
  * @return  boolean  False on failure or error, true otherwise.
  *
  * @since   12.2
  */
 public function loadHistory($version_id, JTable &$table)
 {
     // Only attempt to check the row in if it exists.
     if ($version_id) {
         $user = JFactory::getUser();
         // Get an instance of the row to checkout.
         $historyTable = JTable::getInstance('History', 'ContenthistoryTable');
         if (!$historyTable->load($version_id)) {
             $this->setError($historyTable->getError());
             return false;
         }
         $rowArray = JArrayHelper::fromObject(json_decode($historyTable->version_data));
         $typeId = JTable::getInstance('Types', 'ContentTable')->getTypeId($this->typeAlias);
         if ($historyTable->ucm_type_id != $typeId) {
             $this->setError(JText::_('JLIB_APPLICATION_ERROR_HISTORY_ID_MISMATCH'));
             $key = $table->getKeyName();
             if (isset($rowArray[$key])) {
                 $table->checkIn($rowArray[$key]);
             }
             return false;
         }
     }
     $this->setState('save_date', $historyTable->save_date);
     $this->setState('version_note', $historyTable->version_note);
     return $table->bind($rowArray);
 }
 /**
  * Prepare and sanitise the table data prior to saving.
  *
  * @param   JTable  $table  A reference to a JTable object.
  *
  * @return  void
  */
 protected function prepareTable(\JTable $table)
 {
     $date = DateHelper::getDate('now');
     $user = $this->container->get('user');
     $key = $table->getKeyName();
     // Alias
     if (property_exists($table, 'alias')) {
         if (!$table->alias) {
             $table->alias = JFilterOutput::stringURLSafe(trim($table->title));
         } else {
             $table->alias = JFilterOutput::stringURLSafe(trim($table->alias));
         }
         if (!$table->alias) {
             $table->alias = JFilterOutput::stringURLSafe($date->toSql(true));
         }
     }
     // Created date
     if (property_exists($table, 'created')) {
         if ($table->created) {
             $table->created = DateHelper::toServerTime($table->created);
         } else {
             $table->created = $date->toSql();
         }
     }
     // Publish_up date
     if (property_exists($table, 'publish_up')) {
         if ($table->publish_up) {
             $table->publish_up = DateHelper::toServerTime($table->publish_up);
         } else {
             $table->publish_up = $this->db->getNullDate();
         }
     }
     // Publish_down date
     if (property_exists($table, 'publish_down')) {
         if ($table->publish_down) {
             $table->publish_down = DateHelper::toServerTime($table->publish_down);
         } else {
             $table->publish_down = $this->db->getNullDate();
         }
     }
     // Modified date
     if (property_exists($table, 'modified') && $table->{$key}) {
         $table->modified = $date->toSql();
     }
     // Created user
     if (property_exists($table, 'created_by') && !$table->created_by) {
         $table->created_by = $user->get('id');
     }
     // Modified user
     if (property_exists($table, 'modified_by') && $table->{$key}) {
         $table->modified_by = $user->get('id');
     }
     // Set Ordering or Nested ordering
     if (property_exists($table, 'ordering')) {
         if (empty($table->id)) {
             $this->setOrderPosition($table);
         }
     }
 }