getDB(); $db->isTransactionSupported() and $db->startTransaction(); $keyfields = array('id' => $cat->id); $oldSearch = $db->table('m_mcms#linkdb_categorys')->select($keyfields); $doUpdate = $oldSearch->getRowCount() > 0; $oldSearch->close(); unset($oldSearch); // transient fields and sequence fields needs to be excluded $ignore = array('id','links'); if ($doUpdate) { $db->table('m_mcms#linkdb_categorys')->update( $cat, array('id' => $cat->id), $ignore ); } else { $db->table('m_mcms#linkdb_categorys')->insert( $cat, $ignore ); $cat->id = $db->getInsertId('id'); } $db->isTransactionSupported() and $db->commit(); return $cat; } /** * deletes an entry */ public static function delCat(Category $cat) { $db = System::getInstance()->getDB(); $db->isTransactionSupported() and $db->startTransaction(); // cascade deletes $db->table('m_mcms#linkdb_links')->delete(array( 'cat_id' => $cat->id )); // end cascade deletes $db->table('m_mcms#linkdb_categorys')->delete(array('id' => $cat->id)); $db->isTransactionSupported() and $db->commit(); } /** * 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 storeLink(Link $link) { $db = System::getInstance()->getDB(); $db->isTransactionSupported() and $db->startTransaction(); $keyfields = array('id' => $link->id); $oldSearch = $db->table('m_mcms#linkdb_links')->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#linkdb_links')->update( $link, array('id' => $link->id), $ignore ); } else { $db->table('m_mcms#linkdb_links')->insert( $link, $ignore ); $link->id = $db->getInsertId('id'); } $db->isTransactionSupported() and $db->commit(); return $link; } /** * deletes an entry */ public static function delLink(Link $link) { $db = System::getInstance()->getDB(); $db->isTransactionSupported() and $db->startTransaction(); $db->table('m_mcms#linkdb_links')->delete(array('id' => $link->id)); $db->isTransactionSupported() and $db->commit(); } /** * fetches a list of entries * @return Category the stored entry */ public static function getCatList($site_id,$instance) { $db = System::getInstance()->getDB(); $order = array('name'); $class = '\\MCMS\\_\\Modx\\MCMS\\LinkDB\\_\\Model\\Category'; $result = $db->table('m_mcms#linkdb_categorys')->getObjectList(array('site_id' => $site_id,'instance' => $instance), $order, $class); return $result; } /** * fetches a list of entries * @return Link the stored entry */ public static function getLinkList($cat_id) { $db = System::getInstance()->getDB(); $order = array('url'); $class = '\\MCMS\\_\\Modx\\MCMS\\LinkDB\\_\\Model\\Link'; $result = $db->table('m_mcms#linkdb_links')->getObjectList(array('cat_id' => $cat_id), $order, $class); return $result; } }