gyro/core/controller/base/blockbase.cls.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * Represents a block 00004 * 00005 * if you are familiar with Drupal (http://drupal.org), the concept of blocks is 00006 * not new to you. A block represents a snipppet of HTML that is grouped along 00007 * with other blocks and placed in a location (left, right, too..) on a page. 00008 * 00009 * Most common use is to build dynamic site bars or footers. 00010 * 00011 * @author Gerd Riesselmann 00012 * @ingroup Controller 00013 */ 00014 class BlockBase implements IBlock { 00015 /** 00016 * Title of block (heading) 00017 * 00018 * @var string 00019 */ 00020 public $title; 00021 /** 00022 * Content of block (HTML) 00023 * 00024 * @var string 00025 */ 00026 public $content; 00027 /** 00028 * An index to sort blocks 00029 * 00030 * @var integer 00031 */ 00032 public $index; 00033 /** 00034 * Name (used as CSS class) 00035 * 00036 * @var string 00037 */ 00038 public $name; 00039 /** 00040 * One of LEFT, RIGHT, or CONTENT 00041 * 00042 * @var string 00043 */ 00044 public $position; 00045 00046 /** 00047 * Constructor 00048 * 00049 * @param string The name of this block. Used as class, too 00050 * @param string The title of the block. Displayed as heading, e.g. 00051 * @param string The block's content 00052 * @param integer The block's index. A block with lowest index will be displayed first 00053 * @param enum Where the block is to be dispalyed. 00054 */ 00055 public function __construct($name, $title, $content, $index = 1000, $position = self::LEFT) { 00056 $this->set_title($title); 00057 $this->set_content($content); 00058 $this->set_index($index); 00059 $this->set_name($name); 00060 $this->set_position($position); 00061 } 00062 00063 /** 00064 * Get title of block (heading) 00065 * 00066 * @return string 00067 */ 00068 public function get_title() { 00069 return $this->title; 00070 } 00071 00072 /** 00073 * Set title of block (heading) 00074 * 00075 * @param string 00076 */ 00077 public function set_title($title) { 00078 $this->title = trim($title); 00079 } 00080 00081 /** 00082 * Get content of block (HTML) 00083 * 00084 * @return string 00085 */ 00086 public function get_content() { 00087 return $this->content; 00088 } 00089 00090 /** 00091 * Set content of block (HTML) 00092 * 00093 * @param string 00094 */ 00095 public function set_content($content) { 00096 $this->content = trim($content); 00097 } 00098 00099 /** 00100 * An index to sort blocks 00101 * 00102 * @return integer 00103 */ 00104 public function get_index() { 00105 return $this->index; 00106 } 00107 00108 /** 00109 * Set index to sort blocks 00110 * 00111 * @param integer 00112 */ 00113 public function set_index($index) { 00114 $this->index = $index; 00115 } 00116 00117 /** 00118 * Name (used as CSS class) 00119 * 00120 * @return string 00121 */ 00122 public function get_name() { 00123 return $this->name; 00124 } 00125 00126 /** 00127 * Sets Name (used as CSS class) 00128 * 00129 * @param string 00130 */ 00131 public function set_name($name) { 00132 $this->name = $name; 00133 } 00134 00135 /** 00136 * One of LEFT, RIGHT, CONTENT etc... 00137 * 00138 * @return string 00139 */ 00140 public function get_position() { 00141 return $this->position; 00142 } 00143 00144 /** 00145 * Set position 00146 * 00147 * @param string 00148 */ 00149 public function set_position($position) { 00150 $this->position = $position; 00151 } 00152 00153 /** 00154 * Returns true if this block is valid 00155 * 00156 * @return boolean True if this block has content 00157 */ 00158 public function is_valid() { 00159 return ($this->get_content() !== ''); 00160 } 00161 00162 /** 00163 * Compare this block to another 00164 * 00165 * @return int 0 if index of this is equal to other's index, -1 if this index is less than and +1 if it is more than other's index 00166 */ 00167 public function compare($other) { 00168 $t_idx = $this->get_index(); 00169 $o_idx = $other->get_index(); 00170 if ($t_idx == $o_idx) { 00171 return 0; 00172 } 00173 00174 return ($t_idx < $o_idx) ? -1 : 1; 00175 } 00176 00177 /** 00178 * Renders what should be rendered 00179 * 00180 * @param int $policy Defines how to render, meaning depends on implementation 00181 * @return string The rendered content 00182 */ 00183 public function render($policy = self::NONE) { 00184 $view = ViewFactory::create_view(IViewFactory::MESSAGE, 'widgets/block'); 00185 $view->assign('block', $this); 00186 $view->assign('policy', $policy); 00187 return $view->render(); 00188 } 00189 }