getDB(); $db->isTransactionSupported() and $db->startTransaction(); $keyfields = array('id' => $gallery->id); $oldSearch = $db->table('m_mcms#gallery_gallerys')->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#gallery_gallerys')->update( $gallery, array('id' => $gallery->id), $ignore ); } else { $db->table('m_mcms#gallery_gallerys')->insert( $gallery, $ignore ); $gallery->id = $db->getInsertId('id'); } $db->isTransactionSupported() and $db->commit(); return $gallery; } /** * fetches an entry * @return Gallery the stored entry */ public static function getGallery($siteId,$instance,$id) { $db = System::getInstance()->getDB(); $class = '\\MCMS\\_\\Modx\\MCMS\\Gallery\\_\\Model\\Gallery'; $result = $db->table('m_mcms#gallery_gallerys')->getObject(array('site_id' => $siteId,'instance' => $instance,'id' => $id), false, $class); return $result; } /** * deletes an entry */ public static function removeGallery(Gallery $gallery) { $db = System::getInstance()->getDB(); $db->isTransactionSupported() and $db->startTransaction(); $db->table('m_mcms#gallery_gallerys')->delete(array('id' => $gallery->id)); $db->isTransactionSupported() and $db->commit(); } // public static function storePic(Gallery $gallery,PicInfo $info,$data) {} // public static function updatePicBinData(PicInfo $info,$data) {} // public static function getPicList($gallery,$page,$pageSize) {} // public static function getPicInfo($picId) {} // public static function getPicBinData($picId) {} // public static function removePic(Gallery $gallery,PicInfo $info) {} }