/** * Method to test JTableContent::check(). * * @since 1.6 */ public function testCheck() { // Mock the database table class. $dbStub = $this->getMock('JDatabaseMySQL', array('getTableFields'), array(array())); $dbStub->expects($this->any())->method('getTableFields')->will($this->returnValue(array())); /* $appStub = $this->getMock('JApplication', array('stringURLSafe')); $appStub::staticExpects($this->any()) ->method('stringURLSafe') ->will($this->returnValue('')); // We need phpunit 3.5 for this to work. */ $table = new JTableContent($dbStub); $this->assertThat($table->check(), $this->isFalse(), 'Line: ' . __LINE__ . ' Checking an empty table should fail.'); /* $table->title = 'Test Title'; $this->assertThat( $table->check(), $this->isFalse(), 'Line: '.__LINE__.' Checking the table with just the title should fail.' ); $this->assertThat( $table->alias, $this->equalTo('Test Title'), 'Line: '.__LINE__.' An empty alias should assume the value of the title.' ); $table->publish_up = '2010-01-12 00:00:00'; $table->publish_down = '2010-01-11 00:00:00'; */ $this->markTestIncomplete('More cases to test.'); }
function addArticle($dataContent, $data) { $db = JFactory::getDbo(); $contentTable = new JTableContent($db); $contentTable->bind($dataContent); if ($contentTable->check()) { $contentTable->store(); if ($contentTable->id) { $data->article_id = $contentTable->id; addMinicck($data); } } }
public function saveItemAsArticle($item) { $table = JTableContent::getInstance('content', 'JTable'); $article = array(); $article['id'] = 0; $article['catid'] = $this->categories[$item->catid]; $article['alias'] = $item->alias; $article['title'] = $item->title; $article['state'] = $item->published; $article['publish_up'] = $item->publish_up; $article['publish_down'] = $item->publish_down; $article['introtext'] = $item->introtext; $article['fulltext'] = $item->fulltext; $article['created'] = $item->created; $article['modified'] = $item->modified; $article['created_by'] = $item->created_by; $article['modified_by'] = $item->modified_by; $article['hits'] = $item->hits; $article['language'] = $item->language; if (file_exists(JPATH_BASE . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg')) { $images['image_intro'] = 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg'; $images['image_intro_caption'] = $item->image_caption; $images['image_intro_alt'] = $item->image_credits; $images['image_fulltext'] = 'media/k2/items/cache/' . md5("Image" . $item->id) . '_XL.jpg'; $images['image_fulltext_caption'] = $item->image_caption; $images['image_fulltext_alt'] = $item->image_credits; } $k2tags = $this->getK2ItemTags($item->id); $recipetags = array(); if ($k2tags) { foreach ($k2tags as $key => $k2tag) { $recipetags[] = $this->getTagId($k2tag->name); } } //$article['tags'] = $recipetags ; $table->newTags = $recipetags; $article['images'] = json_encode($images); $retval = $table->save($article); if ($retval) { $item_pk = $table->getPrimaryKey(); $pk = $item_pk['id']; $this->out($item->title . " saved. item_pk = " . $pk); $this->article_ids[$pk] = $item->id; } else { $this->out("Failed to save " . $item->title . " Error: " . $table->getError()); } // update rating $query = "INSERT INTO `#__content_rating` (content_id,rating_sum,rating_count,lastip) SELECT " . $pk . ",rating_sum,rating_count,lastip FROM `#__k2_rating` WHERE itemID = " . $item->id . " ;"; $query_set = $this->dbo->setQuery($query); $this->dbo->execute(); }
/** * Overrides JTable::delete. Deletes event. * * @param mixed $pk An optional primary key value to delete. If not set the insta$ * * @return boolean True on success. * * @link http://docs.joomla.org/JTable/delete * @since 11.1 * @throws UnexpectedValueException */ public function delete($pk = null) { global $shareddb, $sharedtbl, $sharedlinktbl, $koid; if (!parent::delete($pk)) { return false; } $query = $this->_db->getQuery(true)->delete($this->_db->quoteName($shareddb) . '.' . $this->_db->quoteName($sharedtbl))->where($this->_db->quoteName('article_id') . ' = ' . $this->getArticleId() . ' AND ' . $this->_db->quoteName('koid') . ' = ' . $this->_db->quote($this->koid)); $this->_db->setQuery($query); return $this->_db->execute(); }
function mosComponent(&$db) { parent::__construct($db); }
/** * Create an item entry for a resource * * @param integer $id Optional ID to use * @return boolean */ public function make($id = null) { if ($this->exists()) { return true; } $id = $id ?: Request::getInt('id', 0); $this->_tbl->loadType($id, $this->_type); if ($this->exists()) { return true; } include_once PATH_CORE . DS . 'libraries' . DS . 'joomla' . DS . 'database' . DS . 'table' . DS . 'content.php'; $article = new \JTableContent($this->_db); $article->load($id); if (!$article->id) { $this->setError(Lang::txt('Article not found.')); return false; } $text = strip_tags($article->introtext); $text = str_replace(array("\n", "\r", "\t"), ' ', $text); $text = preg_replace('/\\s+/', ' ', $text); $url = Request::getVar('REQUEST_URI', '', 'server'); $url = $url ?: Route::url('index.php?option=com_content&id=' . $article->alias); $url = str_replace('?tryto=collect', '', $url); $url = str_replace('no_html=1', '', $url); $url = trim($url, '&'); $this->set('type', $this->_type)->set('object_id', $article->id)->set('created', $article->created)->set('created_by', $article->created_by)->set('title', $article->title)->set('description', String::truncate($text, 300, array('html' => true)))->set('url', $url); if (!$this->store()) { return false; } return true; }