A QCodo powered CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.0 KiB

  1. <?php
  2. if(!defined('QUINTACMS') ) die("No quinta.");
  3. if (!defined("BLOGMODULE.CLASS.PHP")){
  4. define("BLOGMODULE.CLASS.PHP",1);
  5. /**
  6. * Class BlogModule - provides module that loads content items of type "BlogPost"
  7. *
  8. * To use this module, assign it to a content block and create content items that have the
  9. * content type set to BlogPost. This module will display the most recent 10 posts sorted
  10. * by date descending.
  11. *
  12. * This class can also be used independently by instantiating the class. It accepts optional
  13. * parameters for the type of content item to display and the number of items.
  14. *
  15. *@author Erik Winn <sidewalksoftware@gmail.com>
  16. *
  17. *@version 0.3
  18. *@package Quinta
  19. * @subpackage Modules
  20. */
  21. class BlogModule extends QPanel{
  22. /**
  23. * @var ContentBlockController objContentBlock - the content block to which this module is assigned
  24. */
  25. protected $objContentBlock;
  26. /**
  27. * @var array aryContentItems ContentItems to be displayed
  28. */
  29. protected $aryContentItems;
  30. /**
  31. * @var array aryContentItemControllers ContentItemControllers to be displayed
  32. */
  33. public $aryContentItemControllers;
  34. /**
  35. * Module constructor
  36. * NOTE: When loaded as a module registered in the database, the parameters will be
  37. * a reference to the Module ORM object.
  38. *@param ContentBlock - parent controller object.
  39. *@param mixed - extra parameters for the displayed module
  40. *@param integer - optional content type to display
  41. *@param integer - optional number of posts to display
  42. */
  43. public function __construct( ContentBlockController $objContentBlock,
  44. $mixParameters = null,
  45. $intContentType=ContentType::BlogPost,
  46. $intLimit=10)
  47. {
  48. //Parent should always be a ContentBlockController
  49. $this->objContentBlock =& $objContentBlock;
  50. try {
  51. parent::__construct($this->objContentBlock);
  52. } catch (QCallerException $objExc) {
  53. $objExc->IncrementOffset();
  54. throw $objExc;
  55. }
  56. $this->strTemplate = __QUINTA_CORE_VIEWS__ . '/BlogModule.tpl.php';
  57. $objConditions = QQ::AndCondition(
  58. QQ::Equal(QQN::ContentItem()->TypeId, $intContentType),
  59. QQ::Equal(QQN::ContentItem()->StatusId, ContentStatusType::Published)
  60. );
  61. $aryClauses = QQ::Clause(
  62. QQ::OrderBy(QQN::ContentItem()->CreationDate, false),
  63. QQ::LimitInfo($intLimit));
  64. $this->aryContentItems = ContentItem::QueryArray($objConditions, $aryClauses);
  65. foreach ( $this->aryContentItems as $objContentItem ){
  66. $objContentItemController = new ContentItemController( $this, $objContentItem );
  67. $objContentItemController->AddCssClass($objContentItem->Type);
  68. $this->aryContentItemControllers[] = $objContentItemController;
  69. }
  70. }
  71. /**
  72. * This Function is called when any input is sent - on failure the
  73. * fields are redrawn with optional error messages.
  74. */
  75. public function Validate(){
  76. $blnToReturn = true;
  77. // validate input here
  78. return $blnToReturn;
  79. }
  80. /**
  81. * Event Handling
  82. */
  83. public function btnDoSomething_Click($strFormId, $strControlId, $strParameter){
  84. Quinta::Redirect(__QUINTA_SUBDIRECTORY__ . '/index.php/Home');
  85. }
  86. public function __get($strName){
  87. switch ($strName){
  88. /* case 'SomeClass':
  89. return $this->objSomeClass ;*/
  90. default:
  91. try {
  92. return parent::__get($strName);
  93. } catch (QCallerException $objExc) {
  94. $objExc->IncrementOffset();
  95. throw $objExc;
  96. }
  97. }
  98. }
  99. public function __set($strName, $mixValue){
  100. switch ($strName){
  101. // case 'SomeClass':
  102. // try {
  103. // return ($this->objSomeClass = QType::Cast($mixValue, 'SomeClass' ));
  104. // } catch (QInvalidCastException $objExc) {
  105. // $objExc->IncrementOffset();
  106. // throw $objExc;
  107. // }
  108. default:
  109. try {
  110. return (parent::__set($strName, $mixValue));
  111. } catch (QCallerException $objExc) {
  112. $objExc->IncrementOffset();
  113. throw $objExc;
  114. }
  115. }
  116. }
  117. }//end class
  118. }//end define
  119. ?>