setId((int)$array[0]); } function setId($id) { // Set id and wipe data $this->_sectID = $id; $this->_sectData = null; } /** * Method to get data * @return object with data */ function &getData() { // Load the data if (empty( $this->_sectData )) { $query = ' SELECT * FROM #__sql2excel_sections ' . ' WHERE id = '.$this->_sectID; $this->_db->setQuery( $query ); $this->_sectData = $this->_db->loadObject(); } if (!$this->_sectData) { $sql2excel = new stdClass(); $sql2excel->id = 0; $sql2excel->title = null; $sql2excel->alias = null; $sql2excel->description = null; $sql2excel->published = 1; $sql2excel->editor = null; /// Need this? $sql2excel->ordering = 0; $sql2excel->access = 0; $sql2excel->count = 0; $this->_sectData = $sql2excel; } return $this->_sectData; } /** * Method to check if a section is checked out or not * * @access public * @return boolean True if it is checked out */ function isCheckedOut( $uid=0 ) { if ($this->_loadData()) { if ($uid) { return ($this->_sectData->checked_out && $this->_sectData->checked_out != $uid); } else { return $this->_sectData->checked_out; } } } /** * Method to checkin a section * * @access public * @return boolean True on success */ function checkin() { if ($this->_sectID ) { $sectiontable = & $this->getTable(); if(! $sectiontable->checkin($this->_sectID)) { $this->setError('
Checkin failed!
' . $this->_db->getErrorMsg()); return false; } } return false; } /** * Method to checkout a section * * @access public * @return boolean True on success */ function checkout($uid = null) { if ($this->_sectID ) { // Make sure we have a user id to checkout the article with if (is_null($uid)) { $user =& JFactory::getUser(); $uid = $user->get('id'); } // Lets get to it and checkout the thing... $sectiontable = & $this->getTable(); if(!$sectiontable->checkout($uid, $this->_sectID)) { $this->setError('
Checkout failed!
' . $this->_db->getErrorMsg() ); return false; } return true; } return false; } /** * Method to move section up or down * * @access public * @return boolean True on success */ function move($direction) { $row =& $this->getTable(); if (!$row->load($this->_sectID)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->move( $direction, ' published >= 0 ' )) { $this->setError($this->_db->getErrorMsg()); return false; } return true; } /** * Method to publish section(s) * * @access public * @return boolean True on success */ function publish($cid = array(), $publish = 1) { $user =& JFactory::getUser(); if (count( $cid )) { JArrayHelper::toInteger($cid); $cids = implode( ',', $cid ); $query = 'UPDATE #__sql2excel_sections' . ' SET published = '. (int) $publish . ' WHERE id IN ( '.$cids.' )'; $this->_db->setQuery( $query ); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } } return true; } /** * Method to reorder the sections * * @access public * @return void */ function saveorder($cid = array(), $order) { $row =& $this->getTable(); $total = count( $cid ); // update ordering values for( $i=0; $i < $total; $i++ ) { $row->load( (int) $cid[$i] ); if ($row->ordering != $order[$i]) { $row->ordering = $order[$i]; if (!$row->store()) { JError::raiseError(500, $db->getErrorMsg() ); } } } $row->reorder( ); } /** * Method to store a record * * @access public * @return boolean True on success */ function store($data) { $row =& $this->getTable(); // Bind the form fields to the #__sql2excel_sections table if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } // Make sure the record is valid if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } // Store the web link table to the database if (!$row->store()) { $this->setError( $row->getErrorMsg() ); return false; } return $row->id; } /** * Method to update item access * * @access public * @return boolean True on success */ function accessmenu($id, $access) { global $mainframe; $row =& $this->getTable(); $row->load($id); $row->id = $id; $row->access = $access; if ( !$row->check() ) { $this->setError($this->_db->getErrorMsg()); return false; } if ( !$row->store() ) { $this->setError($this->_db->getErrorMsg()); return false; } return true; } /** * Method to delete record(s) * * @access public * @return boolean True on success */ /* function delete() { $cids = JRequest::getVar( 'cid', array(0), 'post', 'array' ); $row =& $this->getTable(); if (count( $cids )) { foreach($cids as $cid) { if (!$row->delete( $cid )) { $this->setError( $row->getErrorMsg() ); return false; } } } return true; } */ function delete() { $cids = JRequest::getVar( 'cid', array(0), 'post', 'array' ); if (count( $cids )) { $row =& $this->getTable(); $cidStr = implode( ',', $cids ); // Check that there are no categories for the section $query = 'SELECT section, COUNT(*) AS cnt ' . ' FROM #__sql2excel_categories ' . ' WHERE section IN (' . $cidStr . ') ' . ' GROUP BY section'; $db = & JFactory::getDBO(); $db->setQuery($query); $catCounts = $db->loadObjectList(); foreach($cids as $cid) { foreach ($catCounts as $c ) { if ( $c->section == $cid && $c->cnt > 0 ) { return JText::_('CATEGORY_SECT_ERR_MSG'); } } } // Check that there are no Workbooks assigned to the category(ies) $query = 'SELECT section, COUNT(*) AS cnt ' . ' FROM #__sql2excel_workbooks ' . ' WHERE section IN (' . $cidStr . ') ' . ' GROUP BY section'; $db = & JFactory::getDBO(); $db->setQuery($query); $wbCounts = $db->loadObjectList(); $errIds = ""; foreach($cids as $cid) { $err = 0; foreach ($wbCounts as $w ) { if ( $w->section == $cid && $w->cnt > 0 ) { $err=1; $errIds=$errIds . "," . $cid; } } if ( $err == 0 ) { if (!$row->delete( $cid )) { $this->setError( $row->getErrorMsg() ); return JText::_('Error deleting Category!'); } } } if ( $errIds == "" ) { return JText::_('Section(s) Deleted'); } else { return JText::_('One or more Sections could not be deleted. There are still workbook(s) mapped to this section ') . ': '. $errIds; } } return ''; } /** * Method to retrieve current section record * * @access Private * @return boolean True on success */ function _getData() { if (empty($this->_sectData)) { $query = 'SELECT p.* '. ' FROM #__sql2excel_sections' . ' WHERE id = ' . (int) $this->_sectID; $this->_db->setQuery($query); $this->_sectData = $this->_db->loadObject(); return (boolean) $this->_sectData; } return true; } }