Source for file CMS_CHAPTER.phpclass
Documentation is available at CMS_CHAPTER.phpclass
* openCSP class file CMS_CHAPTER.phpclass
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: CMS_CHAPTER.phpclass,v 1.9 2008/12/17 16:28:51 peterkrebs Exp $
// ---------------------------------------------------------
// ---------------------------------------------------------
* openCSP class CMS_CHAPTER
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: CMS_CHAPTER.phpclass,v 1.9 2008/12/17 16:28:51 peterkrebs Exp $
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* @constant string CLASS_SRC_FILE
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** class vars ------------------------------------------------------ */
* @staticvar array $loadedChapters
protected static $loadedChapters =
array();
/*** class methods --------------------------------------------------- */
* uses self::$loadedChapters as unit of work and returns
if ($debug) echoDebugMethod(__FILE__
,"static","CMS_CHAPTER::getInstance({$aId});");
if (!isset
(self::$loadedChapters[intval($aId)]) ||
!pcf_class_implements(self::$loadedChapters[intval($aId)],'INFA_CMS_CHAPTER'))
self::$loadedChapters[intval($aId)] =
self::factoryFromId($aId,$debug);
return self::$loadedChapters[intval($aId)];
* returns if we already have an instance of $aId
if (isset
(self::$loadedChapters[$aId]))
return pcf_class_implements(self::$loadedChapters[$aId],'INFA_CMS_CHAPTER');
* adds a newsletter to the unit of work
* @param NWL_CHAPTER $aLetter
if (intval($aChapter->getId()))
self::$loadedChapters[$aChapter->getId()] =
$aChapter;
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** compostion --------------------------------------------------- */
* @var TMPL_CHAPTER $myTemplate
/*** attributes -------------------------------------------------- */
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* factories a chapter object
* @todo add chapter types
if ($debug) echoDebugMethod(__FILE__
,"static","CMS_CHAPTER::factoryFromId({$aId})");
$obj_ret->populateFromKeys(array('CHA_ID'=>
intval($aId)));
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
public function getId() {
* returns the order number
* sets the sort order number
* returns the chapter state object
* @return CMS_CHAPTER_STATE
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* inserts a new row to the table
* @param boolean $debug show debug info
* @return int returns the autoIncFld ID if exists or True on success
$this->setDBField('CHA_LASTCHANGE_AT',"CURRENT_TIMESTAMP");
$this->setDBField('CHA_CREATE_AT',"CURRENT_TIMESTAMP");
$str_query =
"SELECT MAX(CHA_SORTORDER)+1 FROM T_CMS_CHAPTER";
$str_query.=
" WHERE PAG_ID=" .
$this->getPageId();
return parent::dbInsert($debug);
* replaces a row in the table
* if the object has not been populated (!$this->populateTS)
* @param boolean $debug show debug info
* @param boolean $ignorPopulated (if False the table MUST have been populated)
public function dbReplace($debug=
False,$ignorPopulated=
False)
$this->setDBField('CHA_LASTCHANGE_AT',"CURRENT_TIMESTAMP");
return parent::dbReplace($debug,$ignorPopulated);
$str_query =
"SELECT * FROM T_CMS_CHAPTER";
$str_query.=
" WHERE PAG_ID=" .
$this->getPageId();
$str_query.=
" AND CHA_SORTORDER = " .
$this->getOrderNr();
$str_query.=
" AND CHA_ID <> " .
$this->getId();
$str_query.=
" ORDER BY CHA_SORTORDER";
if ($arr_row =
$this->getDBObj("r")->quickQuery($str_query))
* moves the chapter (sortorder)
* NOTE this method does save other chapters but not itself
* @param int $moveDir (-1 down +1 up, 0 pos)
public function sort_move($moveDir,$movePos,$debug=
False)
$str_query =
"SELECT * FROM T_CMS_CHAPTER";
$str_query.=
" WHERE PAG_ID=" .
$this->getPageId();
$str_query.=
" AND CHA_SORTORDER < " .
$this->getOrderNr();
$str_query.=
" ORDER BY CHA_SORTORDER DESC";
if ($arr_row =
$this->getDBObj("r")->quickQuery($str_query))
$str_query =
"SELECT * FROM T_CMS_CHAPTER";
$str_query.=
" WHERE PAG_ID=" .
$this->getPageId();
$str_query.=
" AND CHA_SORTORDER >= " .
$this->getOrderNr();
$str_query.=
" AND CHA_ID <> " .
$this->getId();
$str_query.=
" ORDER BY CHA_SORTORDER";
if ($arr_row =
$this->getDBObj("r")->quickQuery($str_query))
if ($this->getOrderNr() ==
$arr_row['CHA_SORTORDER'])
$str_cmd =
"UPDATE T_CMS_CHAPTER SET CHA_SORTORDER=CHA_SORTORDER+1";
$str_cmd.=
" WHERE PAG_ID=" .
$this->getPageId();
$str_cmd.=
" AND CHA_SORTORDER >= " .
$this->getOrderNr();
$str_cmd.=
" AND CHA_ID <> " .
$this->getId();
$this->getDBObj("w")->executeCmd($str_cmd);
$arr_row['CHA_SORTORDER'] =
intval($arr_row['CHA_SORTORDER']) +
1;
$arr_chapters =
$this->getMyPageObj()->getChapterArr(0,False);
foreach($arr_chapters as &$obj_chapter)
if ($obj_chapter->getId() !=
$this->getId())
if ($this->getOrderNr() ==
$int_curPos) $int_curPos++
;
if ($obj_chapter->getOrderNr() !=
$int_curPos)
$obj_chapter->setOrderNr($int_curPos);
if (($this->getOrderNr <
1) ||
($this->getOrderNr() >
$int_curPos))
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* returns if the template is online
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"chapter has an offline state");
$obj_date->setDbString($this->getDBField('CHA_SHOWFROM'));
if ($obj_date->isInFutur())
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"chapter will come in future");
$obj_date->setDbString($this->getDBField('CHA_SHOWTILL'));
if ($obj_date->isInPast())
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"chapter is out of date");
$str_showQuery =
$this->getDBField('CHA_SHOWQUERY');
if (!empty($str_showQuery))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Show Query: <br />SELECT " .
$str_showQuery .
"<br /> failed");
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* returns if a user can show the chapter
* NOTE does not check if the chapter is online
* @todo allow editors to ?
$int_grpId =
$this->getState()->getEditGroup();
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* returns the chapter template id
* returns the chapter template
* sets the template object AND column CTMP_ID
* @param TMPL_CHPATER $aTemplate
* replaces dbGetForm and returns a OCSP_FORM
* @param mixed $form (string) form name (int) form id
* @requires CMS_CHAPTER_FORM.phpclass
* @todo $frmClass require check
public function &getForm($mode=
FRM_MODE_READONLY,$form=
'',$frmClass=
'CMS_CHAPTER_FORM',$debug=
FALSE)
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"no template found");
$obj_form=
parent::getForm($mode,$form,'CMS_CHAPTER_FORM',$debug);
$obj_form->setFrmMode($mode);
$obj_form->setMyTblObj($this);
if (!empty($this->myClassSrcFile))
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* renders the html content of the chapter
public function render($debug=
False)
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Chapter Template Values: <pre>" .
print_r($arr_vals,True) .
"</pre>" );
return $this->getMyTemplate($debug)->renderToHtml($arr_vals,$debug);
Documentation generated on Thu, 08 Jan 2009 17:38:34 +0100 by phpDocumentor 1.4.0a2