getDB(); $db->isTransactionSupported() and $db->startTransaction(); $keyfields = array('id' => $e->id); $oldSearch = $db->table('m_mcms#news_entrys')->select($keyfields); $doUpdate = $oldSearch->getRowCount() > 0; $oldSearch->close(); unset($oldSearch); // transient fields and sequence fields needs to be excluded $ignore = array('id','created_by'); if ($doUpdate) { $db->table('m_mcms#news_entrys')->update( $e, array('id' => $e->id), $ignore ); } else { $db->table('m_mcms#news_entrys')->insert( $e, $ignore ); $e->id = $db->getInsertId('id'); } $db->isTransactionSupported() and $db->commit(); return $e; } /** * fetches an entry * @return Entry the stored entry */ public static function getEntry($id) { $db = System::getInstance()->getDB(); $result = $db->table('m_mcms#news_entrys')->getObject(array('id' => $id), false, '\\MCMS\\_\\Modx\\MCMS\\News\\_\\Model\\Entry'); return $result; } /** * deletes an entry */ public static function deleteEntry(Entry $c) { $db = System::getInstance()->getDB(); $db->isTransactionSupported() and $db->startTransaction(); // cascade deletes $db->table('m_mcms#news_comments')->delete(array( 'news_id' => $c->id )); // end cascade deletes $db->table('m_mcms#news_entrys')->delete(array('id' => $c->id)); $db->isTransactionSupported() and $db->commit(); } // public static function getComments(Entry $newsEntry,$page,$pagesize,$reverse) {} /** * stores an entry * update done if no row matching row for the follwing fields is found: id * @return stdClass the stored entry */ public static function storeComment(Comment $e) { $db = System::getInstance()->getDB(); $db->isTransactionSupported() and $db->startTransaction(); $keyfields = array('id' => $e->id); $oldSearch = $db->table('m_mcms#news_comments')->select($keyfields); $doUpdate = $oldSearch->getRowCount() > 0; $oldSearch->close(); unset($oldSearch); // transient fields and sequence fields needs to be excluded $ignore = array('id'); if ($doUpdate) { $db->table('m_mcms#news_comments')->update( $e, array('id' => $e->id), $ignore ); } else { $db->table('m_mcms#news_comments')->insert( $e, $ignore ); $e->id = $db->getInsertId('id'); } $db->isTransactionSupported() and $db->commit(); return $e; } /** * fetches an entry * @return Comment the stored entry */ public static function getComment($id) { $db = System::getInstance()->getDB(); $result = $db->table('m_mcms#news_comments')->getObject(array('id' => $id), false, '\\MCMS\\_\\Modx\\MCMS\\News\\_\\Model\\Comment'); return $result; } /** * deletes an entry */ public static function deleteComment(Comment $c) { $db = System::getInstance()->getDB(); $db->isTransactionSupported() and $db->startTransaction(); $db->table('m_mcms#news_comments')->delete(array('id' => $c->id)); $db->isTransactionSupported() and $db->commit(); } }