protected function loadOne($file)
 {
     $xml = new SimpleXMLElement($file, 0, true);
     if ((string) $xml->head->title == null) {
         return null;
     }
     $article = new Article();
     foreach ($xml->head->meta as $meta) {
         $name = (string) $meta['name'];
         $content = (string) $meta['content'];
         switch ($name) {
             case 'date':
                 $article->setPublicationDate(new DateTime($content));
                 break;
             case 'author':
                 $article->setAuthor($content);
                 break;
         }
     }
     $article->setTitle((string) $xml->head->title);
     $article->setHash($this->getHash($article->getTitle()));
     $content = "";
     foreach ($xml->body->children() as $child) {
         $content .= $child->asXml();
     }
     $article->setContent($content);
     return $article;
 }
function article(array $langs = array())
{
    $article = new Article();
    $article->setAuthor(author('henry'));
    foreach ($langs as $lang) {
        $article->Translation[$lang]->fromArray(array('title' => 'Title in ' . $lang, 'slug' => $lang . '-slug'));
    }
    return $article;
}
$t->is($article->getAuthor_id(), $article->author_id);
$t->is($article->getAuthorId(), $article->author_id);
$t->is($article->getauthorId(), $article->author_id);
$t->is($article->getAuthorID(), $article->author_id);
$t->is($article->getauthor_id(), $article->author_id);
// Camel case columns
$camelCase = new CamelCase();
$camelCase->testCamelCase = 'camel';
$camelCase->setTestCamelCase('camel');
$t->is($camelCase->getTestCamelCase(), 'camel');
$t->is($camelCase->gettestCamelCase(), 'camel');
$t->is($camelCase->gettestcamelcase(), 'camel');
$t->is($camelCase->gettest_camel_case(), 'camel');
$t->is($camelCase->getTest_camel_case(), 'camel');
// Propel style accessors work with relationships
$article->setAuthor($author);
$t->is($article->Author, $author);
$t->is($article->getAuthor(), $author);
// Camel case with relationships
$t->is($article->getCamelCase()->getTable()->getOption('name'), 'CamelCase');
// Test getDateTimeObject()
$dateTime = $article->getDateTimeObject('created_at');
$t->is($dateTime instanceof DateTime, true);
$t->is($dateTime->format('m/d/Y'), date('m/d/Y'));
try {
    $article->getDateTimeObject('author_id');
    $t->fail();
} catch (Exception $e) {
    $t->pass();
}
$article->setDateTimeObject('created_at', new DateTime('1985-09-01'));
 /**
  * Set authors for an article, uses legacy classes
  *
  * @param Article                                   $article
  * @param \Newscoop\IngestPluginBundle\Entity\Entry $entry
  */
 protected function setArticleAuthorsLegacy(\Article $article, \Newscoop\IngestPluginBundle\Entity\Feed\Entry $entry)
 {
     $authors = $entry->getAuthors();
     $order = 0;
     if (count($authors) > 0) {
         foreach ($authors as $author) {
             $name = trim($author['firstname'] . ' ' . $author['lastname']);
             $author = new \Author($name);
             if (!$author->exists()) {
                 $author->create();
             }
             $article->setAuthor($author, $order++);
         }
     } else {
         $name = $entry->getProduct() ?: $entry->getFeed()->getName();
         $author = new \Author($name);
         if (!$author->exists()) {
             $author->create();
         }
         $article->setAuthor($author);
     }
 }
Example #5
0
 if (isset($article->author) && !empty($article->author)) {
     $authorName = (string) $article->author;
 } else {
     $authorName = (string) $g_user->getRealName();
     $isAuthorFromCreator = TRUE;
 }
 $authorObj = new Author($authorName);
 if (!$authorObj->exists()) {
     $authorData = Author::ReadName($authorName);
     if ($isAuthorFromCreator) {
         $authorData['email'] = $g_user->getEmail();
     }
     $authorObj->create($authorData);
 }
 if ($authorObj->exists()) {
     $articleObj->setAuthor($authorObj);
     $articleFields['author'] = true;
 }
 // Updates the publish date
 $articlePublishDate = (string) $article->publish_date;
 $articleObj->setPublishDate($articlePublishDate);
 // Updates the article
 if (isset($article->keywords) && !empty($article->keywords)) {
     $articleObj->setKeywords((string) $article->keywords);
 }
 $articleFields['keywords'] = true;
 foreach ($xmlArticle as $articleFieldName => $articleFieldValue) {
     if (!array_key_exists($articleFieldName, $articleFields)) {
         $errorMessages[$articleCount][] = '"' . $articleFieldName . '" field in XML file ' . 'was not loaded into database as there is not any ' . 'article type field matching it.<br />';
     }
 }
$serialized = serialize($before);
$after = unserialize($serialized);
$t->is($after->title, 'test', '->unserialize() maintains field values on I18n records');

$conn = Doctrine_Manager::getInstance()->getConnectionForComponent('Article');
$before = new Article();
$before->title = 'test';
$serialized = serialize($before);
$conn->clear();
$conn->evictTables();
$after = unserialize($serialized);
$t->is($after->title, 'test', '->unserialize() maintains field values on I18n records upon reset');

$article = new Article();
try {
$article->setAuthor(new stdClass());
} catch (Exception $e) {
  $t->is($e->getMessage(), 'Couldn\'t call Doctrine_Core::set(), second argument should be an instance of Doctrine_Record or Doctrine_Null when setting one-to-one references.', 'Making sure proper exception message is thrown');
}

$article = new Article();
$article->title = 'testing this out';
$serialized = serialize($article);
$article = unserialize($serialized);

$t->is($article->getTitle(), 'testing this out', 'Making sure getTitle() is still accessible after unserializing');

try {
  $test = new ModelWithNumberInColumn();
  $test->getColumn_1();
  $test->getColumn_2();
Example #7
0
 /**
  * Set article authors
  *
  * @param Article $article
  * @param Newscoop\Entity\Ingest\Feed\Entry $entry
  * @return void
  */
 private function setArticleAuthors(\Article $article, Entry $entry)
 {
     $name = $entry->getFeed()->getTitle();
     $author = new \Author($name);
     if (!$author->exists()) {
         $author->create();
     }
     $article->setAuthor($author);
 }
Example #8
0
<?php

include_once 'data/CategoryDAO.php';
include_once 'control/ArticleControls.php';
include_once 'business/Article.php';
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
$categoryDao = new CategoryDao();
$articleController = new ArticleControls();
var_dump($_POST['category']);
$categoryId = $categoryDao->getIdForName($_POST['category']);
$article = new Article();
$article->setName($_POST['title']);
$article->setContent($_POST['editor']);
$article->setSumup($_POST['sumup_editor']);
$article->setCategory($categoryId);
$article->setAuthor($_SESSION['USR']);
$article->setTags($_POST['tags']);
$ret = $articleController->submitNewArticle($article);
if ($ret) {
    header("location:../adminConsole.php");
} else {
    echo "Unexpected exception";
}