getDB(); $db->isTransactionSupported() and $db->startTransaction(); $keyfields = ['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 = ['id','created_by']; if ($doUpdate) { $db->table('m_mcms#news_entrys')->update($e, ['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 \MCMS\_\Modx\MCMS\News\_\Model\Entry the stored entry */ public static function getEntry($id) { $db = System::getInstance()->getDB(); $_class = '\\MCMS\\_\\Modx\\MCMS\\News\\_\\Model\\Entry'; $result = $db->table('m_mcms#news_entrys')->getObject(['id' => $id], false, $_class); return $result; } /** * Deletes an entry */ public static function deleteEntry(\MCMS\_\Modx\MCMS\News\_\Model\Entry $c) { $db = System::getInstance()->getDB(); $db->isTransactionSupported() and $db->startTransaction(); // cascade deletes $db->table('m_mcms#news_comments')->delete([ 'news_id' => $c->id ]); // end cascade deletes $db->table('m_mcms#news_entrys')->delete(['id' => $c->id]); $db->isTransactionSupported() and $db->commit(); } // public static function getComments(MCMS\_\Modx\MCMS\News\_\Model\Entry $newsEntry,$page,$pagesize,$reverse) {} /** * Stores/updates a 'Comment' entry. * * Update is done if no row matching row for the following fields is found: id * * @return \MCMS\_\Modx\MCMS\News\_\Model\Comment the stored entry */ public static function storeComment(\MCMS\_\Modx\MCMS\News\_\Model\Comment $e) { $db = System::getInstance()->getDB(); $db->isTransactionSupported() and $db->startTransaction(); $keyfields = ['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 = ['id']; if ($doUpdate) { $db->table('m_mcms#news_comments')->update($e, ['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 \MCMS\_\Modx\MCMS\News\_\Model\Comment the stored entry */ public static function getComment($id) { $db = System::getInstance()->getDB(); $_class = '\\MCMS\\_\\Modx\\MCMS\\News\\_\\Model\\Comment'; $result = $db->table('m_mcms#news_comments')->getObject(['id' => $id], false, $_class); return $result; } /** * Deletes an entry */ public static function deleteComment(\MCMS\_\Modx\MCMS\News\_\Model\Comment $c) { $db = System::getInstance()->getDB(); $db->isTransactionSupported() and $db->startTransaction(); $db->table('m_mcms#news_comments')->delete(['id' => $c->id]); $db->isTransactionSupported() and $db->commit(); } }