protected function getOrCreatePost($wordpressID)
 {
     if ($wordpressID && ($post = BlogEntry::get()->filter(array('WordpressID' => $wordpressID))->first())) {
         return $post;
     }
     return BlogEntry::create();
 }
 public function BlogEntry()
 {
     if ($this->Type == 'Blog') {
         return BlogEntry::get()->filter(array('ID' => $this->PostID))->First();
     }
     return false;
 }
 protected function getPage($record)
 {
     $page = isset($this->_cache_holders[$record['nid']]) ? $this->_cache_holders[$record['nid']] : null;
     if (!$page) {
         $page = BlogEntry::get()->filter('DrupalNid', $record['nid'])->First();
         $this->_cache_holders[$record['nid']] = $page;
     }
     return $page;
 }
 function Links()
 {
     Requirements::themedCSS('widgets_headlines');
     $entries = BlogEntry::get()->sort('Date', 'DESC')->limit($this->NumberOfHeadlinesShown);
     if ($field = $this->Config()->get("boolean_field_used_to_identify_headline")) {
         $entries = $entries->filter($this->Config()->get("boolean_field_used_to_identify_headline"), 1);
     }
     return $entries;
 }
 function testLevel()
 {
     $entryCount = BlogEntry::get()->count();
     $cat1 = $this->objFromFixture('BlogCategory', 'one');
     $cat2 = $this->objFromFixture('BlogCategory', 'two');
     $cloud = new BlogCategoryCloud();
     $cats = $cloud->Categories();
     $cat1Wrapper = $cats->find('ID', $cat1->ID);
     $this->assertEquals(5, $cat1Wrapper->getLevel());
     $cat2Wrapper = $cats->find('ID', $cat2->ID);
     $this->assertEquals(10, $cat2Wrapper->getLevel());
 }
 /**
  * shows only blog entires
  * associated with the currently selected
  * category. the current blog category is determined
  * through the URLParam ID
  * @param SS_HTTPRequest $request
  * @return {mixed} template to renderWith or httpError
  */
 public function category(SS_HTTPRequest $request)
 {
     $params = $this->owner->getURLParams();
     //get the urlSegment safe for the DB
     $urlSegment = Convert::raw2sql($params['ID']);
     if ($urlSegment != NULL && DataList::create('BlogCategory')->where("URLSegment = '{$urlSegment}'")->count() >= 1) {
         //the category exists - get the id
         $category = DataList::create('BlogCategory')->where("URLSegment = '{$urlSegment}'")->first();
         $categoryID = $category->getField('ID');
         //sort order
         $order = '"BlogEntry"."Date" DESC';
         //get the blog entries
         $entries = BlogEntry::get()->where('"BlogEntry" . "ID" = "BlogEntry_BlogCategories" . "BlogEntryID"')->innerJoin('BlogEntry_BlogCategories', 'BlogEntry_BlogCategories.BlogCategoryID =' . $categoryID)->sort($order);
         //wrap in a paginated list
         $list = new PaginatedList($entries, Controller::curr()->request);
         $data = array('BlogEntries' => $list, 'BlogCategory' => $category->getField('Title'));
         return $this->owner->customise($data)->renderWith(array('BlogHolder', 'Page'));
     } else {
         //no category selected
         return $this->owner->httpError(404, "You must select a category or that category doesn't exist");
     }
 }
 /**
  * @return ArrayList of {@link BlogCategoryCloud_Category}
  */
 public function Categories()
 {
     $result = new ArrayList();
     $cats = BlogCategory::get();
     $entries = BlogEntry::get();
     if ($this->holderId) {
         $cats = $cats->filter('ParentID', $this->holderId);
         $entries = $entries->filter('ParentID', $this->holderId);
     }
     $totalEntryCount = $entries->count();
     // TODO Not possible in a single query due to SS3 ORM
     $aggregateQuery = clone $cats->dataQuery()->query();
     $aggregateQuery->addLeftJoin('BlogEntry_BlogCategories', '"BlogEntry_BlogCategories"."BlogCategoryID" = "BlogCategory"."ID"');
     $aggregateQuery->addLeftJoin('BlogEntry', '"BlogEntry_BlogCategories"."BlogEntryID" = "BlogEntry"."ID"');
     $aggregateQuery->setSelect(array('"BlogCategory"."ID"'));
     $aggregateQuery->selectField('COUNT("BlogEntry"."ID")', 'BlogEntryCount');
     $aggregateQuery->setGroupBy(array('"BlogCategory"."ID"'));
     $aggregateResults = array();
     $maxEntryCount = 0;
     foreach ($aggregateQuery->execute() as $v) {
         $aggregateResults[$v['ID']] = $v;
         if ($v['BlogEntryCount'] > $maxEntryCount) {
             $maxEntryCount = $v['BlogEntryCount'];
         }
     }
     foreach ($cats as $cat) {
         $result->push(BlogCategoryCloud_Category::create($cat, $aggregateResults[$cat->ID]['BlogEntryCount'], $totalEntryCount, $maxEntryCount));
     }
     // Sort in-memory since it might be related to dynamic values like frequency
     // TODO Convert frequency calc to subselect and do sorting in SQL
     if ($this->limit) {
         $result = $result->sort($this->limitSortBy);
         $result = $result->limit($this->limit);
     }
     $result = $result->sort($this->sort);
     return $result;
 }
 public function LatestPost()
 {
     return $post = BlogEntry::get()->sort("Date", "ASC")->First() ? $post : false;
 }
 public function previousPager()
 {
     $page = BlogEntry::get()->filter(array('Date:GreaterThan' => $this->Date, 'ParentID' => $this->ParentID))->sort('Date')->First();
     return $page;
 }
 public function getEntries()
 {
     return BlogEntry::get()->sort('Date DESC');
 }
 /**
  * @return BlogEntry
  */
 protected function findDuplicateByNid($nid, $record)
 {
     return BlogEntry::get()->filter('DrupalNid', $nid)->First();
 }