stickies
[ class tree: stickies ] [ index: stickies ] [ all elements ]

Source for file BitSticky.php

Documentation is available at BitSticky.php

  1. <?php
  2. /**
  3.  * @package    stickies
  4.  * @author    spider <spider@steelsun.com>
  5.  */
  6.  
  7. // +----------------------------------------------------------------------+
  8. // | Copyright (c) 2004, bitweaver.org
  9. // +----------------------------------------------------------------------+
  10. // | All Rights Reserved. See copyright.txt for details and a complete list of authors.
  11. // | Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
  12. // |
  13. // | For comments, please use phpdocu.sourceforge.net documentation standards!!!
  14. // | -> see http://phpdocu.sourceforge.net/
  15. // +----------------------------------------------------------------------+
  16. // | Authors: spider <spider@steelsun.com>
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: BitSticky.php,v 1.9 2006/02/08 23:24:28 spiderr Exp $
  20.  
  21.  
  22.  
  23. /**
  24.  * required setup
  25.  */
  26. require_onceLIBERTY_PKG_PATH.'LibertyContent.php' );
  27.  
  28. define('TIKISTICKY_CONTENT_TYPE_GUID''tikisticky' );
  29.  
  30. /**
  31.  * @package    stickies
  32.  */
  33. class BitSticky extends LibertyContent {
  34.  
  35.     function BitSticky$pStickyId=NULL$pContentId=NULL$pNotatedContentId=NULL {
  36.         $this->registerContentTypeTIKISTICKY_CONTENT_TYPE_GUIDarray(
  37.                 'content_type_guid' => TIKISTICKY_CONTENT_TYPE_GUID,
  38.                 'content_description' => 'Sticky',
  39.                 'handler_class' => 'BitSticky',
  40.                 'handler_package' => 'stickies',
  41.                 'handler_file' => 'BitSticky.php',
  42.                 'maintainer_url' => 'http://www.bitweaver.org'
  43.             ) );
  44.         $this->mStickyId $pStickyId;
  45.         $this->mContentId = $pContentId;
  46.         $this->mNotatedContentId $pNotatedContentId;
  47.     }
  48.  
  49.  
  50.     /**
  51.      * Load a sticky object identified by mStickyId, $this->mNotatedContentId or mContentId in that order
  52.      *
  53.      * Populates the mInfo array with the following fields
  54.      *
  55.      * sticky_id
  56.      * notated_content_id
  57.      * parsed
  58.      * @return integer count of number of fields in MInfo
  59.      */
  60.     function load({
  61.         if@BitBase::verifyId$this->mStickyId || @BitBase::verifyId$this->mContentId )  || @BitBase::verifyId$this->mNotatedContentId ) ) {
  62.             if@BitBase::verifyId$this->mStickyId ) ) {
  63.                 $whereSql 'tn.`sticky_id`=?';
  64.                 $bindVars array$this->mStickyId );
  65.             elseif@BitBase::verifyId$this->mNotatedContentId ) ) {
  66.                 global $gBitUser;
  67.                 $whereSql 'tn.`notated_content_id`=? AND lc.`user_id`=?';
  68.                 $bindVars array$this->mNotatedContentId$gBitUser->mUserId );
  69.             elseif@BitBase::verifyId$this->mContentId ) ) {
  70.                 $whereSql 'tn.`content_id`=?';
  71.                 $bindVars array$this->mContentId );
  72.             }
  73.             $query =   "SELECT tn.*, lc.*
  74.                         FROM `".BIT_DB_PREFIX."stickies` tn 
  75.                         INNER JOIN `".BIT_DB_PREFIX."liberty_contentlc ON (lc.`content_id` = tn.`content_id`) 
  76.                         WHERE $whereSql";
  77.             $result $this->mDb->query$query$bindVars );
  78.  
  79.             if $result && $result->numRows() ) {
  80.                 $this->mInfo = $result->fields;
  81.                 $this->mInfo['parsed'$this->parseData();
  82.                 $this->mContentId = $result->fields['content_id'];
  83.                 $this->mStickyId $result->fields['sticky_id'];
  84.                 LibertyContent::load();
  85.             }
  86.         }
  87.         returncount$this->mInfo ) );
  88.     }
  89.     
  90.     /**
  91.      * Verify the core class data required to update the liberty_content table entries
  92.      *
  93.      * @param array Array of content data to be stored
  94.      *  pParamHash Array
  95.      *  (See LibertyContent::verify for details of the core fields - which
  96.      *  appends a [content_store] array with all the values for liberty_content)
  97.      *
  98.      *  content_type_guid    string    Should contain 'tikisticky'
  99.      *  notated_content_id    integer    content_id of the object to which the stickie isattached
  100.      *  sticky_store - Array of values for entering in stickies
  101.      *         sticky_id            integer        If existing then current sticky id
  102.      *                                         otherwise populate from sequence
  103.      *         content_id            integer        Content id of the note
  104.      *         notated_content_id    integer        Content id of the object to which it is attached
  105.      */
  106.     function verify&$pParamHash {
  107.         // It is possible a derived class set this to something different
  108.         if!@BitBase::verifyId$pParamHash['content_type_guid') ) {
  109.             $pParamHash['content_type_guid'$this->mContentTypeGuid;
  110.         }
  111.  
  112.         if!@BitBase::verifyId$pParamHash['notated_content_id') ) {
  113.             $this->mErrors['content'"No content to notate";
  114.         else {
  115.             global $gBitUser;
  116.             $query "SELECT tn.`sticky_id` FROM `".BIT_DB_PREFIX."stickies` tn 
  117.                         INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( tn.`content_id`=lc.`content_id` )
  118.                       WHERE lc.`user_id`=? AND tn.`notated_content_id`=?";
  119.             $this->mStickyId $this->mDb->getOne$queryarray$gBitUser->mUserId$pParamHash['notated_content_id') );
  120.             $pParamHash['sticky_store']['notated_content_id'$pParamHash['notated_content_id'];
  121.         }
  122.         returncount$this->mErrors == );
  123.     }    
  124.     
  125.     /**
  126.      * Create a new stickies object or update an existing one
  127.      *
  128.      * @param array Array of content data to be stored (see verify for details)
  129.      * @return integer Number of errors detected ( 0 if successful )
  130.      */
  131.     function store&$pParamHash {
  132.         if$this->verify$pParamHash ) ) {
  133.             $this->mDb->StartTrans();
  134.             ifLibertyContent::store$pParamHash ) ) {
  135.                 if$this->mStickyId {
  136.                     $result $this->mDb->associateUpdateBIT_DB_PREFIX."stickies"$pParamHash['sticky_store']array"sticky_id" => $this->mStickyId ) );
  137.                 else {
  138.                     $pParamHash['sticky_store']['content_id'$pParamHash['content_id'];
  139.                     if@BitBase::verifyId$pParamHash['sticky_id') ) {
  140.                         $pParamHash['sticky_store']['sticky_id'$pParamHash['sticky_id'];
  141.                     else {
  142.                         $pParamHash['sticky_store']['sticky_id'$this->mDb->GenID'stickies_sticky_id_seq');
  143.                     }
  144.                     $this->mPageId $pParamHash['sticky_store']['sticky_id'];
  145.  
  146.                     $result $this->mDb->associateInsertBIT_DB_PREFIX."stickies"$pParamHash['sticky_store');
  147.                 }
  148.                 $this->mDb->CompleteTrans();
  149.             else {
  150.                 $this->mDb->RollbackTrans();
  151.             }
  152.         }
  153.  
  154.         returncount$this->mErrors == );
  155.     }
  156.     
  157.     /**
  158.      * Delete stickies object and related content record
  159.      */
  160.     function expunge({
  161.         $ret FALSE;
  162.         if$this->isValid() ) {
  163.             $this->mDb->StartTrans();
  164.             $query "DELETE FROM `".BIT_DB_PREFIX."stickies` WHERE `content_id` = ?";
  165.             $result $this->mDb->query$queryarray$this->mContentId ) );
  166.             ifLibertyContent::expunge() ) {
  167.                 $ret TRUE;
  168.                 $this->mDb->CompleteTrans();
  169.             else {
  170.                 $this->mDb->RollbackTrans();
  171.             }
  172.         }
  173.         return $ret;
  174.     }
  175.     
  176. }
  177.  
  178. ?>

Documentation generated on Thu, 15 Feb 2007 20:32:11 +0000 by phpDocumentor 1.3.0