On branch master
[arthrology.git] / arthrology.class.php
blob623365f5e815840f60e8df8fb8f7a32cb673cdf4
1 <?php
3 /*
4 * Arthrology for Elxis CMS 2008.x and 2009.x+
6 * Event handler
8 * @version 1.0
9 * @package Arthrology
10 * @author Apostolos Koutsoulelos <akoutsoulelos@yahoo.gr>
11 * @copyright Copyright (C) 2009 Apostolos Koutsoulelos. All rights reserved.
12 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
13 * @link
16 // Prevent direct inclusion of this file
17 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
19 if (!defined('ARTHBASE')) {
20 global $_VERSION;
21 if (($_VERSION->RELEASE >= 2009) && ($_VERSION->DEV_LEVEL >= 1)) {
22 define('ARTHBASE', 'arthrology');
23 } else {
24 define('ARTHBASE', 'com_arthology');
28 /*********************************************************/
29 /* THE CLASS THAT WILL CONTAIN THE EVENT FUNCTIONALITY */
30 /*********************************************************/
31 class mosArthrology_Article extends mosDBTable {
33 // Declare variables
34 public $id;
35 public $author;
36 public $title;
37 public $seotitle;
38 public $catid;
39 public $year;
40 public $pages;
41 public $description;
42 public $tags;
43 public $published;
44 public $checked_out = '0';
45 public $checked_out_time = '1979-12-19 00:00:00';
46 public $params;
48 public $category;
49 public $cat_params;
51 /*****************/
52 /* Constructor */
53 /*****************/
54 public function __construct($database) {
55 $this->mosDBTable( '#__arthrology', 'id', $database);
58 /******************************************************/
59 /* Implement load function to have additional stuff */
60 /******************************************************/
61 function load( $oid = null ) {
63 $k = $this->_tbl_key;
64 if ($oid !== null) {
65 $this->$k = $oid;
68 $oid = $this->$k;
69 if ($oid === null) {
70 return false;
73 $class_vars = get_class_vars( get_class( $this ) );
74 foreach ($class_vars as $name => $value) {
75 if (($name != $k) and ($name != "_db") and ($name != "_tbl") and ($name != "_tbl_key")) {
76 $this->$name = $value;
80 $query = "SELECT e.*, c.name AS category, c.params AS cat_params"
81 . "\n FROM $this->_tbl e"
82 . "\n LEFT JOIN #__categories c ON c.id = e.catid"
83 . "\n WHERE e.$this->_tbl_key = $oid";
84 $this->_db->setQuery( $query );
86 return $this->_db->loadObject( $this );
89 /*******************************************/
90 /* Implement the database check function */
91 /*******************************************/
92 function check( $error_msg ) {
93 $error_msg = "";
95 return true;
98 /*******************************************/
99 /* Implement the database store function */
100 /*******************************************/
101 function store( $updateNulls=false ) {
102 $k = $this->_tbl_key;
104 //eliminate the unvalid params
105 $this->category = null;
106 $this->cat_params = null;
108 if ($this->$k) {
109 $ret = $this->_db->updateObject( $this->_tbl, $this, $this->_tbl_key, $updateNulls );
110 } else {
111 $ret = $this->_db->insertObject( $this->_tbl, $this, $this->_tbl_key );
113 if( !$ret ) {
114 $this->_error = strtolower( get_class( $this ) ) . '::store failed <br />' . $this->_db->getErrorMsg();
115 return false;
116 } else {
117 return true;
121 /******************************************/
122 /* Implement the database bind function */
123 /******************************************/
124 //de- / encoding of some passed variables as dates to timestamps and arrays to strings is necessary
125 function bind( $array, $ignore='' ) {
126 global $database;
128 if (!is_array( $array )) {
129 $this->_error = strtolower(get_class( $this ))."::bind failed.";
130 return false;
133 //check if articles for this category have to be published by an administrator
134 $category = new mosCategory ( $database );
135 $category->load( $array['catid'] );
136 $parameter = new mosParameters( $category->params );
137 if ($parameter->get( 'autopublish' )) {
138 $array['published'] = '1';
141 return mosBindArrayToObject( $array, $this, $ignore );
144 /***********************************************************/
145 /* Bind this object to an array of a raw database result */
146 /***********************************************************/
147 function bindRaw( $array, $ignore='' ) {
148 return mosBindArrayToObject( $array, $this, $ignore, null, false );