Advertisement
Guest User

IPS 4: Content Item Example

a guest
Dec 10th, 2013
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.38 KB | None | 0 0
  1. <?php
  2.  
  3. namespace IPS\downloads;
  4.  
  5. /**
  6.  * File Model
  7.  */
  8. class _File extends \IPS\Content\Item implements
  9. \IPS\Content\Permissions,
  10. \IPS\Content\Tags,
  11. \IPS\Content\Reputation,
  12. \IPS\Content\Followable,
  13. \IPS\Content\ReportCenter,
  14. \IPS\Content\ReadMarkers,
  15. \IPS\Content\Hideable,
  16. \IPS\Content\Featurable,
  17. \IPS\Content\Pinnable,
  18. \IPS\Content\Lockable,
  19. \IPS\Content\Shareable
  20. {
  21.     /**
  22.      * @brief   Application
  23.      */
  24.     public static $application = 'downloads';
  25.    
  26.     /**
  27.      * @brief   Module
  28.      */
  29.     public static $module = 'downloads';
  30.    
  31.     /**
  32.      * @brief   Database Table
  33.      */
  34.     public static $databaseTable = 'downloads_files';
  35.    
  36.     /**
  37.      * @brief   Database Prefix
  38.      */
  39.     public static $databasePrefix = 'file_';
  40.    
  41.     /**
  42.      * @brief   Multiton Store
  43.      */
  44.     protected static $multitons;
  45.    
  46.     /**
  47.      * @brief   Default Values
  48.      */
  49.     protected static $defaultValues = NULL;
  50.    
  51.     /**
  52.      * @brief   Node Class
  53.      */
  54.     public static $containerNodeClass = 'IPS\downloads\Category';
  55.    
  56.     /**
  57.      * @brief   Comment Class
  58.      */
  59.     public static $commentClass = 'IPS\downloads\File\Comment';
  60.    
  61.     /**
  62.      * @brief   Review Class
  63.      */
  64.     public static $reviewClass = 'IPS\downloads\File\Review';
  65.    
  66.     /**
  67.      * @brief   Database Column Map
  68.      */
  69.     public static $databaseColumnMap = array(
  70.         'container'     => 'cat',
  71.         'author'        => 'submitter',
  72.         'views'         => 'views',
  73.         'title'         => 'name',
  74.         'content'       => 'desc',
  75.         'num_comments'  => 'comments',
  76.         'num_reviews'   => 'reviews',
  77.         'last_comment'  => 'last_comment',
  78.         'last_review'   => 'last_review',
  79.         'date'          => 'submitted',
  80.         'updated'       => 'updated',
  81.         'rating'        => 'rating',
  82.         'approved'      => 'open',
  83.         'approved_by'   => 'approver',
  84.         'approved_date' => 'approvedon',
  85.         'pinned'        => 'pinned',
  86.         'featured'      => 'featured',
  87.         'locked'        => 'locked',
  88.         'ip_address'    => 'ipaddress'
  89.     );
  90.    
  91.     /**
  92.      * @brief   Title
  93.      */
  94.     public static $title = 'downloads_file';
  95.    
  96.     /**
  97.      * @brief   Icon
  98.      */
  99.     public static $icon = 'download';
  100.    
  101.     /**
  102.      * @brief   Form Lang Prefix
  103.      */
  104.     public static $formLangPrefix = 'file_';
  105.    
  106.     /**
  107.      * @brief   Reputation Type
  108.      */
  109.     public static $reputationType = 'file_id';
  110.    
  111.     /**
  112.      * @brief   Follow Area Key
  113.      */
  114.     public static $followArea = 'file';
  115.        
  116.     /**
  117.      * Get URL
  118.      *
  119.      * @param   string|NULL     $action     Action
  120.      * @return  \IPS\Http\Url
  121.      */
  122.     public function url( $action=NULL )
  123.     {      
  124.         $url = \IPS\Http\Url::internal( "app=downloads&module=downloads&controller=view&id={$this->id}", 'front', 'downloads_file', $this->name_furl );
  125.         if ( $action )
  126.         {
  127.             $url = $url->setQueryString( 'do', $action );
  128.         }
  129.        
  130.         return $url;
  131.     }
  132.    
  133.     /**
  134.      * Should new items be moderated?
  135.      *
  136.      * @param   \IPS\Member     $member     The member posting
  137.      * @param   \IPS\Node\Model $container  The container
  138.      * @return  bool
  139.      */
  140.     public static function moderateNewItems( \IPS\Member $member, \IPS\Node\Model $container = NULL )
  141.     {
  142.         if ( $container and $container->bitoptions['moderation'] and !static::modPermission( 'unhide', $member, $container ) )
  143.         {
  144.             return TRUE;
  145.         }
  146.        
  147.         return parent::moderateNewItems( $member, $container );
  148.     }
  149.    
  150.     /**
  151.      * Should new comments be moderated?
  152.      *
  153.      * @param   \IPS\Member $member The member posting
  154.      * @return  bool
  155.      */
  156.     public function moderateNewComments( \IPS\Member $member )
  157.     {
  158.         $commentClass = static::$commentClass;
  159.         return $this->container()->bitoptions['comment_moderation'] and !$commentClass::modPermission( 'unhide', $member, $this->container() );
  160.     }
  161.    
  162.     /**
  163.      * Should new reviews be moderated?
  164.      *
  165.      * @param   \IPS\Member $member The member posting
  166.      * @return  bool
  167.      */
  168.     public function moderateNewReviews( \IPS\Member $member )
  169.     {
  170.         $reviewClass = static::$reviewClass;
  171.         return $this->container()->bitoptions['reviews_mod'] and !$reviewClass::modPermission( 'unhide', $member, $this->container() );
  172.     }
  173.    
  174.     /**
  175.      * Get elements for add/edit form
  176.      *
  177.      * @param   \IPS\Content\Item|NULL  $item       The current item if editing or NULL if creating
  178.      * @param   int                     $container  Container (e.g. forum) ID, if appropriate
  179.      * @return  array
  180.      */
  181.     public static function formElements( $item=NULL, \IPS\Node\Model $container=NULL )
  182.     {
  183.         $return = parent::formElements( $item, $container );
  184.         $return['file_desc'] = new \IPS\Helpers\Form\Editor( 'file_desc', $item ? $item->desc : NULL, TRUE, array( 'app' => 'downloads', 'key' => 'Downloads', 'autoSaveKey' => 'downloads-new-file' ) );
  185.         return $return;
  186.     }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement